public function testMarshallMaximal()
 {
     $assessmentSection1 = new ExtendedAssessmentSection('section1', 'My Section 1', true);
     $assessmentSection2 = new ExtendedAssessmentSection('section2', 'My Section 2', true);
     $preCondition = new PreCondition(new BaseValue(BaseType::BOOLEAN, true));
     $branching = new BranchRule(new BaseValue(BaseType::BOOLEAN, true), 'EXIT_TESTPART');
     $itemSessionControl = new ItemSessionControl();
     $itemSessionControl->setShowSolution(true);
     $timeLimits = new TimeLimits(null, new QtiDuration('PT1M40S'));
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('Prima!'))));
     $testFeedback = new TestFeedback('feedback1', 'show', new FlowStaticCollection(array($p)));
     $testFeedback->setTitle('hello!');
     $testFeedback->setAccess(TestFeedbackAccess::AT_END);
     $testFeedback->setShowHide(ShowHide::SHOW);
     $testFeedbackRef = new TestFeedbackRef('feedback1', 'show', TestFeedbackAccess::AT_END, ShowHide::SHOW, './TF01.xml');
     $assessmentSections = new AssessmentSectionCollection(array($assessmentSection1, $assessmentSection2));
     $preConditions = new PreConditionCollection(array($preCondition));
     $branchings = new BranchRuleCollection(array($branching));
     $testFeedbacks = new TestFeedbackCollection(array($testFeedback));
     $testFeedbackRefs = new TestFeedbackRefCollection(array($testFeedbackRef));
     $extendedTestPart = new ExtendedTestPart('part1', $assessmentSections);
     $extendedTestPart->setPreConditions($preConditions);
     $extendedTestPart->setBranchRules($branchings);
     $extendedTestPart->setItemSessionControl($itemSessionControl);
     $extendedTestPart->setTimeLimits($timeLimits);
     $extendedTestPart->setTestFeedbacks($testFeedbacks);
     $extendedTestPart->setTestFeedbackRefs($testFeedbackRefs);
     $factory = new CompactMarshallerFactory();
     $element = $factory->createMarshaller($extendedTestPart)->marshall($extendedTestPart);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<testPart identifier="part1" navigationMode="linear" submissionMode="individual"><preCondition><baseValue baseType="boolean">true</baseValue></preCondition><branchRule target="EXIT_TESTPART"><baseValue baseType="boolean">true</baseValue></branchRule><itemSessionControl maxAttempts="1" showFeedback="false" allowReview="true" showSolution="true" allowComment="false" allowSkipping="true" validateResponses="false"/><timeLimits maxTime="100" allowLateSubmission="false"/><assessmentSection identifier="section1" required="false" fixed="false" title="My Section 1" visible="true" keepTogether="true"/><assessmentSection identifier="section2" required="false" fixed="false" title="My Section 2" visible="true" keepTogether="true"/><testFeedback access="atEnd" outcomeIdentifier="show" showHide="show" identifier="feedback1" title="hello!"><p>Prima!</p></testFeedback><testFeedbackRef identifier="feedback1" outcomeIdentifier="show" access="atEnd" showHide="show" href="./TF01.xml"/></testPart>', $dom->saveXML($element));
 }
 /**
  * Unmarshall a DOMElement object corresponding to a QTI testFeedback element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A TestFeedback object.
  * @throws UnmarshallingException 
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($identifier = static::getDOMElementAttributeAs($element, 'identifier', 'string')) !== null) {
         if (($outcomeIdentifier = static::getDOMElementAttributeAs($element, 'outcomeIdentifier', 'string')) !== null) {
             if (($showHide = static::getDOMElementAttributeAs($element, 'showHide', 'string')) !== null) {
                 if (($access = static::getDOMElementAttributeAs($element, 'access', 'string')) !== null) {
                     $content = self::extractContent($element);
                     if (!empty($content)) {
                         $object = new TestFeedback($identifier, $outcomeIdentifier, $content);
                         $object->setAccess($access == 'atEnd' ? TestFeedbackAccess::AT_END : TestFeedbackAccess::DURING);
                         $object->setShowHide($showHide == 'show' ? ShowHide::SHOW : ShowHide::HIDE);
                         if (($title = static::getDOMElementAttributeAs($element, 'title', 'string')) !== null) {
                             $object->setTitle($title);
                         }
                         return $object;
                     } else {
                         $msg = "Element '" . $element->localName . "' has no feedback content.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 } else {
                     $msg = "The mandatory 'access' attribute is missing from element '" . $element->localName . "'.";
                     throw new UnmarshallingException($msg, $element);
                 }
             } else {
                 $msg = "The mandatory 'showHide' attribute is missing from element '" . $element->localName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Ejemplo n.º 3
0
 /**
  * Unmarshall a DOMElement object corresponding to a QTI testFeedback element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A TestFeedback object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($identifier = static::getDOMElementAttributeAs($element, 'identifier', 'string')) !== null) {
         if (($outcomeIdentifier = static::getDOMElementAttributeAs($element, 'outcomeIdentifier', 'string')) !== null) {
             if (($showHide = static::getDOMElementAttributeAs($element, 'showHide', 'string')) !== null) {
                 if (($access = static::getDOMElementAttributeAs($element, 'access', 'string')) !== null) {
                     $content = new FlowStaticCollection();
                     foreach (self::getChildElements($element, true) as $elt) {
                         if ($elt instanceof DOMText) {
                             $elt = self::getDOMCradle()->createElement('textRun', $elt->wholeText);
                         }
                         $marshaller = $this->getMarshallerFactory()->createMarshaller($elt);
                         $cpt = $marshaller->unmarshall($elt);
                         if ($cpt instanceof FlowStatic) {
                             $content[] = $cpt;
                         } else {
                             $msg = "'testFeedback' elements cannot contain '" . $cpt->getQtiClassName() . "' elements.";
                             throw new UnmarshallingException($msg, $element);
                         }
                     }
                     $object = new TestFeedback($identifier, $outcomeIdentifier, $content);
                     $object->setAccess($access == 'atEnd' ? TestFeedbackAccess::AT_END : TestFeedbackAccess::DURING);
                     $object->setShowHide($showHide == 'show' ? ShowHide::SHOW : ShowHide::HIDE);
                     if (($title = static::getDOMElementAttributeAs($element, 'title', 'string')) !== null) {
                         $object->setTitle($title);
                     }
                     return $object;
                 } else {
                     $msg = "The mandatory 'access' attribute is missing from element '" . $element->localName . "'.";
                     throw new UnmarshallingException($msg, $element);
                 }
             } else {
                 $msg = "The mandatory 'showHide' attribute is missing from element '" . $element->localName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }