public function testMarshall() { $identifier = 'myTestFeedBack1'; $outcomeIdentifier = 'myOutcomeIdentifier1'; $access = TestFeedbackAccess::AT_END; $showHide = ShowHide::SHOW; $text = new TextRun('Hello World!'); $p = new P(); $p->setContent(new InlineCollection(array($text))); $div = new Div(); $div->setContent(new FlowCollection(array($p))); $content = new FlowStaticCollection(array($div)); $component = new TestFeedback($identifier, $outcomeIdentifier, $content); $component->setAccess($access); $component->setShowHide($showHide); $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('testFeedback', $element->nodeName); $this->assertEquals($identifier, $element->getAttribute('identifier')); $this->assertEquals($outcomeIdentifier, $element->getAttribute('outcomeIdentifier')); $this->assertEquals('', $element->getAttribute('title')); $this->assertEquals('atEnd', $element->getAttribute('access')); $this->assertEquals('show', $element->getAttribute('showHide')); $content = $element->getElementsByTagName('div'); $this->assertEquals($content->length, 1); $this->assertEquals($content->item(0)->getElementsByTagName('p')->length, 1); }
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)); }
public function testMarshall() { $identifier = 'myTestFeedBack1'; $outcomeIdentifier = 'myOutcomeIdentifier1'; $access = TestFeedbackAccess::AT_END; $showHide = ShowHide::SHOW; $content = '<div><p>Hello World!</p></div>'; $component = new TestFeedback($identifier, $outcomeIdentifier, $content); $component->setAccess($access); $component->setShowHide($showHide); $marshaller = $this->getMarshallerFactory()->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('testFeedback', $element->nodeName); $this->assertEquals($identifier, $element->getAttribute('identifier')); $this->assertEquals($outcomeIdentifier, $element->getAttribute('outcomeIdentifier')); $this->assertEquals('', $element->getAttribute('title')); $this->assertEquals('atEnd', $element->getAttribute('access')); $this->assertEquals('show', $element->getAttribute('showHide')); $content = $element->getElementsByTagName('div'); $this->assertEquals($content->length, 1); $this->assertEquals($content->item(0)->getElementsByTagName('p')->length, 1); }
/** * 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); } }
/** * 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); } }