public static function buildGapMatchInteraction($identifier, array $gapTextList, array $gapImgList, array $gapList)
 {
     $gapChoiceCollection = new GapChoiceCollection();
     foreach ($gapTextList as $identifier => $contentStr) {
         $gapText = new GapText($identifier, 1);
         $content = new TextOrVariableCollection();
         $content->attach(new TextRun($contentStr));
         $gapText->setContent($content);
         $gapChoiceCollection->attach($gapText);
     }
     foreach ($gapImgList as $identifier => $imagedURL) {
         $obj = new Object($imagedURL, 'image/png');
         $gapImg = new GapImg($identifier, 1, $obj);
         $gapChoiceCollection->attach($gapImg);
     }
     $content = new BlockStaticCollection();
     $p = new P();
     $inlineCollection = new InlineCollection();
     foreach ($gapList as $gapIdentifier) {
         $gap = new Gap($gapIdentifier);
         $inlineCollection->attach($gap);
     }
     $p->setContent($inlineCollection);
     $content->attach($p);
     return new GapMatchInteraction($identifier, $gapChoiceCollection, $content);
 }
 public function testMarshall()
 {
     $identifier = 'myTestFeedBack1';
     $outcomeIdentifier = 'myOutcomeIdentifier1';
     $access = TestFeedbackAccess::AT_END;
     $showHide = ShowHide::SHOW;
     $text = new TextRun('Hello World!');
     $p = new P();
     $p->setContent(new InlineCollection(array($text)));
     $div = new Div();
     $div->setContent(new FlowCollection(array($p)));
     $content = new FlowStaticCollection(array($div));
     $component = new TestFeedback($identifier, $outcomeIdentifier, $content);
     $component->setAccess($access);
     $component->setShowHide($showHide);
     $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('testFeedback', $element->nodeName);
     $this->assertEquals($identifier, $element->getAttribute('identifier'));
     $this->assertEquals($outcomeIdentifier, $element->getAttribute('outcomeIdentifier'));
     $this->assertEquals('', $element->getAttribute('title'));
     $this->assertEquals('atEnd', $element->getAttribute('access'));
     $this->assertEquals('show', $element->getAttribute('showHide'));
     $content = $element->getElementsByTagName('div');
     $this->assertEquals($content->length, 1);
     $this->assertEquals($content->item(0)->getElementsByTagName('p')->length, 1);
 }
 public function testMarshallMaximal()
 {
     $assessmentSection1 = new ExtendedAssessmentSection('section1', 'My Section 1', true);
     $assessmentSection2 = new ExtendedAssessmentSection('section2', 'My Section 2', true);
     $preCondition = new PreCondition(new BaseValue(BaseType::BOOLEAN, true));
     $branching = new BranchRule(new BaseValue(BaseType::BOOLEAN, true), 'EXIT_TESTPART');
     $itemSessionControl = new ItemSessionControl();
     $itemSessionControl->setShowSolution(true);
     $timeLimits = new TimeLimits(null, new QtiDuration('PT1M40S'));
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('Prima!'))));
     $testFeedback = new TestFeedback('feedback1', 'show', new FlowStaticCollection(array($p)));
     $testFeedback->setTitle('hello!');
     $testFeedback->setAccess(TestFeedbackAccess::AT_END);
     $testFeedback->setShowHide(ShowHide::SHOW);
     $testFeedbackRef = new TestFeedbackRef('feedback1', 'show', TestFeedbackAccess::AT_END, ShowHide::SHOW, './TF01.xml');
     $assessmentSections = new AssessmentSectionCollection(array($assessmentSection1, $assessmentSection2));
     $preConditions = new PreConditionCollection(array($preCondition));
     $branchings = new BranchRuleCollection(array($branching));
     $testFeedbacks = new TestFeedbackCollection(array($testFeedback));
     $testFeedbackRefs = new TestFeedbackRefCollection(array($testFeedbackRef));
     $extendedTestPart = new ExtendedTestPart('part1', $assessmentSections);
     $extendedTestPart->setPreConditions($preConditions);
     $extendedTestPart->setBranchRules($branchings);
     $extendedTestPart->setItemSessionControl($itemSessionControl);
     $extendedTestPart->setTimeLimits($timeLimits);
     $extendedTestPart->setTestFeedbacks($testFeedbacks);
     $extendedTestPart->setTestFeedbackRefs($testFeedbackRefs);
     $factory = new CompactMarshallerFactory();
     $element = $factory->createMarshaller($extendedTestPart)->marshall($extendedTestPart);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<testPart identifier="part1" navigationMode="linear" submissionMode="individual"><preCondition><baseValue baseType="boolean">true</baseValue></preCondition><branchRule target="EXIT_TESTPART"><baseValue baseType="boolean">true</baseValue></branchRule><itemSessionControl maxAttempts="1" showFeedback="false" allowReview="true" showSolution="true" allowComment="false" allowSkipping="true" validateResponses="false"/><timeLimits maxTime="100" allowLateSubmission="false"/><assessmentSection identifier="section1" required="false" fixed="false" title="My Section 1" visible="true" keepTogether="true"/><assessmentSection identifier="section2" required="false" fixed="false" title="My Section 2" visible="true" keepTogether="true"/><testFeedback access="atEnd" outcomeIdentifier="show" showHide="show" identifier="feedback1" title="hello!"><p>Prima!</p></testFeedback><testFeedbackRef identifier="feedback1" outcomeIdentifier="show" access="atEnd" showHide="show" href="./TF01.xml"/></testPart>', $dom->saveXML($element));
 }
