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); }
/** * 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); } }
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()); }