/** * @dataProvider responseConditionMatchCorrectProvider * * @param string $response A QTI Identifier * @param float $expectedScore The expected score for a given $response */ public function testResponseConditionMatchCorrect($response, $expectedScore) { $rule = $this->createComponentFromXml(' <responseCondition> <responseIf> <match> <variable identifier="RESPONSE"/> <correct identifier="RESPONSE"/> </match> <setOutcomeValue identifier="SCORE"> <baseValue baseType="float">1</baseValue> </setOutcomeValue> </responseIf> <responseElse> <setOutcomeValue identifier="SCORE"> <baseValue baseType="float">0</baseValue> </setOutcomeValue> </responseElse> </responseCondition> '); $responseVarDeclaration = $this->createComponentFromXml(' <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> <correctResponse> <value>ChoiceA</value> </correctResponse> </responseDeclaration> '); $responseVar = ResponseVariable::createFromDataModel($responseVarDeclaration); $this->assertTrue($responseVar->getCorrectResponse()->equals(new Identifier('ChoiceA'))); // Set 'ChoiceA' to 'RESPONSE' in order to get a score of 1.0. $responseVar->setValue($response); $outcomeVarDeclaration = $this->createComponentFromXml(' <outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float"> <defaultValue> <value>0</value> </defaultValue> </outcomeDeclaration> '); $outcomeVar = OutcomeVariable::createFromDataModel($outcomeVarDeclaration); $this->assertEquals(0, $outcomeVar->getDefaultValue()->getValue()); $state = new State(array($responseVar, $outcomeVar)); $processor = new ResponseConditionProcessor($rule); $processor->setState($state); $processor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $state['SCORE']); $this->assertTrue($expectedScore->equals($state['SCORE'])); }