public function testMarshall20() { $choice = new InlineChoice('choice1'); $choice->setContent(new TextOrVariableCollection(array(new TextRun('var: '), new PrintedVariable('pr1')))); $choice->setTemplateIdentifier('tpl1'); $choice->setShowHide(ShowHide::HIDE); // Make sure there is no output for templateIdentifier, showHide, and nested printedVariable elements. $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($choice)->marshall($choice); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoice identifier="choice1">var: </inlineChoice>', $dom->saveXML($element)); }
public static function buildSimple($responseIdentifier, array $identifierTextRunContentMap) { $collection = new InlineChoiceCollection(); foreach ($identifierTextRunContentMap as $identifier => $textRunContent) { $inlineChoice = new InlineChoice($identifier); $textOrVariableCollection = new TextOrVariableCollection(); $textOrVariableCollection->attach(new TextRun($textRunContent)); $inlineChoice->setContent($textOrVariableCollection); $collection->attach($inlineChoice); } return new InlineChoiceInteraction($responseIdentifier, $collection); }
public function testMarshall20() { // check that suffled systematically out and no required attribute. $inlineChoices = new InlineChoiceCollection(); $choice = new InlineChoice('inlineChoice1'); $choice->setFixed(true); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option1')))); $inlineChoices[] = $choice; $inlineChoiceInteraction = new InlineChoiceInteraction('RESPONSE', $inlineChoices); $inlineChoiceInteraction->setShuffle(false); $inlineChoiceInteraction->setRequired(true); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($inlineChoiceInteraction)->marshall($inlineChoiceInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoiceInteraction responseIdentifier="RESPONSE" shuffle="false"><inlineChoice identifier="inlineChoice1" fixed="true">Option1</inlineChoice></inlineChoiceInteraction>', $dom->saveXML($element)); }
public function testMarshall() { $inlineChoices = new InlineChoiceCollection(); $choice = new InlineChoice('inlineChoice1'); $choice->setFixed(true); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option1')))); $inlineChoices[] = $choice; $choice = new InlineChoice('inlineChoice2'); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option2')))); $inlineChoices[] = $choice; $choice = new InlineChoice('inlineChoice3'); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option3')))); $inlineChoices[] = $choice; $inlineChoiceInteraction = new InlineChoiceInteraction('RESPONSE', $inlineChoices); $inlineChoiceInteraction->setShuffle(true); $inlineChoiceInteraction->setRequired(true); $element = $this->getMarshallerFactory()->createMarshaller($inlineChoiceInteraction)->marshall($inlineChoiceInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoiceInteraction responseIdentifier="RESPONSE" shuffle="true" required="true"><inlineChoice identifier="inlineChoice1" fixed="true">Option1</inlineChoice><inlineChoice identifier="inlineChoice2">Option2</inlineChoice><inlineChoice identifier="inlineChoice3">Option3</inlineChoice></inlineChoiceInteraction>', $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 testMarshall() { $choice = new InlineChoice('choice1', 'my-choice1'); $choice->setContent(new TextOrVariableCollection(array(new PrintedVariable('pr1')))); $choice->setFixed(true); $choice->setTemplateIdentifier('tpl1'); $choice->setShowHide(ShowHide::HIDE); $element = $this->getMarshallerFactory()->createMarshaller($choice)->marshall($choice); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoice id="my-choice1" identifier="choice1" fixed="true" templateIdentifier="tpl1" showHide="hide"><printedVariable identifier="pr1" base="10" powerForm="false" delimiter=";" mappingIndicator="="/></inlineChoice>', $dom->saveXML($element)); }