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);
 }
コード例 #2
0
ファイル: Route.php プロジェクト: nagyist/qti-sdk
 /**
  * For more convience, the processing related to the AssessmentItemRef object contained
  * in a newly added RouteItem object is gathered in this method. The following process
  * will occur:
  *
  * * The RouteItem object is inserted in the RouteItem array for storage.
  * * The assessmentItemRef is added to the occurence map.
  * * The assessmentItemRef is added to the category map.
  * * The assessmentItemRef is added to the section map.
  *
  * @param \qtism\runtime\tests\RouteItem $routeItem
  */
 protected function registerAssessmentItemRef(RouteItem $routeItem)
 {
     array_push($this->routeItems, $routeItem);
     // For more convenience ;)
     $assessmentItemRef = $routeItem->getAssessmentItemRef();
     // Count the number of occurences for the assessmentItemRef.
     if (isset($this->assessmentItemRefOccurenceCount[$assessmentItemRef]) === false) {
         $this->assessmentItemRefOccurenceCount[$assessmentItemRef] = 0;
     }
     $this->assessmentItemRefOccurenceCount[$assessmentItemRef] += 1;
     $routeItem->setOccurence($this->assessmentItemRefOccurenceCount[$assessmentItemRef] - 1);
     // Reference the assessmentItemRef object of the RouteItem
     // for a later use.
     $this->assessmentItemRefs->attach($assessmentItemRef);
     // Reference the assessmentItemRef object of the RouteItem
     // by category for a later use.
     foreach ($assessmentItemRef->getCategories() as $category) {
         if (isset($this->assessmentItemRefCategoryMap[$category]) === false) {
             $this->assessmentItemRefCategoryMap[$category] = new AssessmentItemRefCollection();
         }
         $this->assessmentItemRefCategoryMap[$category][] = $assessmentItemRef;
         if ($this->categories->contains($category) === false) {
             $this->categories[] = $category;
         }
     }
     // Reference the AssessmentItemRef object of the RouteItem
     // by section for a later use.
     foreach ($routeItem->getAssessmentSections() as $s) {
         $assessmentSectionIdentifier = $s->getIdentifier();
         if (isset($this->assessmentItemRefSectionMap[$assessmentSectionIdentifier]) === false) {
             $this->assessmentItemRefSectionMap[$assessmentSectionIdentifier] = new AssessmentItemRefCollection();
         }
         $this->assessmentItemRefSectionMap[$assessmentSectionIdentifier][] = $assessmentItemRef;
     }
     // Reference the AssessmentItemRef by routeItem.
     if (isset($this->assessmentItemRefMap[$assessmentItemRef]) === false) {
         $this->assessmentItemRefMap[$assessmentItemRef] = new RouteItemCollection();
     }
     $this->assessmentItemRefMap[$assessmentItemRef][] = $routeItem;
 }