public function testMarshall() { $uploadInteraction = new UploadInteraction('RESPONSE', 'my-upload'); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $uploadInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($uploadInteraction)->marshall($uploadInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<uploadInteraction id="my-upload" responseIdentifier="RESPONSE"><prompt>Prompt...</prompt></uploadInteraction>', $dom->saveXML($element)); }
/** * Unmarshall a DOMElement object corresponding to an uploadInteraction element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent An UploadInteraction object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $component = new UploadInteraction($responseIdentifier); $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($type = self::getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'uploadInteraction' element."; throw new UnmarshallingException($msg, $element); } }