protected static function instantiate($url)
 {
     $doc = new XmlCompactDocument();
     $doc->load($url);
     $manager = new SessionManager();
     return $manager->createAssessmentTestSession($doc->getDocumentComponent());
 }
 public function setUp()
 {
     parent::setUp();
     $test = new XmlCompactDocument();
     $test->load(self::samplesDir() . 'custom/runtime/linear_5_items.xml');
     $this->setTest($test->getDocumentComponent());
 }
Exemple #3
0
 public function testSimpleSave()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/php/php_storage_simple.xml');
     $phpDoc = new PhpDocument('2.1', $doc->getDocumentComponent());
     $file = tempnam('/tmp', 'qsm');
     $phpDoc->save($file);
     unlink($file);
 }
 public function setUp()
 {
     parent::setUp();
     $testFilePath = self::samplesDir() . 'custom/runtime/itemsubset.xml';
     $doc = new XmlCompactDocument();
     $doc->load($testFilePath);
     $sessionManager = new SessionManager();
     $testSession = $sessionManager->createAssessmentTestSession($doc->getDocumentComponent());
     $testSession->beginTestSession();
     $this->setTestSession($testSession);
 }
 public function testClassSelection()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/itemsubset.xml');
     $iterator = new QtiComponentIterator($doc->getDocumentComponent(), array('responseProcessing'));
     $i = 0;
     foreach ($iterator as $responseProcessing) {
         $this->assertEquals($iterator->key(), 'responseProcessing');
         $i++;
     }
     $this->assertEquals(7, $i);
 }
 public function testTestResultsSubmissionNonLinearEnd()
 {
     // This test focuses on test results submission at outcome processing time.
     $file = self::samplesDir() . 'custom/runtime/results_linear.xml';
     $doc = new XmlCompactDocument();
     $doc->load($file);
     $factory = new SimpleResultsSubmittableTestSessionFactory();
     $testSession = $factory->createAssessmentTestSession($doc->getDocumentComponent());
     $testSession->setTestResultsSubmission(TestResultsSubmission::END);
     $this->assertEquals($testSession->getState(), AssessmentTestSessionState::INITIAL);
     $testSession->beginTestSession();
     $this->assertEquals($testSession->getState(), AssessmentTestSessionState::INTERACTING);
     // Q01 - Failure
     $testSession->beginAttempt();
     $testSession->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB')))));
     $this->assertSame(0.0, $testSession['Q01.SCORE']->getValue());
     $testSession->moveNext();
     // Q02 - Success
     $testSession->beginAttempt();
     $testSession->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB')))));
     $this->assertSame(1.0, $testSession['Q02.SCORE']->getValue());
     $testSession->moveNext();
     // Q03 - Success
     $testSession->beginAttempt();
     $testSession->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceC')))));
     $this->assertSame(1.0, $testSession['Q03.SCORE']->getValue());
     $testSession->moveNext();
     $this->assertEquals(AssessmentTestSessionState::CLOSED, $testSession->getState());
     // -- Let's test the submitted results.
     $submittedTestResults = $testSession->getSubmittedTestResults();
     $submittedItemResults = $testSession->getSubmittedItemResults();
     // Test Item Q01.
     $this->assertSame(0.0, $submittedItemResults['Q01.0.SCORE'][0]->getValue());
     // Test Item Q02.
     $this->assertSame(1.0, $submittedItemResults['Q02.0.SCORE'][0]->getValue());
     // Test Item Q03.
     $this->assertSame(1.0, $submittedItemResults['Q03.0.SCORE'][0]->getValue());
     // Test Results (submitted once).
     $this->assertSame(round(0.66666, 3), round($submittedTestResults['TEST_SCORE'][0]->getValue(), 3));
     $this->assertEquals(1, count($submittedTestResults['TEST_SCORE']));
 }
 public function testSeekPosition()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/itemsubset.xml');
     $seeker = new AssessmentTestSeeker($doc->getDocumentComponent(), array('assessmentItemRef', 'assessmentSection'));
     $this->assertEquals(1, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('Q02')));
     $this->assertEquals(0, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('Q01')));
     $this->assertEquals(0, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('S01')));
     $this->assertEquals(2, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('S03')));
     $this->assertEquals(2, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('Q03')));
     $this->assertEquals(1, $seeker->seekPosition($doc->getDocumentComponent()->getComponentByIdentifier('S02')));
     try {
         $pos = $seeker->seekPosition(new AssessmentItemRef('Q05', 'Q05.xml'));
         $this->assertFalse(true, "Nothing should be found for Q05.");
     } catch (OutOfBoundsException $e) {
         $this->assertTrue(true);
     }
     try {
         $pos = $seeker->seekPosition(new Correct('Q01.SCORE'));
         $this->assertFalse(true, "The 'correct' QTI class is not registered with the AssessmentTestSeeker object.");
     } catch (OutOfBoundsException $e) {
         $this->assertTrue(true);
     }
 }
 /**
  * @dataProvider branchingMultipleOccurencesProvider
  */
 public function testBranchingMultipleOccurences($response, $expectedTarget, $occurence)
 {
     // This test aims at testing the possibility to jump
     // on a particular item ref occurence.
     $doc = new XmlCompactDocument('1.0');
     $doc->load(self::samplesDir() . 'custom/runtime/branchings/branchings_multiple_occurences.xml');
     $manager = new SessionManager();
     $testSession = $manager->createAssessmentTestSession($doc->getDocumentComponent());
     $testSession->beginTestSession();
     $testSession->beginAttempt();
     if (empty($response) === true) {
         $testSession->skip();
         $testSession->moveNext();
     } else {
         $testSession->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, $response))));
         $testSession->moveNext();
     }
     $this->assertEquals($expectedTarget, $testSession->getCurrentAssessmentItemRef()->getIdentifier());
     $this->assertEquals($occurence, $testSession->getCurrentAssessmentItemRefOccurence());
 }
 public function testWritePendingResponses()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/itemsubset_simultaneous.xml');
     $seeker = new AssessmentTestSeeker($doc->getDocumentComponent(), array('assessmentItemRef', 'assessmentSection', 'testPart', 'outcomeDeclaration', 'responseDeclaration', 'branchRule', 'preCondition'));
     $stream = new MemoryStream();
     $stream->open();
     $access = new QtiBinaryStreamAccess($stream, new FileSystemFileManager());
     $factory = new SessionManager();
     $session = $factory->createAssessmentTestSession($doc->getDocumentComponent());
     $session->beginTestSession();
     $session->beginAttempt();
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceB')))));
     $store = $session->getPendingResponseStore();
     $pendingResponses = $store->getPendingResponses($doc->getDocumentComponent()->getComponentByIdentifier('Q01'));
     $access->writePendingResponses($seeker, $pendingResponses);
     $stream->rewind();
     $pendingResponses = $access->readPendingResponses($seeker);
     $state = $pendingResponses->getState();
     $this->assertEquals('ChoiceB', $state['RESPONSE']->getValue());
     $this->assertEquals('Q01', $pendingResponses->getAssessmentItemRef()->getIdentifier());
     $this->assertEquals(0, $pendingResponses->getOccurence());
     $this->assertInternalType('integer', $pendingResponses->getOccurence());
 }
 /**
  * Compile the items referended by $compactDoc.
  * 
  * @param XmlCompactDocument $compactDoc An XmlCompactDocument object referencing the items of the test.
  * @throws taoQtiTest_models_classes_QtiTestCompilationFailedException If the test does not refer to at least one item.
  * @return common_report_Report
  */
 protected function compileItems(XmlCompactDocument $compactDoc)
 {
     $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Items Compilation'));
     $iterator = new QtiComponentIterator($compactDoc->getDocumentComponent(), array('assessmentItemRef'));
     $itemCount = 0;
     foreach ($iterator as $assessmentItemRef) {
         // Each item could take some time to be compiled, making the request to timeout.
         helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::SHORT);
         $itemToCompile = new core_kernel_classes_Resource($assessmentItemRef->getHref());
         $subReport = $this->subCompile($itemToCompile);
         $report->add($subReport);
         if ($subReport->getType() == common_report_Report::TYPE_SUCCESS) {
             $itemService = $subReport->getdata();
             $inputValues = tao_models_classes_service_ServiceCallHelper::getInputValues($itemService, array());
             $assessmentItemRef->setHref($inputValues['itemUri'] . '|' . $inputValues['itemPath'] . '|' . $inputValues['itemDataPath']);
         } else {
             $report->setType(common_report_Report::TYPE_ERROR);
         }
         // Count the item even if it fails to avoid false "no item" error.
         $itemCount++;
         common_Logger::t("QTI Item successfully compiled and registered as a service call in the QTI Test Definition.");
     }
     if ($itemCount === 0) {
         $report->setType(common_report_Report::TYPE_ERROR);
         $report->setMessage(__("A QTI Test must contain at least one QTI Item to be compiled. None found."));
     }
     return $report;
 }
 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());
 }
 public function testEmptySection()
 {
     // Aims at testing that even a section of the test is empty,
     // it is simply ignored at runtime.
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/empty_section.xml');
     $manager = new SessionManager();
     $session = $manager->createAssessmentTestSession($doc->getDocumentComponent());
     $session->beginTestSession();
     // First section contains a single item.
     $this->assertEquals('Q01', $session->getCurrentAssessmentItemRef()->getIdentifier());
     $session->beginAttempt();
     $session->skip();
     $session->moveNext();
     // The second section is empty, moveNext() goes to the end of the current route,
     // and the session is then closed.
     $this->assertEquals(AssessmentTestSessionState::CLOSED, $session->getState());
 }
 public function testIsTimeout()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/linear_5_items.xml');
     $manager = new SessionManager();
     $session = $manager->createAssessmentTestSession($doc->getDocumentComponent());
     // If the session has not begun, the method systematically returns false.
     $this->assertFalse($session->isTimeout());
     // If no time limits in force, the test session is never considered timeout while running.
     $session->beginTestSession();
     $this->assertSame(0, $session->isTimeout());
     // Q01.
     $session->beginAttempt();
     $this->assertSame(0, $session->isTimeout());
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA')))));
     $this->assertSame(0, $session->isTimeout());
     $session->moveNext();
     // Q02.
     $session->beginAttempt();
     $this->assertSame(0, $session->isTimeout());
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB')))));
     $this->assertSame(0, $session->isTimeout());
     $session->moveNext();
     // Q03.
     $session->beginAttempt();
     $this->assertSame(0, $session->isTimeout());
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceC')))));
     $this->assertSame(0, $session->isTimeout());
     $session->moveNext();
     // Q04.
     $session->beginAttempt();
     $this->assertSame(0, $session->isTimeout());
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceD')))));
     $this->assertSame(0, $session->isTimeout());
     $session->moveNext();
     // Q05.
     $session->beginAttempt();
     $this->assertSame(0, $session->isTimeout());
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceE')))));
     $this->assertSame(0, $session->isTimeout());
     $session->moveNext();
     // If the session is closed, the method systematically returns false.
     $this->assertEquals(AssessmentTestSessionState::CLOSED, $session->getState());
     $this->assertFalse($session->isTimeout());
 }
 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 testTestFeedbackRefLoad()
 {
     $src = self::samplesDir() . 'custom/runtime/test_feedback_refs.xml';
     $doc = new XmlCompactDocument();
     $doc->load($src, true);
     $test = $doc->getDocumentComponent();
     $testFeedbackRefs = $test->getComponentsByClassName('testFeedbackRef');
     $this->assertEquals(3, count($testFeedbackRefs));
 }
 public function testTemplateDefault1()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/templates/template_test_simple.xml');
     $test = $doc->getDocumentComponent();
     $sessionManager = new SessionManager($doc->getDocumentComponent());
     $storage = new TemporaryQtiBinaryStorage($sessionManager, new BinaryAssessmentTestSeeker($test));
     $session = $storage->instantiate($test);
     $sessionId = $session->getSessionId();
     // Let's try to persist a not begun session.
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // The session is instantiated, but not yet begun.
     $this->assertEquals(AssessmentTestSessionState::INITIAL, $session->getState());
     // The session begins...
     $session->beginTestSession();
     $this->assertEquals(AssessmentTestSessionState::INTERACTING, $session->getState());
     // We are in linear, non adaptive test. In this context, all item sessions
     // should be already begun.
     $QTPL1Sessions = $session->getAssessmentItemSessions('QTPL1');
     $QTPL1Session = $QTPL1Sessions[0];
     // The the session is correctly instantiated, with the <templateDefault>s in force.
     $this->assertEquals(AssessmentItemSessionState::INITIAL, $QTPL1Session->getState());
     $this->assertEquals(1.0, $QTPL1Session->getVariable('GOODSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(0.0, $QTPL1Session->getVariable('WRONGSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(1.0, $session['QTPL1.GOODSCORE']->getValue());
     $this->assertEquals(1.0, $QTPL1Session['GOODSCORE']->getValue());
     $this->assertEquals(0.0, $session['QTPL1.WRONGSCORE']->getValue());
     $this->assertEquals(0.0, $QTPL1Session['WRONGSCORE']->getValue());
     $QTPL2Sessions = $session->getAssessmentItemSessions('QTPL2');
     $QTPL2Session = $QTPL2Sessions[0];
     $this->assertEquals(AssessmentItemSessionState::INITIAL, $QTPL2Session->getState());
     $this->assertEquals(2.0, $QTPL2Session->getVariable('GOODSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(-1.0, $QTPL2Session->getVariable('WRONGSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(2.0, $session['QTPL2.GOODSCORE']->getValue());
     $this->assertEquals(2.0, $QTPL2Session['GOODSCORE']->getValue());
     $this->assertEquals(-1.0, $session['QTPL2.WRONGSCORE']->getValue());
     $this->assertEquals(-1.0, $QTPL2Session['WRONGSCORE']->getValue());
     // Now let's make sure the persistence works correctly when <templateDefault>s are in force...
     // We do this by testing again that default values are correctly initialized within their respective
     // item sessions...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     $this->assertEquals(AssessmentItemSessionState::INITIAL, $QTPL1Session->getState());
     $this->assertEquals(1.0, $QTPL1Session->getVariable('GOODSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(0.0, $QTPL1Session->getVariable('WRONGSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(1.0, $session['QTPL1.GOODSCORE']->getValue());
     $this->assertEquals(1.0, $QTPL1Session['GOODSCORE']->getValue());
     $this->assertEquals(0.0, $session['QTPL1.WRONGSCORE']->getValue());
     $this->assertEquals(0.0, $QTPL1Session['WRONGSCORE']->getValue());
     $QTPL2Sessions = $session->getAssessmentItemSessions('QTPL2');
     $QTPL2Session = $QTPL2Sessions[0];
     $this->assertEquals(AssessmentItemSessionState::INITIAL, $QTPL2Session->getState());
     $this->assertEquals(2.0, $QTPL2Session->getVariable('GOODSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(-1.0, $QTPL2Session->getVariable('WRONGSCORE')->getDefaultValue()->getValue());
     $this->assertEquals(2.0, $session['QTPL2.GOODSCORE']->getValue());
     $this->assertEquals(2.0, $QTPL2Session['GOODSCORE']->getValue());
     $this->assertEquals(-1.0, $session['QTPL2.WRONGSCORE']->getValue());
     $this->assertEquals(-1.0, $QTPL2Session['WRONGSCORE']->getValue());
     // It seems to be ok! Let's take the test!
     $session->beginAttempt();
     // TPL1's responses should be applied their default values if any at the
     // beginning of the first attempt.
     $this->assertEquals(null, $session['QTPL1.RESPONSE']);
     // Noisy persistence ...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // TPL1's response should still be at their default.
     $this->assertEquals(null, $session['QTPL1.RESPONSE']);
     // -- TPL1 - Correct response.
     $candidateResponses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA'))));
     $session->endAttempt($candidateResponses);
     $this->assertEquals(1.0, $session['QTPL1.SCORE']->getValue());
     // Noisy persistence...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     $this->assertEquals('ChoiceA', $session['QTPL1.RESPONSE']->getValue());
     $this->assertEquals(1.0, $session['QTPL1.SCORE']->getValue());
     $session->moveNext();
     // Noisy persistence...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // -- TPL2 - Correct response.
     $session->beginAttempt();
     // TPL2's responses should be at their default values if any at
     // the beginning of the first attempt.
     $this->assertEquals(null, $session['QTPL2.RESPONSE']);
     // Noisy persistence ...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // TPL2's response should still be at their default.
     $this->assertEquals(null, $session['QTPL2.RESPONSE']);
     // -- TPL2 - Incorrect response.
     $candidateResponses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceC'))));
     $session->endAttempt($candidateResponses);
     $this->assertEquals(-1.0, $session['QTPL2.SCORE']->getValue());
     // Noisy persistence...
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     $this->assertEquals('ChoiceC', $session['QTPL2.RESPONSE']->getValue());
     $this->assertEquals(-1.0, $session['QTPL2.SCORE']->getValue());
     // -- Go to the end of test.
     $session->moveNext();
     // Check states...
     $QTPL1Sessions = $session->getAssessmentItemSessions('QTPL1');
     $QTPL1Session = $QTPL1Sessions[0];
     $QTPL2Sessions = $session->getAssessmentItemSessions('QTPL2');
     $QTPL2Session = $QTPL2Sessions[0];
     $this->assertEquals(AssessmentTestSessionState::CLOSED, $session->getState());
     $this->assertEquals(AssessmentItemSessionState::CLOSED, $QTPL1Session->getState());
     $this->assertEquals(AssessmentItemSessionState::CLOSED, $QTPL2Session->getState());
 }
Exemple #17
0
<?php

require_once dirname(__FILE__) . '/../../../../vendor/autoload.php';
use qtism\data\storage\php\PhpDocument;
use qtism\data\storage\xml\XmlCompactDocument;
$test = $argv[1];
$xmlFile = dirname(__FILE__) . "/../runtime/{$test}.xml";
$xmlDoc = new XmlCompactDocument();
$xmlDoc->load($xmlFile);
$phpDoc = new PhpDocument();
$phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent());
$phpDoc->save("{$test}.php");
 public function testLoadRubricBlockRefs(XmlCompactDocument $doc = null)
 {
     if (empty($doc) === true) {
         $src = self::samplesDir() . 'custom/runtime/rubricblockref.xml';
         $doc = new XmlCompactDocument();
         $doc->load($src, true);
     }
     // It validates !
     $this->assertInstanceOf('qtism\\data\\AssessmentTest', $doc->getDocumentComponent());
     // Did we retrieve the section as ExtendedAssessmentSection objects?
     $sections = $doc->getDocumentComponent()->getComponentsByClassName('assessmentSection');
     $this->assertEquals(1, count($sections));
     $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentSection', $sections[0]);
     // Retrieve rubricBlockRefs.
     $rubricBlockRefs = $doc->getDocumentComponent()->getComponentsByClassName('rubricBlockRef');
     $this->assertEquals(1, count($rubricBlockRefs));
     $rubricBlockRef = $rubricBlockRefs[0];
     $this->assertInstanceOf('qtism\\data\\content\\RubricBlockRef', $rubricBlockRef);
     $this->assertEquals('R01', $rubricBlockRef->getIdentifier());
     $this->assertEquals('./R01.xml', $rubricBlockRef->getHref());
 }
 public function testFiles()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/files/files.xml');
     $test = $doc->getDocumentComponent();
     $sessionManager = new SessionManager($doc->getDocumentComponent());
     $storage = new TemporaryQtiBinaryStorage($sessionManager, new BinaryAssessmentTestSeeker($test));
     $session = $storage->instantiate($test);
     $session->beginTestSession();
     $sessionId = $session->getSessionId();
     // --- Q01 - files_1.txt = ('text.txt', 'text/plain', 'Some text...')
     $session->beginAttempt();
     $filepath = self::samplesDir() . 'datatypes/file/files_1.txt';
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::FILE, FileSystemFile::retrieveFile($filepath)))));
     $session->moveNext();
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q01.RESPONSE']);
     $this->assertEquals('text.txt', $session['Q01.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q01.RESPONSE']->getMimeType());
     $this->assertEquals('Some text...', $session['Q01.RESPONSE']->getData());
     // Let's persist and retrieve and look if we have the same value in Q01.RESPONSE.
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q01.RESPONSE']);
     $this->assertEquals('text.txt', $session['Q01.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q01.RESPONSE']->getMimeType());
     $this->assertEquals('Some text...', $session['Q01.RESPONSE']->getData());
     // --- Q02 - files_2.txt = ('', 'text/html', '<img src="/qtism/img.png"/>')
     $session->beginAttempt();
     $filepath = self::samplesDir() . 'datatypes/file/files_2.txt';
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::FILE, FileSystemFile::retrieveFile($filepath)))));
     $session->moveNext();
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q02.RESPONSE']);
     $this->assertEquals('', $session['Q02.RESPONSE']->getFilename());
     $this->assertEquals('text/html', $session['Q02.RESPONSE']->getMimeType());
     $this->assertEquals('<img src="/qtism/img.png"/>', $session['Q02.RESPONSE']->getData());
     // Again, we persist and retrieve.
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // We now test all the collected variables.
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q01.RESPONSE']);
     $this->assertEquals('text.txt', $session['Q01.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q01.RESPONSE']->getMimeType());
     $this->assertEquals('Some text...', $session['Q01.RESPONSE']->getData());
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q02.RESPONSE']);
     $this->assertEquals('', $session['Q02.RESPONSE']->getFilename());
     $this->assertEquals('text/html', $session['Q02.RESPONSE']->getMimeType());
     $this->assertEquals('<img src="/qtism/img.png"/>', $session['Q02.RESPONSE']->getData());
     // --- Q03 - files_3.txt ('empty.txt', 'text/plain', '')
     $session->beginAttempt();
     $filepath = self::samplesDir() . 'datatypes/file/files_3.txt';
     $session->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::FILE, FileSystemFile::retrieveFile($filepath)))));
     $session->moveNext();
     $this->assertFalse($session->isRunning());
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q02.RESPONSE']);
     $this->assertEquals('empty.txt', $session['Q03.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q03.RESPONSE']->getMimeType());
     $this->assertEquals('', $session['Q03.RESPONSE']->getData());
     $storage->persist($session);
     unset($session);
     $session = $storage->retrieve($test, $sessionId);
     // Final big check.
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q01.RESPONSE']);
     $this->assertEquals('text.txt', $session['Q01.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q01.RESPONSE']->getMimeType());
     $this->assertEquals('Some text...', $session['Q01.RESPONSE']->getData());
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q02.RESPONSE']);
     $this->assertEquals('', $session['Q02.RESPONSE']->getFilename());
     $this->assertEquals('text/html', $session['Q02.RESPONSE']->getMimeType());
     $this->assertEquals('<img src="/qtism/img.png"/>', $session['Q02.RESPONSE']->getData());
     $this->assertInstanceOf('qtism\\common\\datatypes\\File', $session['Q02.RESPONSE']);
     $this->assertEquals('empty.txt', $session['Q03.RESPONSE']->getFilename());
     $this->assertEquals('text/plain', $session['Q03.RESPONSE']->getMimeType());
     $this->assertEquals('', $session['Q03.RESPONSE']->getData());
 }