public function testMarshall()
 {
     $interactionObject = new Object('airplane.jpg', 'image/jpeg');
     $interactionObject->setHeight(16);
     $interactionObject->setWidth(16);
     $interaction = new PositionObjectInteraction('RESPONSE', $interactionObject);
     $interaction->setCenterPoint(new Point(8, 8));
     $stageObject = new Object('country.jpg', 'image/jpeg');
     $positionObjectStage = new PositionObjectStage($stageObject, new PositionObjectInteractionCollection(array($interaction)));
     $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($positionObjectStage)->marshall($positionObjectStage);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<positionObjectStage><object data="country.jpg" type="image/jpeg"/><positionObjectInteraction responseIdentifier="RESPONSE" maxChoices="1" centerPoint="8 8"><object data="airplane.jpg" type="image/jpeg" width="16" height="16"/></positionObjectInteraction></positionObjectStage>', $dom->saveXML($element));
 }
 /**
  * @depends testMarshall21
  */
 public function testMarshall20()
 {
     // Make sure minChoices is not taken into account in a QTI 2.0 context.
     $object = new Object('myimg.jpg', 'image/jpeg');
     $object->setWidth(400);
     $object->setHeight(300);
     $positionObjectInteraction = new PositionObjectInteraction('RESPONSE', $object);
     $positionObjectInteraction->setMaxChoices(2);
     $positionObjectInteraction->setMinChoices(1);
     $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($positionObjectInteraction)->marshall($positionObjectInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<positionObjectInteraction responseIdentifier="RESPONSE" maxChoices="2"><object data="myimg.jpg" type="image/jpeg" width="400" height="300"/></positionObjectInteraction>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $object = new Object('myimg.jpg', 'image/jpeg');
     $object->setWidth(400);
     $object->setHeight(300);
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $positionObjectInteraction = new PositionObjectInteraction('RESPONSE', $object, 'my-pos');
     $positionObjectInteraction->setCenterPoint(new Point(150, 74));
     $positionObjectInteraction->setMaxChoices(2);
     $positionObjectInteraction->setMinChoices(1);
     $element = $this->getMarshallerFactory()->createMarshaller($positionObjectInteraction)->marshall($positionObjectInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<positionObjectInteraction responseIdentifier="RESPONSE" maxChoices="2" minChoices="1" centerPoint="150 74" id="my-pos"><object data="myimg.jpg" type="image/jpeg" width="400" height="300"/></positionObjectInteraction>', $dom->saveXML($element));
 }
 /**
  * Unmarshall a DOMElement object corresponding to an positionObjectInteraction element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A PositionObjectInteraction object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
         $objectElts = self::getChildElementsByTagName($element, 'object');
         if (count($objectElts) > 0) {
             $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]);
             $component = new PositionObjectInteraction($responseIdentifier, $object);
             if (($maxChoices = self::getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) {
                 $component->setMaxChoices($maxChoices);
             }
             if (Version::compare($version, '2.1.0', '>=') === true && ($minChoices = self::getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) {
                 $component->setMinChoices($minChoices);
             }
             if (($centerPoint = self::getDOMElementAttributeAs($element, 'centerPoint')) !== null) {
                 $points = explode(" ", $centerPoint);
                 $pointsCount = count($points);
                 if ($pointsCount === 2) {
                     if (Format::isInteger($points[0]) === true) {
                         if (Format::isInteger($points[1]) === true) {
                             $component->setCenterPoint(new QtiPoint(intval($points[0]), intval($points[1])));
                         } else {
                             $msg = "The 2nd integer of the 'centerPoint' attribute value is not a valid integer for element 'positionObjectInteraction'.";
                             throw new UnmarshallingException($msg, $element);
                         }
                     } else {
                         $msg = "The 1st value of the 'centerPoint' attribute value is not a valid integer for element 'positionObjectInteraction'.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 } else {
                     $msg = "The value of the 'centePoint' attribute of a 'positionObjectInteraction' element must be composed of exactly 2 integer values, {$pointsCount} given.";
                     throw new UnmarshallingException($msg, $element);
                 }
             }
             $this->fillBodyElement($component, $element);
             return $component;
         } else {
             $msg = "A 'positionObjectInteraction' element must contain exactly one 'object' element, none given.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'positionObjectInteraction' object.";
         throw new UnmarshallingException($msg, $element);
     }
 }