Example #4
0
 public function testMarshallUl()
 {
     $strong = new Strong();
     $strong->setContent(new InlineCollection(array(new TextRun('text'))));
     $li1 = new Li();
     $li1->setContent(new FlowCollection(array(new TextRun('Simple '), $strong, new TextRun('.'))));
     $em = new Em();
     $em->setContent(new InlineCollection(array(new TextRun('text'))));
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('Some complex text.'))));
     $li3 = new Li();
     $li3->setContent(new FlowCollection(array(new TextRun('Some super '), $em, new TextRun(':'), $p)));
     $ol = new Ol();
     $ol->setId('ordered-list');
     $ol->setContent(new LiCollection(array($li3)));
     $li2 = new Li();
     $li2->setContent(new FlowCollection(array(new TextRun('olé '), $ol)));
     $ul = new Ul();
     $ul->setClass('my-qti-list');
     $ul->setContent(new LiCollection(array($li1, $li2)));
     $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($ul)->marshall($ul);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<ul class="my-qti-list"><li>Simple <strong>text</strong>.</li><li>olé <ol id="ordered-list"><li>Some super <em>text</em>:<p>Some complex text.</p></li></ol></li></ul>', $dom->saveXML($element));
 }
 public function testMarshallP()
 {
     $p = new P('my-p');
     $em = new Em();
     $em->setContent(new InlineCollection(array(new TextRun('simple'))));
     $p->setContent(new InlineCollection(array(new TextRun('This text is a '), $em, new TextRun(' test.'))));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($p);
     $element = $marshaller->marshall($p);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<p id="my-p">This text is a <em>simple</em> test.</p>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $stylesheet = new Stylesheet('./stylesheet.css');
     $h3 = new H3();
     $h3->setContent(new InlineCollection(array(new TextRun('Be carefull kiddo!'))));
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('Read the instructions twice.'))));
     $rubricBlock = new RubricBlock(new ViewCollection(array(View::CANDIDATE, View::TUTOR)));
     $rubricBlock->setClass('warning');
     $rubricBlock->setContent(new FlowStaticCollection(array($h3, $p)));
     $rubricBlock->setStylesheets(new StylesheetCollection(array($stylesheet)));
     $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($rubricBlock)->marshall($rubricBlock);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<rubricBlock view="candidate tutor" class="warning"><h3>Be carefull kiddo!</h3><p>Read the instructions twice.</p><stylesheet href="./stylesheet.css" media="screen" type="text/css"/></rubricBlock>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $gapText = new GapText('gapText1', 1);
     $gapText->setContent(new TextOrVariableCollection(array(new TextRun('This is gapText1'))));
     $object = new Object("./myimg.png", "image/png");
     $gapImg = new GapImg('gapImg1', 1, $object);
     $gap1 = new Gap('G1');
     $gap2 = new Gap('G2');
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('A text... '), $gap1, new TextRun(' and an image... '), $gap2)));
     $gapMatch = new GapMatchInteraction('RESPONSE', new GapChoiceCollection(array($gapText, $gapImg)), new BlockStaticCollection(array($p)));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($gapMatch);
     $element = $marshaller->marshall($gapMatch);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gapMatchInteraction responseIdentifier="RESPONSE"><gapText identifier="gapText1" matchMax="1">This is gapText1</gapText><gapImg identifier="gapImg1" matchMax="1"><object data="./myimg.png" type="image/png"/></gapImg><p>A text... <gap identifier="G1"/> and an image... <gap identifier="G2"/></p></gapMatchInteraction>', $dom->saveXML($element));
 }
 public static function buildSimple($identifier, $contentMap)
 {
     $interactionContent = new BlockStaticCollection();
     $p = new P();
     $pCollection = new InlineCollection();
     foreach ($contentMap as $content) {
         if (is_array($content)) {
             $hottext = new Hottext(key($content));
             $hottextContent = new InlineStaticCollection();
             $hottextContent->attach(new TextRun($content[key($content)]));
             $hottext->setContent($hottextContent);
             $pCollection->attach($hottext);
         } else {
             if (is_string($content)) {
                 $pCollection->attach(new TextRun($content));
             }
         }
     }
     $p->setContent($pCollection);
     $interactionContent->attach($p);
     return new HottextInteraction($identifier, $interactionContent);
 }
 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;
 }
