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());
 }
 /**
  * Apply the templateDefault values to the item $session.
  * 
  * param \qtism\runtime\tests\AssessmentItemSession $session
  * @throws \qtism\runtime\expressions\ExpressionProcessingException|\qtism\runtime\expressions\operators\OperatorProcessingException If something wrong happens when initializing templateDefaults.
  */
 protected function applyTemplateDefaults(AssessmentItemSession $session)
 {
     $templateDefaults = $session->getAssessmentItem()->getTemplateDefaults();
     if (count($templateDefaults) > 0) {
         // Some templateVariable default values must have to be changed...
         foreach ($session->getAssessmentItem()->getTemplateDefaults() as $templateDefault) {
             $identifier = $templateDefault->getTemplateIdentifier();
             $expression = $templateDefault->getExpression();
             $variable = $session->getVariable($identifier);
             $expressionEngine = new ExpressionEngine($expression, $this);
             if (is_null($variable) === false) {
                 $val = $expressionEngine->process();
                 $variable->setDefaultValue($val);
             }
         }
     }
 }
 /**
  * AssessmentTestSession implementations must override this method in order
  * to submit item results from a given $assessmentItemSession to the appropriate
  * data source.
  *
  * This method is triggered each time response processing takes place.
  *
  * @param AssessmentItemSession $itemSession The lastly updated AssessmentItemSession.
  * @param integer $occurrence The occurrence number of the item bound to $assessmentItemSession.
  * @throws AssessmentTestSessionException With error code RESULT_SUBMISSION_ERROR if an error occurs while transmitting results.
  */
 public function submitItemResults(AssessmentItemSession $itemSession, $occurrence = 0)
 {
     $itemRef = $itemSession->getAssessmentItem();
     $identifier = $itemRef->getIdentifier();
     $duration = $this->getTimerDuration($identifier);
     $itemDurationVar = $itemSession->getVariable('duration');
     $sessionDuration = $itemDurationVar->getValue();
     \common_Logger::i("Force duration of item '{$identifier}' to {$duration} instead of {$sessionDuration}");
     $itemSession->getVariable('duration')->setValue($duration);
     parent::submitItemResults($itemSession, $occurrence);
 }
 /**
  * Transmit the variables contained in the AssessmentTestSession $itemSession as
  * item results to the Result Server.
  * 
  * @param core_kernel_classes_Resource $item The item definition in database.
  * @param AssessmentItemSession $itemSession The AssessmentItemSession objects from where the results must be extracted.
  * @throws taoQtiCommon_helpers_ResultTransmissionException If an error occurs while transmitting results to the ResultServer.
  */
 protected function transmitResults(core_kernel_classes_Resource $item, AssessmentItemSession $itemSession)
 {
     $resultTransmitter = new taoQtiCommon_helpers_ResultTransmitter(taoResultServer_models_classes_ResultServerStateFull::singleton());
     foreach ($itemSession->getKeys() as $identifier) {
         // QTI built-in variables not suitable for this standalone QTI item execution case.
         if (!in_array($identifier, array('completionStatus', 'numAttempts', 'duration'))) {
             // Transmit to Result Server.
             $resultTransmitter->transmitItemVariable($itemSession->getVariable($identifier), $this->getServiceCallId(), $item->getUri());
         }
     }
 }