public function testMarshallOne() { $uri = 'http://myuri.com'; $type = 'text/css'; $media = 'screen'; $title = 'A pure stylesheet'; $component = new Stylesheet($uri); $component->setType($type); $component->setMedia($media); $component->setTitle($title); $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('stylesheet', $element->nodeName); $this->assertEquals($uri, $element->getAttribute('href')); $this->assertEquals($type, $element->getAttribute('type')); $this->assertEquals($media, $element->getAttribute('media')); $this->assertEquals($title, $element->getAttribute('title')); }
/** * Unmarshall a DOMElement object corresponding to a QTI stylesheet element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent A Stylesheet object. * @throws UnmarshallingException If the mandatory attribute 'href' is missing from $element. */ protected function unmarshall(DOMElement $element) { // href is a mandatory value, retrieve it first. if (($value = static::getDOMElementAttributeAs($element, 'href', 'string')) !== null) { $object = new Stylesheet($value); if (($value = static::getDOMElementAttributeAs($element, 'type', 'string')) !== null) { $object->setType($value); } if (($value = static::getDOMElementAttributeAs($element, 'media', 'string')) !== null) { $object->setMedia($value); } if (($value = static::getDOMElementAttributeAs($element, 'title', 'string')) !== null) { $object->setTitle($value); } } else { $msg = "The mandatory attribute 'href' is missing."; throw new UnmarshallingException($msg, $element); } return $object; }