Example #11
0
 public function testMarshall()
 {
     $li1 = new Li();
     $li1->setContent(new FlowCollection(array(new TextRun('Start the Game'))));
     $li2 = new Li();
     $li2->setContent(new FlowCollection(array(new TextRun('Configure Inputs'))));
     $li3 = new Li();
     $li3->setContent(new FlowCollection(array(new TextRun('Hall of Fame'))));
     $li4 = new Li();
     $li4->setContent(new FlowCollection(array(new TextRun('Quit'))));
     $ul = new Ul();
     $ul->setContent(new LiCollection(array($li1, $li2, $li3, $li4)));
     $divMenu = new Div('menu');
     $divMenu->setContent(new FlowCollection(array($ul)));
     $h1 = new H1();
     $h1->setContent(new InlineCollection(array(new TextRun('Escape from Death Star'))));
     $strong = new Strong();
     $strong->setContent(new InlineCollection(array(new TextRun('incredible'))));
     $p = new P();
     $p->setClass('short-story');
     $p->setContent(new InlineCollection(array(new TextRun('An '), $strong, new TextRun(' adventure.'))));
     $divContent = new Div('content');
     $divContent->setContent(new FlowCollection(array($h1, $p)));
     $divContainer = new Div('main-container', 'ui-pane');
     $divContainer->setContent(new FlowCollection(array($divMenu, $divContent)));
     $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($divContainer)->marshall($divContainer);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $expected = '<div id="main-container" class="ui-pane"><div id="menu"><ul><li>Start the Game</li><li>Configure Inputs</li><li>Hall of Fame</li><li>Quit</li></ul></div><div id="content"><h1>Escape from Death Star</h1><p class="short-story">An <strong>incredible</strong> adventure.</p></div></div>';
     $this->assertEquals($expected, $dom->saveXML($element));
 }
 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;
 }
 public function testPrompt()
 {
     $interaction = ChoiceInteractionBuilder::buildSimple('testIdentifier', ['choiceA' => 'Choice A']);
     $prompt = new Prompt();
     $promptContent = new FlowStaticCollection();
     $promptContent->attach(new TextRun('Test'));
     $htmlCollection = new InlineCollection();
     $htmlCollection->attach(new TextRun('123'));
     $p = new P();
     $p->setContent($htmlCollection);
     $promptContent->attach($p);
     $prompt->setContent($promptContent);
     $interaction->setPrompt($prompt);
     $interactionMapper = new ChoiceInteractionMapper($interaction);
     $questionType = $interactionMapper->getQuestionType();
     $this->assertTrue($questionType->get_stimulus() === 'Test<p>123</p>');
 }