/** * Unmarshall a DOMElement object corresponding to a selectPointInteraction element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent A SelectPointInteraction object. * @throws UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $objectElts = self::getChildElementsByTagName($element, 'object'); if (count($objectElts) > 0) { $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]); if (($maxChoices = self::getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) { $component = new SelectPointInteraction($responseIdentifier, $object, $maxChoices); if (($minChoices = self::getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) { $component->setMinChoices($minChoices); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'maxChoices' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "A 'selectPointInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } }
/** * @depends testMarshall21 */ public function testMarshall20() { // Make sure minChoices is not in the output in a QTI 2.0 context. $object = new Object('./myimg.png', 'image/png'); $selectPointInteraction = new SelectPointInteraction('RESPONSE', $object, 1); $selectPointInteraction->setMinChoices(1); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($selectPointInteraction)->marshall($selectPointInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<selectPointInteraction responseIdentifier="RESPONSE" maxChoices="1"><object data="./myimg.png" type="image/png"/></selectPointInteraction>', $dom->saveXML($element)); }
public function testMarshall() { $object = new Object('./myimg.png', 'image/png'); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $selectPointInteraction = new SelectPointInteraction('RESPONSE', $object, 1); $selectPointInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory()->createMarshaller($selectPointInteraction)->marshall($selectPointInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<selectPointInteraction responseIdentifier="RESPONSE" maxChoices="1"><prompt>Prompt...</prompt><object data="./myimg.png" type="image/png"/></selectPointInteraction>', $dom->saveXML($element)); }