public function testMarshall() { $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $object = new Object('myimg.png', 'image/png'); $choice1 = new AssociableHotspot('choice1', 2, Shape::CIRCLE, new Coords(Shape::CIRCLE, array(0, 0, 15))); $choice1->setMatchMin(1); $choice2 = new AssociableHotspot('choice2', 1, Shape::CIRCLE, new Coords(Shape::CIRCLE, array(2, 2, 15))); $choice3 = new AssociableHotspot('choice3', 1, Shape::CIRCLE, new Coords(Shape::CIRCLE, array(4, 4, 15))); $choices = new AssociableHotspotCollection(array($choice1, $choice2, $choice3)); $graphicAssociateInteraction = new GraphicAssociateInteraction('RESPONSE', $object, $choices, 'prout'); $graphicAssociateInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory()->createMarshaller($graphicAssociateInteraction)->marshall($graphicAssociateInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<graphicAssociateInteraction id="prout" responseIdentifier="RESPONSE"><prompt>Prompt...</prompt><object data="myimg.png" type="image/png"/><associableHotspot identifier="choice1" shape="circle" coords="0,0,15" matchMax="2" matchMin="1"/><associableHotspot identifier="choice2" shape="circle" coords="2,2,15" matchMax="1"/><associableHotspot identifier="choice3" shape="circle" coords="4,4,15" matchMax="1"/></graphicAssociateInteraction>', $dom->saveXML($element)); }
/** * @depends testMarshall21 */ public function testMarshall20() { // Make sure that maxAssociations is always in the output but never minAssociations. $object = new Object('myimg.png', 'image/png'); $choice1 = new AssociableHotspot('choice1', 2, QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, array(0, 0, 15))); $choice1->setMatchMin(1); $choice2 = new AssociableHotspot('choice2', 1, QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, array(2, 2, 15))); $choice3 = new AssociableHotspot('choice3', 1, QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, array(4, 4, 15))); $choices = new AssociableHotspotCollection(array($choice1, $choice2, $choice3)); $graphicAssociateInteraction = new GraphicAssociateInteraction('RESPONSE', $object, $choices); $graphicAssociateInteraction->setMaxAssociations(3); $graphicAssociateInteraction->setMinAssociations(2); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($graphicAssociateInteraction)->marshall($graphicAssociateInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<graphicAssociateInteraction responseIdentifier="RESPONSE" maxAssociations="3"><object data="myimg.png" type="image/png"/><associableHotspot identifier="choice1" shape="circle" coords="0,0,15" matchMax="2"/><associableHotspot identifier="choice2" shape="circle" coords="2,2,15" matchMax="1"/><associableHotspot identifier="choice3" shape="circle" coords="4,4,15" matchMax="1"/></graphicAssociateInteraction>', $dom->saveXML($element)); }
public function testMarshall() { $shape = Shape::RECT; $coords = new Coords($shape, array(92, 19, 261, 66)); $matchMax = 2; $matchMin = 1; $fixed = true; $showHide = ShowHide::HIDE; $associableHotspot = new AssociableHotspot('hotspot1', $matchMax, $shape, $coords, 'my-hot'); $associableHotspot->setMatchMin($matchMin); $associableHotspot->setFixed($fixed); $associableHotspot->setShowHide($showHide); $element = $this->getMarshallerFactory()->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" fixed="true" showHide="hide" matchMax="2" matchMin="1" id="my-hot"/>', $dom->saveXML($element)); }
/** * @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 QtiComponent A HotspotChoice/AssociableHotspot object. * @throws UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($shape = self::getDOMElementAttributeAs($element, 'shape')) !== null) { if (($coords = self::getDOMElementAttributeAs($element, 'coords')) !== null) { $shape = Shape::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); if (($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) { $component->setMatchMin($matchMin); } } 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); } } self::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 . "'."; } }