public function testMultipleOccurences() { $doc = new XmlCompactDocument(); $doc->load(self::samplesDir() . 'custom/runtime/scenario_basic_nonadaptive_linear_singlesection_withreplacement.xml'); $sessionManager = new SessionManager(); $session = $sessionManager->createAssessmentTestSession($doc->getDocumentComponent()); $variableExpr = $this->createComponentFromXml('<variable identifier="Q01.SCORE"/>'); $occurenceVariableExpression = $this->createComponentFromXml('<variable identifier="Q01.1.SCORE"/>'); $variableProcessor = new VariableProcessor($variableExpr); $variableProcessor->setState($session); // non begun test session. $this->assertSame(null, $variableProcessor->process()); $variableProcessor->setExpression($occurenceVariableExpression); $this->assertSame(null, $variableProcessor->process()); // begun test session. $variableProcessor->setExpression($variableExpr); $session->beginTestSession(); // Why not 0.0? Because when using a non sequenced variable identifier // for an item with multiple occurence, the very last instance submitted becomes // the item where the values will be pulled out. No instances were submitted yet // and NULL is returned. $this->assertSame(null, $variableProcessor->process()); $variableProcessor->setExpression($occurenceVariableExpression); // Why not NULL? Because we are in a linear test and Q01 is eligible for selection. // The item session is then instantiated. Outcome variables are set to their default // when the item session instantiation occurs. $this->assertSame(0.0, $variableProcessor->process()->getValue()); // Q01.1 $session->beginAttempt(); $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA'))))); $variableProcessor->setExpression($variableExpr); $result = $variableProcessor->process(); // Null because submission mode is individual... $this->assertSame(null, $result); $variableProcessor->setExpression($occurenceVariableExpression); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(1.0, $result->getValue()); $session->moveNext(); // Q01.2 $session->beginAttempt(); $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB'))))); $variableProcessor->setExpression($variableExpr); $result = $variableProcessor->process(); $this->assertSame(null, $result); // $occurenceVariableExpression still targets Q01.1 $variableProcessor->setExpression($occurenceVariableExpression); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(1.0, $result->getValue()); // $occurenceVariableExpression now targets Q01.2 $occurenceVariableExpression->setIdentifier('Q01.2.SCORE'); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(0.0, $result->getValue()); }
public function testMultipleOccurences() { $doc = new XmlCompactDocument(); $doc->load(self::samplesDir() . 'custom/runtime/scenario_basic_nonadaptive_linear_singlesection_withreplacement.xml'); $sessionManager = new SessionManager(); $session = $sessionManager->createAssessmentTestSession($doc->getDocumentComponent()); $variableExpr = $this->createComponentFromXml('<variable identifier="Q01.SCORE"/>'); $occurenceVariableExpression = $this->createComponentFromXml('<variable identifier="Q01.1.SCORE"/>'); $variableProcessor = new VariableProcessor($variableExpr); $variableProcessor->setState($session); // non begun test session. $this->assertSame(null, $variableProcessor->process()); $variableProcessor->setExpression($occurenceVariableExpression); $this->assertSame(null, $variableProcessor->process()); // begun test session. $variableProcessor->setExpression($variableExpr); $session->beginTestSession(); // Why not 0.0? Because we are in individual mode. $variableProcessor->setExpression($occurenceVariableExpression); // Why not NULL? Because we are in a linear test and Q01 is eligible for selection. // The item session is then instantiated. Outcome variables are set to their default // when the item session instantiation occurs. $this->assertSame(0.0, $variableProcessor->process()->getValue()); // Q01.1 $session->beginAttempt(); $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceA'))))); $variableProcessor->setExpression($variableExpr); $result = $variableProcessor->process(); // Null because submission mode is individual... // From IMS QTI: // The value of an item variable taken from an item instantiated multiple times from the same // assessmentItemRef (through the use of selection withReplacement) is taken from the last instance // submitted if submission is simultaneous, otherwise it is undefined. $this->assertSame(null, $result); $variableProcessor->setExpression($occurenceVariableExpression); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\QtiFloat', $result); $this->assertEquals(1.0, $result->getValue()); $session->moveNext(); // Q01.2 $session->beginAttempt(); $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceB'))))); $variableProcessor->setExpression($variableExpr); $result = $variableProcessor->process(); $this->assertSame(null, $result); // $occurenceVariableExpression still targets Q01.1 $variableProcessor->setExpression($occurenceVariableExpression); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\QtiFloat', $result); $this->assertEquals(1.0, $result->getValue()); // $occurenceVariableExpression now targets Q01.2 $occurenceVariableExpression->setIdentifier('Q01.2.SCORE'); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\QtiFloat', $result); $this->assertEquals(0.0, $result->getValue()); }