/** * @depends testMarshall20 */ public function testMarshallMatchGroup20() { $shape = QtiShape::RECT; $coords = new QtiCoords($shape, array(92, 19, 261, 66)); $matchMax = 2; $matchMin = 1; $showHide = ShowHide::HIDE; $templateIdentifier = 'XTEMPLATE'; $associableHotspot = new AssociableHotspot('hotspot1', $matchMax, $shape, $coords); $associableHotspot->setShowHide($showHide); $associableHotspot->setTemplateIdentifier($templateIdentifier); $associableHotspot->setMatchGroup(new IdentifierCollection(array('identifier1', 'identifier2'))); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($associableHotspot)->marshall($associableHotspot); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<associableHotspot identifier="hotspot1" shape="rect" coords="92,19,261,66" matchGroup="identifier1 identifier2" matchMax="2"/>', $dom->saveXML($element)); }
/** * Unmarshall a DOMElement object corresponding to a hotspotChoice/associableHotspot element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent A HotspotChoice/AssociableHotspot object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException */ protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($shape = self::getDOMElementAttributeAs($element, 'shape')) !== null) { if (($coords = self::getDOMElementAttributeAs($element, 'coords')) !== null) { $shape = QtiShape::getConstantByName($shape); if ($shape === false) { $msg = "The value of the mandatory attribute 'shape' is not a value from the 'shape' enumeration."; throw new UnmarshallingException($msg, $element); } try { $coords = Utils::stringToCoords($coords, $shape); } catch (UnexpectedValueException $e) { $msg = "The coordinates 'coords' of element '" . $element->localName . "' are not valid regarding the shape they are bound to."; throw new UnmarshallingException($msg, $element, $e); } catch (InvalidArgumentException $e) { $msg = "The coordinates 'coords' of element '" . $element->localName . "' could not be converted."; throw new UnmarshallingException($msg, $element, $e); } if ($element->localName === 'hotspotChoice') { $component = new HotspotChoice($identifier, $shape, $coords); } else { if (($matchMax = self::getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) { $component = new AssociableHotspot($identifier, $matchMax, $shape, $coords); } else { $msg = "The mandatory attribute 'matchMax' is missing from element 'associableHotspot'."; throw new UnmarshallingException($msg, $element); } } if (($hotspotLabel = self::getDOMElementAttributeAs($element, 'hotspotLabel')) !== null) { $component->setHotspotLabel($hotspotLabel); } if (($fixed = self::getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) { $component->setFixed($fixed); } if (($templateIdentifier = self::getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) { $component->setTemplateIdentifier($templateIdentifier); } if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) { if (($showHide = ShowHide::getConstantByName($showHide)) !== false) { $component->setShowHide($showHide); } else { $msg = "The value of the 'showHide' attribute of element '" . $element->localName . "' is not a value from the 'showHide' enumeration."; throw new UnmarshallingException($msg, $element); } } if ($element->localName === 'associableHotspot') { if (Version::compare($version, '2.1.0', '<') === true) { if (($matchGroup = self::getDOMElementAttributeAs($element, 'matchGroup')) !== null) { $component->setMatchGroup(new IdentifierCollection(explode(" ", $matchGroup))); } } if (Version::compare($version, '2.1.0', '>=') === true) { if (($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) { $component->setMatchMin($matchMin); } } } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'."; } }