public function testModel()
 {
     $myItem = new Item();
     $myItem->setAttribute('title', 'My Coolest Item');
     $myItem->getBody()->edit('sth');
     $myInteraction = new ChoiceInteraction();
     $myInteraction->getPrompt()->edit('Prompt you');
     $myChoice1 = $myInteraction->createChoice(array('fixed' => true), 'This is correct');
     $myChoice2 = $myInteraction->createChoice(array('fixed' => true), 'This is not correct');
     $this->assertInstanceOf('\\oat\\taoQtiItem\\model\\qti\\choice\\SimpleChoice', $myChoice2);
     $this->assertEquals(count($myInteraction->getChoices()), 2);
     $myChoice1->setContent('answer #1');
     $myChoice2->setContent('answer #2');
     $myInteraction->removeChoice($myChoice1);
     $this->assertEquals(count($myInteraction->getChoices()), 1);
     $myItem->addInteraction($myInteraction, "Adding my interaction here {$myInteraction->getPlaceholder()}. And not there.");
     $this->assertNotNull($myInteraction->getRelatedItem());
     $this->assertEquals($myInteraction->getRelatedItem()->getSerial(), $myItem->getSerial());
     $myResponse = new ResponseDeclaration();
     $myItem->addResponse($myResponse);
     $this->assertNotNull($myResponse->getRelatedItem());
     $this->assertEquals($myResponse->getRelatedItem()->getSerial(), $myItem->getSerial());
     $myItem->removeResponse($myResponse);
     $responses = $myItem->getResponses();
     $this->assertTrue(empty($responses));
 }
 /**
  * Set the item the current Qti Element belongs to.
  * The related item assignment is propagated to all containing Qti Element of the current one.
  * The "force" option allows changing the associated item (even if it has already been defined)
  * 
  * @param oat\taoQtiItem\model\qti\Item $item
  * @param boolean $force
  * @return boolean
  * @throws oat\taoQtiItem\model\qti\exception\QtiModelException
  */
 public function setRelatedItem(Item $item, $force = false)
 {
     $returnValue = false;
     if (!is_null($this->relatedItem) && $this->relatedItem->getSerial() == $item->getSerial()) {
         $returnValue = true;
         // identical
     } elseif (!$force && !is_null($this->relatedItem)) {
         throw new QtiModelException('attempt to change item reference for a QTI element');
     } else {
         // propagate the assignation of item to all included objects
         $reflection = new ReflectionClass($this);
         foreach ($reflection->getProperties() as $property) {
             if (!$property->isStatic() && !$property->isPrivate()) {
                 $propertyName = $property->getName();
                 $value = $this->{$propertyName};
                 if (is_array($value)) {
                     foreach ($value as $subvalue) {
                         if (is_object($subvalue) && $subvalue instanceof Element) {
                             $subvalue->setRelatedItem($item);
                         } elseif (is_object($subvalue) && $subvalue instanceof ResponseIdentifier) {
                             // manage the reference of identifier
                             $idenfierBaseType = $subvalue->getValue(true);
                             if (!is_null($idenfierBaseType)) {
                                 $idenfierBaseType->getReferencedObject()->setRelatedItem($item);
                             }
                         }
                     }
                 } elseif (is_object($value) && $value instanceof Element) {
                     $value->setRelatedItem($item);
                 }
             }
         }
         // set item reference to current object
         $this->relatedItem = $item;
         $returnValue = true;
     }
     return $returnValue;
 }