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)); }
/** * Save a QTI_Item into an RDF Item, by exporting the QTI_Item to QTI xml * and saving it in the itemContent property of the RDF Item * * @param \oat\taoQtiItem\model\qti\Item $qtiItem * @param core_kernel_classes_Resource $rdfItem * @return bool * @throws \common_exception_Error * @throws \common_exception_NotFound * @throws common_Exception * @throws exception\QtiModelException */ public function saveDataItemToRdfItem(Item $qtiItem, core_kernel_classes_Resource $rdfItem) { $label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8'); //set the current data lang in the item content to keep the integrity $qtiItem->setAttribute('xml:lang', \common_session_SessionManager::getSession()->getDataLanguage()); $qtiItem->setAttribute('label', $label); $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem); $success = $directory->getFile(self::QTI_ITEM_FILE)->put($qtiItem->toXML()); if ($success) { $this->getEventManager()->trigger(new ItemUpdatedEvent($rdfItem->getUri())); } return $success; }