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 convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel) { /** @var clozetext $question */ $question = $questionType; // Extra text that can't be mapped since we are in textEntryInteraction which does not have prompt $this->extraContent = $question->get_stimulus(); // Replace {{ response }} with `textEntryInteraction` elements $maxLength = !is_null($question->get_max_length()) ? intval($question->get_max_length()) : 15; // Set default to `15` if not set $index = 0; $template = preg_replace_callback('/{{response}}/', function ($match) use(&$index, $interactionIdentifier, $interactionLabel, $maxLength) { $interaction = new TextEntryInteraction($interactionIdentifier . '_' . $index); $interaction->setLabel($interactionLabel); $interaction->setExpectedLength($maxLength); $index++; $replacement = QtiMarshallerUtil::marshall($interaction); return $replacement; }, $question->get_template()); // Wrap this interaction in a block since our `clozetext` `template` meant to be blocky and not inline $div = new Div(); $div->setClass('lrn-template'); $div->setContent(ContentCollectionBuilder::buildFlowCollectionContent(QtiMarshallerUtil::unmarshallElement($template))); // Build validation $isCaseSensitive = is_null($question->get_case_sensitive()) ? true : $question->get_case_sensitive(); $validationBuilder = new ClozetextValidationBuilder($isCaseSensitive); list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation(), $isCaseSensitive); return [$div, $responseDeclaration, $responseProcessing]; }
public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel) { /** @var shorttext $question */ $question = $questionType; // Extra text that can't be mapped since we are in textEntryInteraction which does not have prompt $this->extraContent = $question->get_stimulus(); $interaction = new TextEntryInteraction($interactionIdentifier); $interaction->setLabel($interactionLabel); // Build placeholder $placeholderText = $question->get_placeholder(); if (!empty($placeholderText)) { $interaction->setPlaceholderText($placeholderText); } // Use 15 as default $interaction->setExpectedLength($question->get_max_length() ? $question->get_max_length() : 15); // Build those validation $isCaseSensitive = $question->get_case_sensitive() === null ? true : $question->get_case_sensitive(); $validationBuilder = new ShorttextValidationBuilder($isCaseSensitive); list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation(), $isCaseSensitive); // TODO: This is a freaking hack // Wrap this interaction in a block since our `shorttext` meant to be blocky and not inline $div = new Div(); $content = new FlowCollection(); $content->attach($interaction); $div->setContent($content); return [$div, $responseDeclaration, $responseProcessing]; }
public function testMarshall() { $templateBlock = new TemplateBlock('tpl1', 'block1'); $div = new Div(); $div->setContent(new FlowCollection(array(new TextRun('Templatable...')))); $templateBlock->setContent(new FlowStaticCollection(array($div))); $element = $this->getMarshallerFactory()->createMarshaller($templateBlock)->marshall($templateBlock); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<templateBlock templateIdentifier="tpl1" identifier="block1" showHide="show"><div>Templatable...</div></templateBlock>', $dom->saveXML($element)); }
public function testMarshall() { $div = new Div(); $div->setContent(new FlowCollection(array(new TextRun("This is text...")))); $content = new FlowCollection(); $content[] = $div; $feedback = new FeedbackBlock('outcome1', 'please_show_me', ShowHide::SHOW); $feedback->setContent($content); $element = $this->getMarshallerFactory()->createMarshaller($feedback)->marshall($feedback); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<feedbackBlock outcomeIdentifier="outcome1" identifier="please_show_me" showHide="show"><div>This is text...</div></feedbackBlock>', $dom->saveXML($element)); }
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 testMarshall() { $identifier = 'myAssessmentTest'; $title = 'My Assessment Test'; $toolName = 'QTIStateMachine'; $toolVersion = '1.0b'; $assessmentSections = new AssessmentSectionCollection(); $assessmentSections[] = new AssessmentSection('myAssessmentSection', 'My Assessment Section', true); $testParts = new TestPartCollection(); $testParts[] = new TestPart('myTestPart', $assessmentSections); $div = new Div(); $div->setContent(new FlowCollection(array(new TextRun('Feedback!')))); $testFeedBacks = new TestFeedbackCollection(); $testFeedBacks[] = new TestFeedback('myFeedback', 'myOutcome', new FlowStaticCollection(array($div)), 'A Feedback'); $outcomeRules = new OutcomeRuleCollection(); $outcomeRules[] = new SetOutcomeValue('myOutcome', new BaseValue(BaseType::BOOLEAN, true)); $outcomeProcessing = new OutcomeProcessing($outcomeRules); $outcomeDeclarations = new OutcomeDeclarationCollection(); $outcomeDeclarations[] = new OutcomeDeclaration('myOutcome', BaseType::BOOLEAN); $component = new AssessmentTest($identifier, $title, $testParts); $component->setToolName($toolName); $component->setToolVersion($toolVersion); $component->setTestFeedbacks($testFeedBacks); $component->setOutcomeProcessing($outcomeProcessing); $component->setOutcomeDeclarations($outcomeDeclarations); $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($component); $element = $marshaller->marshall($component); $this->assertInstanceOf('\\DOMElement', $element); $this->assertEquals('assessmentTest', $element->nodeName); $this->assertEquals($identifier, $element->getAttribute('identifier')); $this->assertEquals($title, $element->getAttribute('title')); $this->assertEquals($toolName, $element->getAttribute('toolName')); $this->assertEquals($toolVersion, $element->getAttribute('toolVersion')); // testParts $this->assertEquals(1, $element->getElementsByTagName('testPart')->length); $this->assertTrue($element === $element->getElementsByTagName('testPart')->item(0)->parentNode); // assessmentSections $testPart = $element->getElementsByTagName('testPart')->item(0); $this->assertEquals(1, $element->getElementsByTagName('assessmentSection')->length); $this->assertTrue($testPart === $element->getElementsByTagName('assessmentSection')->item(0)->parentNode); // outcomeDeclarations $this->assertEquals(1, $element->getElementsByTagName('outcomeDeclaration')->length); $this->assertTrue($element === $element->getElementsByTagName('outcomeDeclaration')->item(0)->parentNode); // testFeedbacks $this->assertEquals(1, $element->getElementsByTagName('testFeedback')->length); $this->assertTrue($element === $element->getElementsByTagName('testFeedback')->item(0)->parentNode); // outcomeProcessing $this->assertEquals(1, $element->getElementsByTagName('outcomeProcessing')->length); $this->assertTrue($element === $element->getElementsByTagName('outcomeProcessing')->item(0)->parentNode); }
public function testMarshall() { $div = new Div(); $div->setClass('description'); $div->setContent(new FlowCollection(array(new TextRun('An old Physicist.')))); $h4 = new H4(); $h4->setContent(new InlineCollection(array(new TextRun('Albert Einstein')))); $blockquote = new Blockquote(); $blockquote->setClass('physics'); $blockquote->setContent(new BlockCollection(array($h4, $div))); $element = $this->getMarshallerFactory()->createMarshaller($blockquote)->marshall($blockquote); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<blockquote class="physics"><h4>Albert Einstein</h4><div class="description">An old Physicist.</div></blockquote>', $dom->saveXML($element)); }
/** * @depends testMarshall21 */ public function testMarshallNoOutputMinStrings20() { // Make sure no output for minStrings in a QTI 2.0 context. $hottext = new Hottext('hottext1'); $hottext->setContent(new InlineStaticCollection(array(new TextRun('hot')))); $div = new Div(); $div->setContent(new FlowCollection(array(new TextRun('This is a '), new Hottext('hot1'), new TextRun(' text...')))); $content = new BlockStaticCollection(array($div)); $hottextInteraction = new HottextInteraction('RESPONSE', $content); $hottextInteraction->setMinChoices(1); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($hottextInteraction)->marshall($hottextInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<hottextInteraction responseIdentifier="RESPONSE"><div>This is a <hottext identifier="hot1"/> text...</div></hottextInteraction>', $dom->saveXML($element)); }
public function testMarshall() { $hottext = new Hottext('hottext1'); $hottext->setContent(new InlineStaticCollection(array(new TextRun('hot')))); $div = new Div(); $div->setContent(new FlowCollection(array(new TextRun('This is a '), new Hottext('hot1'), new TextRun(' text...')))); $content = new BlockStaticCollection(array($div)); $hottextInteraction = new HottextInteraction('RESPONSE', $content); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $hottextInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory()->createMarshaller($hottextInteraction)->marshall($hottextInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<hottextInteraction responseIdentifier="RESPONSE"><prompt>Prompt...</prompt><div>This is a <hottext identifier="hot1"/> text...</div></hottextInteraction>', $dom->saveXML($element)); }
public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel) { /** @var clozedropdown $question */ $question = $questionType; // Extra text that can't be mapped since we are in textEntryInteraction which does not have prompt $this->extraContent = $question->get_stimulus(); // Replace {{ response }} with `textEntryInteraction` elements $valueIdentifierMapPerInlineChoices = []; $index = 0; $possibleResponses = $question->get_possible_responses(); $template = preg_replace_callback('/{{response}}/', function ($match) use(&$index, &$valueIdentifierMapPerInlineChoices, $possibleResponses, $interactionIdentifier, $interactionLabel) { $inlineChoiceCollection = new InlineChoiceCollection(); if (!isset($possibleResponses[$index])) { throw new MappingException('Invalid `possible_responses`, missing entries'); } foreach ($possibleResponses[$index] as $choiceIndex => $choiceValue) { $inlineChoiceIdentifier = 'INLINECHOICE_' . $choiceIndex; $valueIdentifierMapPerInlineChoices[$index][$choiceValue] = $inlineChoiceIdentifier; // Update this map so can be used later upon building responseDeclaration objects $inlineChoice = new InlineChoice($inlineChoiceIdentifier); $inlineChoiceContent = new TextOrVariableCollection(); $inlineChoiceContent->attach(new TextRun($choiceValue)); $inlineChoice->setContent($inlineChoiceContent); $inlineChoiceCollection->attach($inlineChoice); } $interaction = new InlineChoiceInteraction($interactionIdentifier . '_' . $index, $inlineChoiceCollection); $interaction->setLabel($interactionLabel); $index++; $replacement = QtiMarshallerUtil::marshall($interaction); return $replacement; }, $question->get_template()); // Wrap this interaction in a block since our `clozedropdown` `template` meant to be blocky and not inline $div = new Div(); $div->setClass('lrn-template'); $div->setContent(ContentCollectionBuilder::buildFlowCollectionContent(QtiMarshallerUtil::unmarshallElement($template))); // Build validation $validationBuilder = new ClozedropdownValidationBuilder($valueIdentifierMapPerInlineChoices); list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation()); return [$div, $responseDeclaration, $responseProcessing]; }
public function buildContentCollection(QtiComponentCollection $contentCollection) { $areBlockComponents = array_reduce($contentCollection->getArrayCopy(), function ($initial, $component) { return $initial && $component instanceof Block; }, true); // Check whether the content could all be attached as is if ($areBlockComponents) { $blockCollection = new BlockCollection(); foreach ($contentCollection as $component) { $blockCollection->attach($component); } return $blockCollection; } // Otherwise, build a `div` wrapper around it $divCollection = new FlowCollection(); foreach ($contentCollection as $component) { $divCollection->attach($component); } $div = new Div(); $div->setContent($divCollection); $blockCollection = new BlockCollection(); $blockCollection->attach($div); return $blockCollection; }
private function buildItemBodyWithItemContent(array $interactions, $content) { // Map <itemBody> // TODO: Wrap these `content` stuff in a div // TODO: to avoid QtiComponentIterator bug ignoring 2nd element with empty content $contentCollection = QtiMarshallerUtil::unmarshallElement($content); $wrapperCollection = new FlowCollection(); foreach ($contentCollection as $component) { $wrapperCollection->attach($component); } $divWrapper = new Div(); $divWrapper->setContent($wrapperCollection); // Iterate through these elements and try to replace every single question `span` with its interaction equivalent $iterator = $divWrapper->getIterator(); foreach ($iterator as $component) { if ($component instanceof Span && StringUtil::contains($component->getClass(), 'learnosity-response')) { $currentContainer = $iterator->getCurrentContainer(); $questionReference = trim(str_replace('learnosity-response', '', $component->getClass())); $questionReference = trim(str_replace('question-', '', $questionReference)); // Build the actual interaction $interaction = $interactions[$questionReference]['interaction']; $content = new FlowCollection(); if (isset($interactions[$questionReference]['extraContent'])) { $content->attach($interactions[$questionReference]['extraContent']); } $content->attach($interaction); $replacement = ContentCollectionBuilder::buildContent($currentContainer, $content)->current(); $currentContainer->getComponents()->replace($component, $replacement); } } // Extract the actual content from the div wrapper and add that to our <itemBody> $componentsWithinDiv = $divWrapper->getComponents(); $itemBody = new ItemBody(); $itemBody->setContent(ContentCollectionBuilder::buildBlockCollectionContent($componentsWithinDiv)); return $itemBody; }
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)); }