protected function unmarshall(DOMElement $element) { if (($identifier = static::getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($navigationMode = static::getDOMElementAttributeAs($element, 'navigationMode')) !== null) { if (($submissionMode = static::getDOMElementAttributeAs($element, 'submissionMode')) !== null) { // We do not use the regular DOMElement::getElementsByTagName method // because it is recursive. We only want the first level elements with // tagname = 'assessmentSection'. $assessmentSectionElts = self::getChildElementsByTagName($element, 'assessmentSection'); $assessmentSections = new AssessmentSectionCollection(); foreach ($assessmentSectionElts as $sectElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($sectElt); $assessmentSections[] = $marshaller->unmarshall($sectElt); } if (count($assessmentSections) > 0) { // We can instantiate because all mandatory attributes/elements were found. $navigationMode = NavigationMode::getConstantByName($navigationMode); $submissionMode = SubmissionMode::getConstantByName($submissionMode); $object = new TestPart($identifier, $assessmentSections, $navigationMode, $submissionMode); // preConditions $preConditionElts = self::getChildElementsByTagName($element, 'preCondition'); $preConditions = new PreConditionCollection(); foreach ($preConditionElts as $preConditionElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($preConditionElt); $preConditions[] = $marshaller->unmarshall($preConditionElt); } $object->setPreConditions($preConditions); // branchRules $branchRuleElts = self::getChildElementsByTagName($element, 'branchRule'); $branchRules = new BranchRuleCollection(); foreach ($branchRuleElts as $branchRuleElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($branchRuleElt); $branchRules[] = $marshaller->unmarshall($branchRuleElt); } $object->setBranchRules($branchRules); // itemSessionControl $itemSessionControlElts = self::getChildElementsByTagName($element, 'itemSessionControl'); if (count($itemSessionControlElts) === 1) { $marshaller = $this->getMarshallerFactory()->createMarshaller($itemSessionControlElts[0]); $itemSessionControl = $marshaller->unmarshall($itemSessionControlElts[0]); $object->setItemSessionControl($itemSessionControl); } // timeLimits $timeLimitsElts = self::getChildElementsByTagName($element, 'timeLimits'); if (count($timeLimitsElts) === 1) { $marshaller = $this->getMarshallerFactory()->createMarshaller($timeLimitsElts[0]); $timeLimits = $marshaller->unmarshall($timeLimitsElts[0]); $object->setTimeLimits($timeLimits); } // testFeedbacks $testFeedbackElts = self::getChildElementsByTagName($element, 'testFeedback'); $testFeedbacks = new TestFeedbackCollection(); foreach ($testFeedbackElts as $testFeedbackElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($testFeedbackElt); $testFeedbacks[] = $marshaller->unmarshall($testFeedbackElt); } $object->setTestFeedbacks($testFeedbacks); return $object; } else { $msg = "A testPart element must contain at least one assessmentSection."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'submissionMode' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'navigationMode' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
public function testRouteTest() { $assessmentSections = new AssessmentSectionCollection(); $assessmentSections[] = new AssessmentSection('S1', 'Section 1', true); $assessmentSections[] = new AssessmentSection('S2', 'Section 2', true); $q1 = new AssessmentItemRef('Q1', 'Q1.xml'); $q1->setCategories(new IdentifierCollection(array('mathematics', 'expert'))); $q2 = new AssessmentItemRef('Q2', 'Q2.xml'); $q2->setCategories(new IdentifierCollection(array('sciences', 'expert'))); $q3 = new AssessmentItemRef('Q3', 'Q3.xml'); $q3->setCategories(new IdentifierCollection(array('mathematics'))); $q4 = new AssessmentItemRef('Q4', 'Q4.xml'); $sectionPartsS1 = new SectionPartCollection(array($q1, $q2, $q3, $q4)); $assessmentSections['S1']->setSectionParts($sectionPartsS1); $q5 = new AssessmentItemRef('Q5', 'Q5.xml'); $q6 = new AssessmentItemRef('Q6', 'Q6.xml'); $q6->setCategories(new IdentifierCollection(array('mathematics'))); $sectionPartsS2 = new SectionPartCollection(array($q5, $q6)); $assessmentSections['S2']->setSectionParts($sectionPartsS2); $testPart = new TestPart('TP1', $assessmentSections); $testPart->setAssessmentSections($assessmentSections); $assessmentTest = new AssessmentTest('test', 'A Test', new TestPartCollection(array($testPart))); $route = new Route(); $route->addRouteItem($sectionPartsS1['Q1'], $assessmentSections['S1'], $testPart, $assessmentTest); $route->addRouteItem($sectionPartsS1['Q2'], $assessmentSections['S1'], $testPart, $assessmentTest); $route->addRouteItem($sectionPartsS1['Q3'], $assessmentSections['S1'], $testPart, $assessmentTest); $route->addRouteItem($sectionPartsS1['Q4'], $assessmentSections['S1'], $testPart, $assessmentTest); $route->addRouteItem($sectionPartsS2['Q5'], $assessmentSections['S2'], $testPart, $assessmentTest); $route->addRouteItem($sectionPartsS2['Q6'], $assessmentSections['S2'], $testPart, $assessmentTest); $this->assertEquals('Q1', $route->getFirstRouteItem()->getAssessmentItemRef()->getIdentifier()); $this->assertEquals('Q6', $route->getLastRouteItem()->getAssessmentItemRef()->getIdentifier()); // Is Q3 in TP1? $this->assertTrue($route->isInTestPart(2, $testPart)); // What are the RouteItem objects involved in each AssessmentItemRef ? $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS1['Q1']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q1', $involved[0]->getAssessmentItemRef()->getIdentifier()); $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS1['Q2']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q2', $involved[0]->getAssessmentItemRef()->getIdentifier()); $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS1['Q3']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q3', $involved[0]->getAssessmentItemRef()->getIdentifier()); $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS1['Q4']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q4', $involved[0]->getAssessmentItemRef()->getIdentifier()); $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS2['Q5']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q5', $involved[0]->getAssessmentItemRef()->getIdentifier()); $involved = $route->getRouteItemsByAssessmentItemRef($sectionPartsS2['Q6']); $this->assertEquals(1, count($involved)); $this->assertEquals('Q6', $involved[0]->getAssessmentItemRef()->getIdentifier()); // What are the RouteItem objects involded in part 'TP1'? $tp1RouteItems = $route->getRouteItemsByTestPart($testPart); $this->assertEquals(6, count($tp1RouteItems)); $tp1RouteItems = $route->getRouteItemsByTestPart('TP1'); $this->assertEquals(6, count($tp1RouteItems)); try { $tp1RouteItems = $route->getRouteItemsByTestPart('TPX'); $this->assertFalse(true); } catch (OutOfBoundsException $e) { $this->assertTrue(true); } // What are the RouteItems objects involved in section 'S1'? $s1RouteItems = $route->getRouteItemsByAssessmentSection($assessmentSections['S1']); $this->assertEquals(4, count($s1RouteItems)); $this->assertEquals('Q1', $s1RouteItems[0]->getAssessmentItemRef()->getIdentifier()); $this->assertEquals('Q2', $s1RouteItems[1]->getAssessmentItemRef()->getIdentifier()); $this->assertEquals('Q3', $s1RouteItems[2]->getAssessmentItemRef()->getIdentifier()); $this->assertEquals('Q4', $s1RouteItems[3]->getAssessmentItemRef()->getIdentifier()); // What are the RouteItems objects involved in section 'S2'? $s2RouteItems = $route->getRouteItemsByAssessmentSection('S2'); $this->assertEquals(2, count($s2RouteItems)); $this->assertEquals('Q5', $s2RouteItems[0]->getAssessmentItemRef()->getIdentifier()); $this->assertEquals('Q6', $s2RouteItems[1]->getAssessmentItemRef()->getIdentifier()); // What are the RouteItems objects involded in an unknown section :-D ? // An OutOfBoundsException must be thrown. try { $sXRouteItems = $route->getRouteItemsByAssessmentSection(new AssessmentSection('SX', 'Unknown Section', true)); $this->assertTrue(false, 'An exception must be thrown because the AssessmentSection object is not known by the Route.'); } catch (OutOfBoundsException $e) { $this->assertTrue(true); } // Only 1 one occurence of each selected item found? foreach (array_merge($sectionPartsS1->getArrayCopy(), $sectionPartsS2->getArrayCopy()) as $itemRef) { $this->assertEquals(1, $route->getOccurenceCount($itemRef)); } $assessmentItemRefs = $route->getAssessmentItemRefs(); $this->assertEquals(6, count($assessmentItemRefs)); // test to retrieve items by category. $mathRefs = $route->getAssessmentItemRefsByCategory('mathematics'); $this->assertEquals(3, count($mathRefs)); $sciencesRefs = $route->getAssessmentItemRefsByCategory('sciences'); $this->assertEquals(1, count($sciencesRefs)); $mathAndSciences = $route->getAssessmentItemRefsByCategory(new IdentifierCollection(array('mathematics', 'sciences'))); $this->assertEquals(4, count($mathAndSciences)); $expertRefs = $route->getAssessmentItemRefsByCategory('expert'); $this->assertEquals(2, count($expertRefs)); // test to retrieve items by section. $section1Refs = $route->getAssessmentItemRefsBySection('S1'); $this->assertEquals(4, count($section1Refs)); $section2Refs = $route->getAssessmentItemRefsBySection('S2'); $this->assertEquals(2, count($section2Refs)); // test to retrieve items by section/category. $section1Refs = $route->getAssessmentItemRefsSubset('S1'); $this->assertEquals(4, count($section1Refs)); $mathRefs = $route->getAssessmentItemRefsSubset('', new IdentifierCollection(array('mathematics'))); $this->assertEquals(3, count($mathRefs)); $s1MathRefs = $route->getAssessmentItemRefsSubset('S1', new IdentifierCollection(array('mathematics'))); $this->assertEquals(2, count($s1MathRefs)); // go by exclusion. $exclusionRefs = $route->getAssessmentItemRefsSubset('', null, new IdentifierCollection(array('sciences', 'expert'))); $this->assertEquals(4, count($exclusionRefs)); $this->assertTrue(isset($exclusionRefs['Q3'])); $this->assertTrue(isset($exclusionRefs['Q4'])); $this->assertTrue(isset($exclusionRefs['Q5'])); $this->assertTrue(isset($exclusionRefs['Q6'])); }