diff --git a/src/qtism/data/storage/xml/marshalling/AssessmentSectionMarshaller.php b/src/qtism/data/storage/xml/marshalling/AssessmentSectionMarshaller.php index 26d73673c..4c34d90c0 100644 --- a/src/qtism/data/storage/xml/marshalling/AssessmentSectionMarshaller.php +++ b/src/qtism/data/storage/xml/marshalling/AssessmentSectionMarshaller.php @@ -76,8 +76,12 @@ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentColl // Deal with selection elements. $selectionElements = static::getChildElementsByTagName($element, 'selection'); if (count($selectionElements) == 1) { - $marshaller = $this->getMarshallerFactory()->createMarshaller($selectionElements[0]); - $object->setSelection($marshaller->unmarshall($selectionElements[0])); + $select = intval($selectionElements[0]->getAttribute('select')); + + if ($select > 0) { + $marshaller = $this->getMarshallerFactory()->createMarshaller($selectionElements[0]); + $object->setSelection($marshaller->unmarshall($selectionElements[0])); + } } // Deal with ordering elements. diff --git a/test/qtismtest/data/storage/xml/marshalling/AssessmentSectionMarshallerTest.php b/test/qtismtest/data/storage/xml/marshalling/AssessmentSectionMarshallerTest.php index cd23982ba..0f60171c5 100644 --- a/test/qtismtest/data/storage/xml/marshalling/AssessmentSectionMarshallerTest.php +++ b/test/qtismtest/data/storage/xml/marshalling/AssessmentSectionMarshallerTest.php @@ -230,6 +230,7 @@ public function testUnmarshallNotRecursive() { // Does it contain a selection? $this->assertTrue($component->hasSelection()); + $this->assertEquals(1, $component->getSelection()->getSelect()); // Does it contain an itemSessionControl? $this->assertTrue($component->hasItemSessionControl()); @@ -240,6 +241,37 @@ public function testUnmarshallNotRecursive() { // Does it contain a branchRule? $this->assertEquals(1, count($component->getBranchRules())); } + + /** + * @depends testUnmarshallNotRecursive + */ + public function testUnmarshallNotRecursiveZeroSelection() { + $dom = new DOMDocument('1.0', 'UTF-8'); + $dom->loadXML( + ' + + + true + + + false + + + + + + + + ' + ); + $element = $dom->documentElement; + + $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($element); + $component = $marshaller->unmarshall($element); + + // Has the element has an attribute 'select' with a zero value, it's skipped. + $this->assertFalse($component->hasSelection()); + } public function testUnmarshallRecursive() { $dom = new DOMDocument('1.0', 'UTF-8'); @@ -314,4 +346,4 @@ public function testUnmarshallOneSectionAssessmentItemRefOnly() { $assessmentItemRefs = $component->getSectionParts(); $this->assertEquals(3, count($assessmentItemRefs)); } -} \ No newline at end of file +}