/** * Marshall an numberSelected QTI element in its NumberSelected object equivalent. * * @param DOMElement A DOMElement object. * @return QtiComponent The corresponding NumberSelected object. */ protected function unmarshall(DOMElement $element) { $baseComponent = parent::unmarshall($element); $object = new NumberSelected(); $object->setSectionIdentifier($baseComponent->getSectionIdentifier()); $object->setIncludeCategories($baseComponent->getIncludeCategories()); $object->setExcludeCategories($baseComponent->getExcludeCategories()); return $object; }
protected static function getNumberSelected($sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null) { $numberSelected = new NumberSelected(); $numberSelected->setSectionIdentifier($sectionIdentifier); if (empty($includeCategories) === false) { $numberSelected->setIncludeCategories($includeCategories); } if (empty($excludeCategories) === false) { $numberSelected->setExcludeCategories($excludeCategories); } return $numberSelected; }
public function testMarshall() { $sectionIdentifier = 'mySection1'; $includeCategory = 'cat1'; $excludeCategory = 'cat2 cat3'; $component = new NumberSelected(); $component->setSectionIdentifier($sectionIdentifier); $component->setIncludeCategories(new IdentifierCollection(explode(" ", $includeCategory))); $component->setExcludeCategories(new IdentifierCollection(explode(" ", $excludeCategory))); $marshaller = $this->getMarshallerFactory()->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('numberSelected', $element->nodeName); $this->assertEquals($sectionIdentifier, $element->getAttribute('sectionIdentifier')); $this->assertEquals($includeCategory, $element->getAttribute('includeCategory')); $this->assertEquals($excludeCategory, $element->getAttribute('excludeCategory')); }