public function testLinearNavigationMode()
 {
     $assessmentItemRef = new AssessmentItemRef('Q01', 'Q01.xml');
     $timeLimits = new TimeLimits(new Duration('PT1S'), new Duration('PT2S'), false);
     $assessmentItemRef->setTimeLimits($timeLimits);
     $timeConstraint = new TimeConstraint($assessmentItemRef, new Duration('PT1S'), NavigationMode::LINEAR);
     // Minimum times are applicable to assessmentSections and assessmentItems only when linear navigation
     // mode is in effect, this is the case!
     $this->assertTrue($timeConstraint->minTimeInForce());
     $this->assertEquals('PT0S', $timeConstraint->getMinimumRemainingTime()->__toString());
 }
 /**
  * Unmarshall a DOMElement object corresponding to a QTI assessmentItemRef element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent An AssessmentItemRef object.
  * @throws UnmarshallingException If the mandatory attribute 'href' is missing.
  */
 protected function unmarshall(DOMElement $element)
 {
     $baseComponent = parent::unmarshall($element);
     if (($href = static::getDOMElementAttributeAs($element, 'href')) !== null) {
         $object = new AssessmentItemRef($baseComponent->getIdentifier(), $href);
         $object->setRequired($baseComponent->isRequired());
         $object->setFixed($baseComponent->isFixed());
         $object->setPreConditions($baseComponent->getPreConditions());
         $object->setBranchRules($baseComponent->getBranchRules());
         $object->setItemSessionControl($baseComponent->getItemSessionControl());
         $object->setTimeLimits($baseComponent->getTimeLimits());
         // Deal with categories.
         if (($category = static::getDOMElementAttributeAs($element, 'category')) !== null) {
             $object->setCategories(new IdentifierCollection(explode(" ", $category)));
         }
         // Deal with variableMappings.
         $variableMappingElts = $element->getElementsByTagName('variableMapping');
         $variableMappings = new VariableMappingCollection();
         for ($i = 0; $i < $variableMappingElts->length; $i++) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($variableMappingElts->item($i));
             $variableMappings[] = $marshaller->unmarshall($variableMappingElts->item($i));
         }
         $object->setVariableMappings($variableMappings);
         // Deal with weights.
         $weightElts = $element->getElementsByTagName('weight');
         $weights = new WeightCollection();
         for ($i = 0; $i < $weightElts->length; $i++) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($weightElts->item($i));
             $weights[] = $marshaller->unmarshall($weightElts->item($i));
         }
         $object->setWeights($weights);
         // Deal with templateDefaults.
         $templateDefaultElts = $element->getElementsByTagName('templateDefault');
         $templateDefaults = new TemplateDefaultCollection();
         for ($i = 0; $i < $templateDefaultElts->length; $i++) {
             $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDefaultElts->item($i));
             $templateDefaults[] = $marshaller->unmarshall($templateDefaultElts->item($i));
         }
         $object->setTemplateDefaults($templateDefaults);
         return $object;
     } else {
         $msg = "The mandatory attribute 'href' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 /**
  * Convenience method that returns the mapped variable identifier from $targetIdentifier.
  *
  * @param \qtism\data\AssessmentItemRef $assessmentItemRef An AssessmentItemRef object where variable mappings can be found.
  * @param string $targetIdentifier A targetIdentifier to be replaced by a sourceIdentifier.
  * @return string|false The mapped identifier or $targetIdentifier if no mapping could be established.
  */
 protected static function getMappedVariableIdentifier(AssessmentItemRef $assessmentItemRef, $targetIdentifier)
 {
     // return false if no mapping found.
     $sourceIdentifier = $targetIdentifier;
     foreach ($assessmentItemRef->getVariableMappings() as $variableMapping) {
         if ($variableMapping->getTarget() === $targetIdentifier) {
             $sourceIdentifier = $variableMapping->getSource();
             break;
         } elseif ($variableMapping->getSource() === $targetIdentifier) {
             // Conflict.
             $sourceIdentifier = false;
         }
     }
     return $sourceIdentifier;
 }
 /**
  * Get the item sessions related to $assessmentItemRef.
  *
  * @param \qtism\data\AssessmentItemRef $assessmentItemRef An AssessmentItemRef object.
  * @throws \OutOfBoundsException If no item sessions related to $assessmentItemRef are found.
  * @return \qtism\runtime\tests\AssessmentItemSessionCollection A collection of AssessmentItemSession objects related to $assessmentItemRef.
  */
 public function getAssessmentItemSessions(AssessmentItemRef $assessmentItemRef)
 {
     if (isset($this->shelves[$assessmentItemRef]) === true) {
         return $this->shelves[$assessmentItemRef];
     } else {
         $itemId = $assessmentItemRef->getIdentifier();
         $msg = "No AssessmentItemSession objects bound to '{$itemId}'.";
         throw new OutOfBoundsException($msg);
     }
 }
 public function testMarshallMaximal()
 {
     $identifier = 'question1';
     $href = '../../question1.xml';
     $required = true;
     $fixed = true;
     $preConditions = new PreConditionCollection();
     $preConditions[] = new PreCondition(new BaseValue(BaseType::BOOLEAN, true));
     $preConditions[] = new PreCondition(new BaseValue(BaseType::BOOLEAN, false));
     $branchRules = new BranchRuleCollection();
     $branchRules[] = new BranchRule(new BaseValue(BaseType::INTEGER, 1), 'target1');
     $branchRules[] = new BranchRule(new BaseValue(BaseType::INTEGER, 2), 'target2');
     $itemSessionControl = new ItemSessionControl();
     $timeLimits = new TimeLimits();
     $timeLimits->setMaxTime(new Duration('PT50S'));
     // 50 seconds.
     $variableMappings = new VariableMappingCollection();
     $variableMappings[] = new VariableMapping('var1', 'var2');
     $variableMappings[] = new VariableMapping('var3', 'var4');
     $weights = new WeightCollection();
     $weights[] = new Weight('weight1', 1.5);
     $templateDefaults = new TemplateDefaultCollection();
     $templateDefaults[] = new TemplateDefault('tpl1', new BaseValue(BaseType::INTEGER, 15));
     $categories = new IdentifierCollection(array('cat1', 'cat2'));
     $component = new AssessmentItemRef($identifier, $href, $categories);
     $component->setRequired($required);
     $component->setFixed($fixed);
     $component->setPreConditions($preConditions);
     $component->setBranchRules($branchRules);
     $component->setItemSessionControl($itemSessionControl);
     $component->setTimeLimits($timeLimits);
     $component->setWeights($weights);
     $component->setVariableMappings($variableMappings);
     $component->setTemplateDefaults($templateDefaults);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('assessmentItemRef', $element->nodeName);
     $this->assertEquals($identifier, $element->getAttribute('identifier'));
     $this->assertEquals($href, $element->getAttribute('href'));
     $this->assertEquals(implode(" ", $categories->getArrayCopy()), $element->getAttribute('category'));
     $this->assertEquals('true', $element->getAttribute('required'));
     $this->assertEquals('true', $element->getAttribute('fixed'));
     $weightElts = $element->getElementsByTagName('weight');
     $this->assertEquals(1, $weightElts->length);
     $templateDefaultElts = $element->getElementsByTagName('templateDefault');
     $this->assertEquals(1, $templateDefaultElts->length);
     $variableMappingsElts = $element->getElementsByTagName('variableMapping');
     $this->assertEquals(2, $variableMappingsElts->length);
     $preConditionElts = $element->getElementsByTagName('preCondition');
     $this->assertEquals(2, $preConditionElts->length);
     $branchRuleElts = $element->getElementsByTagName('branchRule');
     $this->assertEquals(2, $branchRuleElts->length);
     $itemSessionControlElts = $element->getElementsByTagName('itemSessionControl');
     $this->assertEquals(1, $itemSessionControlElts->length);
     $timeLimitsElts = $element->getElementsByTagName('timeLimits');
     $this->assertEquals(1, $timeLimitsElts->length);
 }
 /**
  * @see \qtism\data\AssessmentItemRef::getComponents()
  */
 public function getComponents()
 {
     $components = array_merge(parent::getComponents()->getArrayCopy(), $this->getResponseDeclarations()->getArrayCopy(), $this->getOutcomeDeclarations()->getArrayCopy(), $this->getTemplateDeclarations()->getArrayCopy());
     if ($this->hasTemplateProcessing() === true) {
         $components[] = $this->getResponseProcessing();
     }
     if ($this->hasResponseProcessing() === true) {
         $components[] = $this->getResponseProcessing();
     }
     $components = array_merge($components, $this->getModalFeedbackRules()->getArrayCopy());
     return new QtiComponentCollection($components);
 }
 /**
  * Get the URI referencing the Assessment Item (in the knowledge base)
  *
  * @param AssessmentItemRef $itemRef
  * @return string A URI.
  */
 private function getItemUri(AssessmentItemRef $itemRef)
 {
     $href = $itemRef->getHref();
     $parts = explode('|', $href);
     return $parts[0];
 }
 public function getComponents()
 {
     $components = array_merge(parent::getComponents()->getArrayCopy(), $this->getResponseDeclarations()->getArrayCopy(), $this->getOutcomeDeclarations()->getArrayCopy());
     if ($this->hasResponseProcessing() === true) {
         $components[] = $this->getResponseProcessing();
     }
     return new QtiComponentCollection($components);
 }
Beispiel #9
0
 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']));
 }