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);
     }
 }
 /**
  * Create a new BinaryAssessmentTestSeeker object.
  *
  * @param \qtism\data\AssessmentTest $test
  */
 public function __construct(AssessmentTest $test)
 {
     $classes = array('assessmentItemRef', 'assessmentSection', 'testPart', 'outcomeDeclaration', 'responseDeclaration', 'templateDeclaration', 'branchRule', 'preCondition', 'itemSessionControl');
     parent::__construct($test, $classes);
 }
 /**
  * Write a PendingResponses object in the current binary stream.
  * 
  * @param AssessmentTestSeeker $seeker An AssessmentTestSeeker object from where positions in the assessmentTest tree will be pulled out.
  * @param PendingResponses $pendingResponses The read PendingResponses object.
  * @throws QtiBinaryStreamAccessException
  */
 public function writePendingResponses(AssessmentTestSeeker $seeker, PendingResponses $pendingResponses)
 {
     try {
         $state = $pendingResponses->getState();
         $itemRef = $pendingResponses->getAssessmentItemRef();
         $occurence = $pendingResponses->getOccurence();
         // Write the state.
         $responseDeclarations = $itemRef->getResponseDeclarations();
         $varCount = count($state);
         $this->writeTinyInt($varCount);
         foreach ($state as $responseVariable) {
             $respId = $responseVariable->getIdentifier();
             if (isset($responseDeclarations[$respId]) === true) {
                 $this->writeShort($seeker->seekPosition($responseDeclarations[$respId]));
                 $this->writeVariableValue($responseVariable);
             } else {
                 $msg = "No response variable with identifier '{$respId}' found in related assessmentItemRef.";
                 throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES);
             }
         }
         // Write the assessmentItemRef.
         $this->writeShort($seeker->seekPosition($itemRef));
         // Write the occurence number.
         $this->writeTinyInt($occurence);
     } catch (BinaryStreamAccessException $e) {
         $msg = "An error occured while reading some pending responses.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
     } catch (OutOfBoundsException $e) {
         $msg = "A QTI component position could not be found in the assessmentTest tree structure.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
     }
 }