public function testMarshall()
 {
     $h1 = new H1();
     $h1->setContent(new InlineCollection(array(new TextRun('Super Item'))));
     $div = new Div();
     $div->setContent(new FlowCollection(array(new TextRun('This is some stimulus.'))));
     $itemBody = new ItemBody('my-body');
     $itemBody->setContent(new BlockCollection(array($h1, $div)));
     $element = $this->getMarshallerFactory()->createMarshaller($itemBody)->marshall($itemBody);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<itemBody id="my-body"><h1>Super Item</h1><div>This is some stimulus.</div></itemBody>', $dom->saveXML($element));
 }
 public function processAssessmentItem(AssessmentItem $assessmentItem)
 {
     // TODO: Yea, we ignore rubric but what happen if the rubric is deep inside nested
     $newCollection = new BlockCollection();
     $itemBodyNew = new ItemBody();
     /** @var QtiComponent $component */
     foreach ($assessmentItem->getItemBody()->getContent() as $key => $component) {
         if (!$component instanceof RubricBlock) {
             $newCollection->attach($component);
         } else {
             LogService::log('Does not support <rubricBlock>. Ignoring <rubricBlock>');
         }
     }
     $itemBodyNew->setContent($newCollection);
     $assessmentItem->setItemBody($itemBodyNew);
     return $assessmentItem;
 }
 public static function buildItemBody(QtiComponentCollection $componentCollection)
 {
     $itemBody = new ItemBody('testItemBody');
     $blockCollection = new BlockCollection();
     $p = new P();
     $pCollection = new InlineCollection();
     $pCollection->attach(new TextRun('The Matrix movie is starring '));
     // Build the <itemBody>
     $blockCollection->attach($p);
     foreach ($componentCollection as $c) {
         if ($c instanceof InlineInteraction) {
             $pCollection->attach($c);
         } else {
             $blockCollection->attach($c);
         }
     }
     $p->setContent($pCollection);
     $itemBody->setContent($blockCollection);
     return $itemBody;
 }
 protected function buildAssessmentItem(array $interactions, $responseProcessingTemplate = '')
 {
     $assessmentItem = new AssessmentItem('testItemID', 'testItemTitle', false);
     $responseProcessing = new ResponseProcessing();
     $responseProcessing->setTemplate($responseProcessingTemplate);
     $assessmentItem->setResponseProcessing($responseProcessing);
     $itemBody = new ItemBody();
     $p = new P();
     $pCollection = new InlineCollection();
     $pCollection->attach(new TextRun('The Matrix movie is starring '));
     $pCollection->attach(new TextRun('.'));
     foreach ($interactions as $interaction) {
         $pCollection->attach($interaction);
     }
     $p->setContent($pCollection);
     $collection = new BlockCollection();
     $collection->attach($p);
     $itemBody->setContent($collection);
     $assessmentItem->setItemBody($itemBody);
     return $assessmentItem;
 }
 private function buildItemBodyWithSingleInteraction(TextEntryInteraction $interactionOne = null)
 {
     $interactionOne = empty($interactionOne) ? new TextEntryInteraction('testIdentifierOne') : $interactionOne;
     $itemBody = new ItemBody();
     $itemBodyCollection = new BlockCollection();
     // Build `<p>The Matrix .... <inlineChoiceInteraction...></inlineChoiceInteraction>.</p>`
     $p = new P();
     $pCollection = new InlineCollection();
     $pCollection->attach(new TextRun('The Matrix movie is starring '));
     $pCollection->attach($interactionOne);
     $pCollection->attach(new TextRun('.'));
     $p->setContent($pCollection);
     // Build the <itemBody>
     $itemBodyCollection->attach($p);
     $itemBody->setContent($itemBodyCollection);
     return $itemBody;
 }
 private function buildItemBodyWithTwoInteractions()
 {
     $interactionOne = InlineChoiceInteractionBuilder::buildSimple('testIdentifierOne', ['sydney' => 'Sydney', 'melbourne' => 'Melbourne', 'canberra' => 'Canberra']);
     $interactionTwo = InlineChoiceInteractionBuilder::buildSimple('testIdentifierTwo', ['hugh' => 'Hugh Jackman', 'keanu' => 'Keanu Reeves', 'gloria' => 'Gloria Foster']);
     $itemBody = new ItemBody();
     $itemBodyCollection = new BlockCollection();
     // Build `<p>The Matrix .... <inlineChoiceInteraction...></inlineChoiceInteraction>.</p>`
     $p = new P();
     $pCollection = new InlineCollection();
     $pCollection->attach(new TextRun('The Matrix movie is filmed at '));
     $pCollection->attach($interactionOne);
     $pCollection->attach(new TextRun(', and starring '));
     $pCollection->attach($interactionTwo);
     $p->setContent($pCollection);
     // Build the <itemBody>
     $itemBodyCollection->attach($p);
     $itemBody->setContent($itemBodyCollection);
     return $itemBody;
 }
 private function buildItemBodySimple(array $interactions)
 {
     $interactions = array_values($interactions);
     $contentCollection = new QtiComponentCollection();
     // Append the extra contents belong to an interaction before the interaction itself
     foreach ($interactions as $data) {
         if (isset($data['extraContent'])) {
             $content = QtiMarshallerUtil::unmarshallElement($data['extraContent']);
             $contentCollection->merge($content);
         }
         $contentCollection->attach($data['interaction']);
     }
     $itemBody = new ItemBody();
     $itemBody->setContent(ContentCollectionBuilder::buildBlockCollectionContent($contentCollection));
     return $itemBody;
 }