public function testAssigningScoresAndCorrectResponses() { $doc = new XmlDocument(); $doc->load(self::samplesDir() . 'custom/items/template_processing.xml'); $session = new AssessmentItemSession($doc->getDocumentComponent()); $itemSessionControl = new ItemSessionControl(); $itemSessionControl->setMaxAttempts(0); $session->setItemSessionControl($itemSessionControl); $session->beginItemSession(); // Check that the templateProcessing was correctly processed. $this->assertEquals('ChoiceA', $session->getVariable('RESPONSE')->getCorrectResponse()->getValue()); $this->assertEquals(1.0, $session['GOODSCORE']->getValue()); $this->assertEquals(0.0, $session['WRONGSCORE']->getValue()); // Check that it really works... // With a correct response. $session->beginAttempt(); $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceA')))); $session->endAttempt($responses); $this->assertEquals(1.0, $session['SCORE']->getValue()); // With an incorrect response. $session->beginAttempt(); $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceB')))); $session->endAttempt($responses); $this->assertEquals(0.0, $session['SCORE']->getValue()); }
/** * @see \qtism\data\storage\xml\marshalling\Marshaller::unmarshall() */ protected function unmarshall(DOMElement $element) { $object = new ItemSessionControl(); if (($value = static::getDOMElementAttributeAs($element, 'maxAttempts', 'integer')) !== null) { $object->setMaxAttempts($value); } if (($value = static::getDOMElementAttributeAs($element, 'showFeedback', 'boolean')) !== null) { $object->setShowFeedback($value); } if (($value = static::getDOMElementAttributeAs($element, 'allowReview', 'boolean')) !== null) { $object->setAllowReview($value); } if (($value = static::getDOMElementAttributeAs($element, 'showSolution', 'boolean')) !== null) { $object->setShowSolution($value); } if (($value = static::getDOMElementAttributeAs($element, 'allowComment', 'boolean')) !== null) { $object->setAllowComment($value); } if (($value = static::getDOMElementAttributeAs($element, 'allowSkipping', 'boolean')) !== null) { $object->setAllowSkipping($value); } if (($value = static::getDOMElementAttributeAs($element, 'validateResponses', 'boolean')) !== null) { $object->setValidateResponses($value); } return $object; }
public function testIsDefault() { $itemSessionControl = new ItemSessionControl(); $this->assertTrue($itemSessionControl->isDefault()); $itemSessionControl->setMaxAttempts(0); $this->assertFalse($itemSessionControl->isDefault()); }
public function testMarshall() { $component = new ItemSessionControl(); $component->setAllowComment(true); $component->setMaxAttempts(2); $component->setValidateResponses(false); $marshaller = $this->getMarshallerFactory()->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('itemSessionControl', $element->nodeName); $this->assertEquals('true', $element->getAttribute('allowComment')); $this->assertEquals('2', $element->getAttribute('maxAttempts')); $this->assertEquals('false', $element->getAttribute('validateResponses')); $this->assertEquals('true', $element->getAttribute('allowReview')); $this->assertEquals('false', $element->getAttribute('showSolution')); $this->assertEquals('true', $element->getAttribute('allowSkipping')); }
public function testTemplateVariableDefault() { // This test aims at testing whether template variables // are correctly instantiated as part of the item session and // they can be used in response processing. $doc = new XmlDocument('2.1.0'); $doc->load(self::samplesDir() . 'custom/items/template_declaration_default.xml'); $itemSession = new AssessmentItemSession($doc->getDocumentComponent()); $itemSessionControl = new ItemSessionControl(); $itemSessionControl->setMaxAttempts(0); $itemSession->setItemSessionControl($itemSessionControl); $itemSession->beginItemSession(); $this->assertTrue($itemSession['WRONGSCORE']->equals(new Float(0.0))); $this->assertTrue($itemSession['GOODSCORE']->equals(new Float(1.0))); // 1st attempt to get 'GOODSCORE' as 'SCORE'. $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA')))); $itemSession->beginAttempt(); $itemSession->endAttempt($responses); $this->assertTrue($itemSession['SCORE']->equals($itemSession['GOODSCORE'])); // 2nd attempt to get 'WRONGSCORE' as 'SCORE'. $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB')))); $itemSession->beginAttempt(); $itemSession->endAttempt($responses); $this->assertTrue($itemSession['SCORE']->equals($itemSession['WRONGSCORE'])); }
public function testEvolutionBasicMultipleAttempts() { $count = 5; $attempts = array(new Identifier('ChoiceA'), new Identifier('ChoiceB'), new Identifier('ChoiceC'), new Identifier('ChoiceD'), new Identifier('ChoiceE')); $expected = array(new Float(0.0), new Float(1.0), new Float(0.0), new Float(0.0), new Float(0.0)); $itemSession = self::instantiateBasicAssessmentItemSession(); $itemSessionControl = new ItemSessionControl(); $itemSessionControl->setMaxAttempts($count); $itemSession->setItemSessionControl($itemSessionControl); $itemSession->beginItemSession(); for ($i = 0; $i < $count; $i++) { // Here, manual set up of responses. $this->assertTrue($itemSession->isAttemptable()); $itemSession->beginAttempt(); // simulate some time... 1 second to answer the item. sleep(1); $itemSession['RESPONSE'] = $attempts[$i]; $itemSession->endAttempt(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $itemSession['SCORE']); $this->assertTrue($expected[$i]->equals($itemSession['SCORE'])); $this->assertEquals($i + 1, $itemSession['numAttempts']->getValue()); // 1 more second before the next attempt. // we are here in suspended mode so it will not be // added to the duration. sleep(1); } // The total duration shold have taken 5 seconds, the rest of the time was in SUSPENDED state. $this->assertEquals(5, $itemSession['duration']->getSeconds(true)); // one more and we get an expection... :) try { $this->assertFalse($itemSession->isAttemptable()); $itemSession->beginAttempt(); $this->assertTrue(false); } catch (AssessmentItemSessionException $e) { $this->assertEquals(AssessmentItemSessionException::STATE_VIOLATION, $e->getCode()); } }
public function testEvolutionBasicMultipleAttempts() { $count = 5; $attempts = array(new QtiIdentifier('ChoiceA'), new QtiIdentifier('ChoiceB'), new QtiIdentifier('ChoiceC'), new QtiIdentifier('ChoiceD'), new QtiIdentifier('ChoiceE')); $expected = array(new QtiFloat(0.0), new QtiFloat(1.0), new QtiFloat(0.0), new QtiFloat(0.0), new QtiFloat(0.0)); $itemSession = self::instantiateBasicAssessmentItemSession(); $itemSessionControl = new ItemSessionControl(); $itemSessionControl->setMaxAttempts($count); $itemSession->setItemSessionControl($itemSessionControl); $itemSession->setTime(self::createDate('2014-07-14 13:00:00')); $itemSession->beginItemSession(); for ($i = 0; $i < $count; $i++) { // Here, manual set up of responses. $this->assertTrue($itemSession->isAttemptable()); $itemSession->beginAttempt(); // simulate some time... 1 second to answer the item. $t = $i + 1; $itemSession->setTime(self::createDate("2014-07-14 13:00:0{$t}")); $itemSession['RESPONSE'] = $attempts[$i]; $itemSession->endAttempt(); $this->assertInstanceOf('qtism\\common\\datatypes\\QtiFloat', $itemSession['SCORE']); $this->assertTrue($expected[$i]->equals($itemSession['SCORE'])); $this->assertEquals($t, $itemSession['numAttempts']->getValue()); } // The total duration should have taken 5 seconds. $this->assertEquals(5, $itemSession['duration']->getSeconds(true)); // one more and we get an exception... :) try { $this->assertFalse($itemSession->isAttemptable()); $itemSession->beginAttempt(); $this->assertTrue(false); } catch (AssessmentItemSessionException $e) { $this->assertEquals(AssessmentItemSessionException::ATTEMPTS_OVERFLOW, $e->getCode()); } }