Skip to content

Commit

Permalink
Fixing <select> unmarshalling with attribute select = 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 18, 2015
1 parent 292c553 commit 6198a99
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(
'
<assessmentSection identifier="myAssessmentSection" title="A non Recursive Assessment Section" visible="true" keepTogether="false">
<preCondition>
<baseValue baseType="boolean">true</baseValue>
</preCondition>
<branchRule target="EXIT_TEST">
<baseValue baseType="boolean">false</baseValue>
</branchRule>
<itemSessionControl allowReview="true"/>
<selection select="0"/>
<assessmentItemRef identifier="Q01" required="false" fixed="false" href="./questions/Q01.xml"/>
<assessmentItemRef identifier="Q02" required="false" fixed="false" href="./questions/Q02.xml"/>
<assessmentSectionRef identifier="S01" required="false" fixed="false" href="./sections/S01.xml"/>
</assessmentSection>
'
);
$element = $dom->documentElement;

$marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($element);
$component = $marshaller->unmarshall($element);

// Has the <selection> 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');
Expand Down Expand Up @@ -314,4 +346,4 @@ public function testUnmarshallOneSectionAssessmentItemRefOnly() {
$assessmentItemRefs = $component->getSectionParts();
$this->assertEquals(3, count($assessmentItemRefs));
}
}
}

0 comments on commit 6198a99

Please sign in to comment.