public function testReadAssessmentItemSession()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/itemsubset.xml');
     $position = pack('S', 0);
     // Q01
     $state = "";
     // INTERACTING
     $navigationMode = "";
     // LINEAR
     $submissionMode = "";
     // INDIVIDUAL
     $attempting = "";
     // false
     $hasItemSessionControl = "";
     // false
     $numAttempts = "";
     // 2
     $duration = pack('S', 4) . 'PT0S';
     // 0 seconds recorded yet.
     $completionStatus = pack('S', 10) . 'incomplete';
     $timeReference = pack('l', 1378302030);
     //  Wednesday, September 4th 2013, 13:40:30 (GMT)
     $varCount = "";
     // 2 variables (SCORE & RESPONSE).
     $score = "" . pack('S', 8) . "" . "" . pack('d', 1.0);
     $response = "" . pack('S', 0) . "" . "" . pack('S', 7) . 'ChoiceA';
     $bin = implode('', array($position, $state, $navigationMode, $submissionMode, $attempting, $hasItemSessionControl, $numAttempts, $duration, $completionStatus, $timeReference, $varCount, $score, $response));
     $stream = new MemoryStream($bin);
     $stream->open();
     $access = new QtiBinaryStreamAccessFsfile($stream);
     $seeker = new AssessmentTestSeeker($doc->getDocumentComponent(), array('assessmentItemRef', 'outcomeDeclaration', 'responseDeclaration', 'itemSessionControl'));
     $session = $access->readAssessmentItemSession(new SessionManager(), $seeker);
     $this->assertEquals('Q01', $session->getAssessmentItem()->getIdentifier());
     $this->assertEquals(AssessmentItemSessionState::INTERACTING, $session->getState());
     $this->assertEquals(NavigationMode::LINEAR, $session->getNavigationMode());
     $this->assertEquals(SubmissionMode::INDIVIDUAL, $session->getSubmissionMode());
     $this->assertEquals(2, $session['numAttempts']->getValue());
     $this->assertEquals('PT0S', $session['duration']->__toString());
     $this->assertEquals('incomplete', $session['completionStatus']->getValue());
     $this->assertInstanceOf('qtism\\runtime\\common\\OutcomeVariable', $session->getVariable('scoring'));
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $session['scoring']);
     $this->assertEquals(1.0, $session['scoring']->getValue());
     $this->assertInstanceOf('qtism\\runtime\\common\\ResponseVariable', $session->getVariable('RESPONSE'));
     $this->assertEquals(BaseType::IDENTIFIER, $session->getVariable('RESPONSE')->getBaseType());
     $this->assertInstanceOf('qtism\\common\\datatypes\\String', $session['RESPONSE']);
     $this->assertEquals('ChoiceA', $session['RESPONSE']->getValue());
 }
 /**
  * @depends testReadAssessmentItemSession1
  */
 public function testReadAssessmentItemSession2()
 {
     $doc = new XmlCompactDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/templatevariables_in_items.xml');
     $position = pack('S', 0);
     // Q01
     $state = "";
     // CLOSED
     $navigationMode = "";
     // NONLINEAR
     $submissionMode = "";
     // SIMULTANEOUS
     $attempting = "";
     // false
     $hasItemSessionControl = "";
     // false
     $numAttempts = "";
     // 1
     $duration = pack('S', 5) . 'PT20S';
     // 20 seconds recorded.
     $completionStatus = pack('S', 8) . 'complete';
     $hasTimeReference = "";
     // true
     $timeReference = pack('l', 1378302030);
     //  Wednesday, September 4th 2013, 13:40:30 (GMT)
     $varCount = "";
     // 3 variables (SCORE & RESPONSE & TPL)
     $score = pack('S', 0) . pack('S', 0) . "" . "" . "" . "" . pack('d', 1.0);
     // 1st (0 + 1) outcomeDeclaration.
     $response = pack('S', 1) . pack('S', 0) . "" . "" . "" . "" . pack('S', 7) . 'ChoiceA';
     // 1st (0 + 1) responseDeclaration.
     $template = pack('S', 2) . pack('S', 0) . "" . "" . "" . "" . pack('l', 10);
     // 1st (0 + 1) templateDeclaration.
     $shufflingCount = "";
     // No shuffling states.
     $binArray = array($position, $state, $navigationMode, $submissionMode, $attempting, $hasItemSessionControl, $numAttempts, $duration, $completionStatus, $hasTimeReference, $timeReference, $varCount, $score, $response, $template, $shufflingCount);
     $bin = implode('', $binArray);
     $stream = new MemoryStream($bin);
     $stream->open();
     $access = new QtiBinaryStreamAccessFsfile($stream);
     $seeker = new AssessmentTestSeeker($doc->getDocumentComponent(), array('assessmentItemRef', 'outcomeDeclaration', 'responseDeclaration', 'templateDeclaration', 'itemSessionControl'));
     $session = $access->readAssessmentItemSession(new SessionManager(), $seeker);
     $this->assertEquals('Q01', $session->getAssessmentItem()->getIdentifier());
     $this->assertEquals(AssessmentItemSessionState::CLOSED, $session->getState());
     $this->assertEquals(NavigationMode::NONLINEAR, $session->getNavigationMode());
     $this->assertEquals(SubmissionMode::SIMULTANEOUS, $session->getSubmissionMode());
     $this->assertFalse($session->isAttempting(false));
     $this->assertEquals(1, $session['numAttempts']->getValue());
     $this->assertEquals('PT20S', $session['duration']->__toString());
     $this->assertEquals('complete', $session['completionStatus']->getValue());
     $this->assertInstanceOf('qtism\\runtime\\common\\OutcomeVariable', $session->getVariable('SCORE'));
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $session['SCORE']);
     $this->assertEquals(1.0, $session['SCORE']->getValue());
     $this->assertInstanceOf('qtism\\runtime\\common\\ResponseVariable', $session->getVariable('RESPONSE'));
     $this->assertSame(BaseType::IDENTIFIER, $session->getVariable('RESPONSE')->getBaseType());
     $this->assertInstanceOf('qtism\\common\\datatypes\\String', $session['RESPONSE']);
     $this->assertEquals('ChoiceA', $session['RESPONSE']->getValue());
     $this->assertInstanceOf('qtism\\runtime\\common\\TemplateVariable', $session->getVariable('TPL'));
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $session['TPL']);
     $this->assertSame(10, $session['TPL']->getValue());
 }