public function testMarshallMaximal()
 {
     $identifier = 'question1';
     $href = '../../question1.xml';
     $required = true;
     $fixed = true;
     $preConditions = new PreConditionCollection();
     $preConditions[] = new PreCondition(new BaseValue(BaseType::BOOLEAN, true));
     $preConditions[] = new PreCondition(new BaseValue(BaseType::BOOLEAN, false));
     $branchRules = new BranchRuleCollection();
     $branchRules[] = new BranchRule(new BaseValue(BaseType::INTEGER, 1), 'target1');
     $branchRules[] = new BranchRule(new BaseValue(BaseType::INTEGER, 2), 'target2');
     $itemSessionControl = new ItemSessionControl();
     $timeLimits = new TimeLimits();
     $timeLimits->setMaxTime(new Duration('PT50S'));
     // 50 seconds.
     $variableMappings = new VariableMappingCollection();
     $variableMappings[] = new VariableMapping('var1', 'var2');
     $variableMappings[] = new VariableMapping('var3', 'var4');
     $weights = new WeightCollection();
     $weights[] = new Weight('weight1', 1.5);
     $templateDefaults = new TemplateDefaultCollection();
     $templateDefaults[] = new TemplateDefault('tpl1', new BaseValue(BaseType::INTEGER, 15));
     $categories = new IdentifierCollection(array('cat1', 'cat2'));
     $component = new AssessmentItemRef($identifier, $href, $categories);
     $component->setRequired($required);
     $component->setFixed($fixed);
     $component->setPreConditions($preConditions);
     $component->setBranchRules($branchRules);
     $component->setItemSessionControl($itemSessionControl);
     $component->setTimeLimits($timeLimits);
     $component->setWeights($weights);
     $component->setVariableMappings($variableMappings);
     $component->setTemplateDefaults($templateDefaults);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('assessmentItemRef', $element->nodeName);
     $this->assertEquals($identifier, $element->getAttribute('identifier'));
     $this->assertEquals($href, $element->getAttribute('href'));
     $this->assertEquals(implode(" ", $categories->getArrayCopy()), $element->getAttribute('category'));
     $this->assertEquals('true', $element->getAttribute('required'));
     $this->assertEquals('true', $element->getAttribute('fixed'));
     $weightElts = $element->getElementsByTagName('weight');
     $this->assertEquals(1, $weightElts->length);
     $templateDefaultElts = $element->getElementsByTagName('templateDefault');
     $this->assertEquals(1, $templateDefaultElts->length);
     $variableMappingsElts = $element->getElementsByTagName('variableMapping');
     $this->assertEquals(2, $variableMappingsElts->length);
     $preConditionElts = $element->getElementsByTagName('preCondition');
     $this->assertEquals(2, $preConditionElts->length);
     $branchRuleElts = $element->getElementsByTagName('branchRule');
     $this->assertEquals(2, $branchRuleElts->length);
     $itemSessionControlElts = $element->getElementsByTagName('itemSessionControl');
     $this->assertEquals(1, $itemSessionControlElts->length);
     $timeLimitsElts = $element->getElementsByTagName('timeLimits');
     $this->assertEquals(1, $timeLimitsElts->length);
 }
Esempio n. 2
0
 /**
  * Unmarshall a DOMElement object corresponding to a QTI timeLimits element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A TimeLimits object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the attribute 'allowLateSubmission' is not a valid boolean value.
  */
 protected function unmarshall(DOMElement $element)
 {
     $object = new TimeLimits();
     if (($value = static::getDOMElementAttributeAs($element, 'minTime', 'string')) !== null) {
         $object->setMinTime(StorageUtils::stringToDatatype("PT{$value}S", BaseType::DURATION));
     }
     if (($value = static::getDOMElementAttributeAs($element, 'maxTime', 'string')) !== null) {
         $object->setMaxTime(StorageUtils::stringToDatatype("PT{$value}S", BaseType::DURATION));
     }
     if (($value = static::getDOMElementAttributeAs($element, 'allowLateSubmission', 'boolean')) !== null) {
         $object->setAllowLateSubmission($value);
     }
     return $object;
 }
 public function testRemainingTimeOne()
 {
     $itemSession = self::instantiateBasicAssessmentItemSession();
     $this->assertFalse($itemSession->getRemainingTime());
     $timeLimits = new TimeLimits();
     $timeLimits->setMaxTime(new Duration('PT3S'));
     $itemSession->setTimeLimits($timeLimits);
     $itemSession->beginItemSession();
     $this->assertEquals(1, $itemSession->getRemainingAttempts());
     $this->assertTrue($itemSession->getRemainingTime()->equals(new Duration('PT3S')));
     $itemSession->beginAttempt();
     sleep(2);
     $itemSession->updateDuration();
     $this->assertTrue($itemSession->getRemainingTime()->equals(new Duration('PT1S')));
     sleep(1);
     $itemSession->updateDuration();
     $this->assertTrue($itemSession->getRemainingTime()->equals(new Duration('PT0S')));
     sleep(1);
     $itemSession->updateDuration();
     // It is still 0...
     $this->assertTrue($itemSession->getRemainingTime()->equals(new Duration('PT0S')));
     try {
         $itemSession->endAttempt(new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceB')))));
         // Must be rejected, no more time remaining!!!
         $this->assertFalse(true);
     } catch (AssessmentItemSessionException $e) {
         $this->assertEquals(AssessmentItemSessionException::DURATION_OVERFLOW, $e->getCode());
         $this->assertTrue($itemSession->getRemainingTime()->equals(new Duration('PT0S')));
     }
 }
 /**
  * Whether or not the maximum time limits in force are reached. If there is
  * no time limits in force, this method systematically returns false.
  * 
  * @return boolean
  */
 protected function isMaxTimeReached()
 {
     $reached = false;
     if ($this->hasTimeLimits() && $this->timeLimits->hasMaxTime() === true) {
         if ($this['duration']->getSeconds(true) > $this->getDurationWithLatency($this->timeLimits->getMaxTime())->getSeconds(true)) {
             $reached = true;
         }
     }
     return $reached;
 }