public function testWeighted()
 {
     $assessmentItemRef = new ExtendedAssessmentItemRef('Q01', './Q01.xml');
     $weights = new WeightCollection(array(new Weight('weight1', 1.1)));
     $assessmentItemRef->setWeights($weights);
     $assessmentItemRef->addOutcomeDeclaration(new OutcomeDeclaration('var1', BaseType::INTEGER, Cardinality::SINGLE));
     $assessmentItemRef->addOutcomeDeclaration(new OutcomeDeclaration('var2', BaseType::FLOAT, Cardinality::MULTIPLE));
     $assessmentItemRefs = new AssessmentItemRefCollection(array($assessmentItemRef));
     $assessmentTest = new AssessmentTest('A01', 'An assessmentTest');
     $assessmentSection = new AssessmentSection('S01', 'An assessmentSection', true);
     $assessmentSection->setSectionParts($assessmentItemRefs);
     $assessmentSections = new AssessmentSectionCollection(array($assessmentSection));
     $testPart = new TestPart('P01', $assessmentSections);
     $assessmentTest->setTestParts(new TestPartCollection(array($testPart)));
     $sessionManager = new SessionManager();
     $assessmentTestSession = $sessionManager->createAssessmentTestSession($assessmentTest);
     $assessmentTestSession->beginTestSession();
     $assessmentTestSession['Q01.var1'] = new Integer(1337);
     $variableExpr = $this->createComponentFromXml('<variable identifier="Q01.var1" weightIdentifier="weight1" />');
     $variableProcessor = new VariableProcessor($variableExpr);
     $variableProcessor->setState($assessmentTestSession);
     // -- single cardinality test.
     $result = $variableProcessor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(1470.7, $result->getValue());
     // The value in the state must be intact.
     $this->assertEquals(1337, $assessmentTestSession['Q01.var1']->getValue());
     // What if the indicated weight is not found?
     $variableExpr = $this->createComponentFromXml('<variable identifier="Q01.var1" weightIdentifier="weight2" />');
     $variableProcessor->setExpression($variableExpr);
     $result = $variableProcessor->process();
     $this->assertEquals(1337, $result->getValue());
     // -- multiple cardinality test.
     $assessmentTestSession['Q01.var2'] = new MultipleContainer(BaseType::FLOAT, array(new Float(10.1), new Float(12.1)));
     $variableExpr = $this->createComponentFromXml('<variable identifier="Q01.var2" weightIdentifier="weight1"/>');
     $variableProcessor->setExpression($variableExpr);
     $result = $variableProcessor->process();
     $this->assertEquals(11.11, $result[0]->getValue());
     $this->assertEquals(13.31, $result[1]->getValue());
     // The value in the state must be unchanged.
     $stateVal = $assessmentTestSession['Q01.var2'];
     $this->assertEquals(10.1, $stateVal[0]->getValue());
     $this->assertEquals(12.1, $stateVal[1]->getValue());
 }
 /**
  * @see \qtism\data\AssessmentSection::getComponents()
  */
 public function getComponents()
 {
     $parentComponents = parent::getComponents();
     $parentComponents->merge($this->getRubricBlockRefs());
     return $parentComponents;
 }
 public function testMarshallRecursive()
 {
     // sub1
     $identifier = "sub1AssessmentSection";
     $title = "Sub1 Assessment Section";
     $visible = true;
     $sub1 = new AssessmentSection($identifier, $title, $visible);
     $sub1Parts = new SectionPartCollection();
     $sub1Parts[] = new AssessmentItemRef('Q01', './questions/Q01.xml');
     $sub1Parts[] = new AssessmentItemRef('Q02', './questions/Q02.xml');
     $sub1->setSectionParts($sub1Parts);
     // sub21
     $identifier = "sub21AssessmentSection";
     $title = "Sub21 Assessment Section";
     $visible = false;
     $sub21 = new AssessmentSection($identifier, $title, $visible);
     $sub21Parts = new SectionPartCollection();
     $sub21Parts[] = new AssessmentItemRef('Q04', './questions/Q04.xml');
     $sub21->setSectionParts($sub21Parts);
     // sub22
     $identifier = "sub22AssessmentSection";
     $title = "Sub22 Assessment Section";
     $visible = true;
     $sub22 = new AssessmentSection($identifier, $title, $visible);
     $sub22Parts = new SectionPartCollection();
     $sub22Parts[] = new AssessmentSectionRef('S01', './sections/S01.xml');
     $sub22->setSectionParts($sub22Parts);
     // sub2
     $identifier = "sub2AssessmentSection";
     $title = "Sub2 Assessment Section";
     $visible = true;
     $sub2 = new AssessmentSection($identifier, $title, $visible);
     $sub2Parts = new SectionPartCollection();
     $sub2Parts[] = new AssessmentItemRef('Q03', './questions/Q03.xml');
     $sub2Parts[] = $sub21;
     $sub2Parts[] = $sub22;
     $sub2->setSectionParts($sub2Parts);
     // root
     $identifier = "rootAssessmentSection";
     $title = "Root Assessment Section";
     $visible = true;
     $root = new AssessmentSection($identifier, $title, $visible);
     $root->setSectionParts(new SectionPartCollection(array($sub1, $sub2)));
     $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($root);
     $element = $marshaller->marshall($root);
     $this->assertInstanceOf('qtism\\data\\AssessmentSection', $root);
     $this->assertEquals(4, $element->getElementsByTagName('assessmentSection')->length);
     $sub1Elt = $element->getElementsByTagName('assessmentSection')->item(0);
     $this->assertEquals('sub1AssessmentSection', $sub1Elt->getAttribute('identifier'));
     $this->assertTrue($element === $sub1Elt->parentNode);
     $this->assertEquals('Q02', $sub1Elt->getElementsByTagName('assessmentItemRef')->item(1)->getAttribute('identifier'));
     $sub2Elt = $element->getElementsByTagName('assessmentSection')->item(1);
     $this->assertEquals('sub2AssessmentSection', $sub2Elt->getAttribute('identifier'));
     $this->assertTrue($element === $sub2Elt->parentNode);
     $sub21Elt = $element->getElementsByTagName('assessmentSection')->item(2);
     $this->assertEquals('sub21AssessmentSection', $sub21Elt->getAttribute('identifier'));
     $this->assertTrue($sub2Elt === $sub21Elt->parentNode);
     $sub22Elt = $element->getElementsByTagName('assessmentSection')->item(3);
     $this->assertEquals('sub22AssessmentSection', $sub22Elt->getAttribute('identifier'));
     $this->assertTrue($sub2Elt === $sub22Elt->parentNode);
 }
 public function testGetIdentifiableComponentsCollision()
 {
     $assessmentSection = new AssessmentSection('S01', 'Section S01', true);
     $assessmentSection1a = new AssessmentSection('S01a', 'Section S01a', true);
     $assessmentSection1b = new AssessmentSection('S01b', 'Section S01b', true);
     $assessmentItemRef1a = new AssessmentItemRef('Q01', './Q01.xml');
     $assessmentItemRef1b = new AssessmentItemRef('Q01', './Q01.xml');
     $assessmentSection1a->setSectionParts(new SectionPartCollection(array($assessmentItemRef1a)));
     $assessmentSection1b->setSectionParts(new SectionPartCollection(array($assessmentItemRef1b)));
     $assessmentSection->setSectionParts(new SectionPartCollection(array($assessmentSection1a, $assessmentSection1b)));
     $search = $assessmentSection->getIdentifiableComponents();
     $this->assertInstanceOf('qtism\\data\\QtiComponentCollection', $search);
     $this->assertEquals(4, count($search));
     $this->assertTrue($assessmentSection1a === $search[0]);
     $this->assertTrue($assessmentItemRef1a === $search[1]);
     $this->assertTrue($assessmentSection1b === $search[2]);
     $this->assertTrue($assessmentItemRef1b === $search[3]);
 }