public function testMarshall() { $select = 2; $withReplacement = true; $component = new Selection($select); $component->setWithReplacement($withReplacement); $marshaller = $this->getMarshallerFactory()->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('selection', $element->nodeName); $this->assertSame($select . '', $element->getAttribute('select')); $this->assertEquals('true', $element->getAttribute('withReplacement')); }
/** * Unmarshall a DOMElement object corresponding to a QTI Selection object. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent A Selection object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory 'select' attribute is missing from $element. */ protected function unmarshall(DOMElement $element) { // select is a mandatory value, retrieve it first. if (($value = static::getDOMElementAttributeAs($element, 'select', 'integer')) !== null) { $object = new Selection($value); if (($value = static::getDOMElementAttributeAs($element, 'withReplacement', 'boolean')) !== null) { $object->setWithReplacement($value); } } else { $msg = "The mandatory attribute 'select' is missing."; throw new UnmarshallingException($msg, $element); } return $object; }