public function testMarshall() { $associableChoice1 = new SimpleAssociableChoice('choice1', 1); $associableChoice1->setContent(new FlowStaticCollection(array(new TextRun('This is choice1')))); $associableChoice2 = new SimpleAssociableChoice('choice2', 2); $associableChoice2->setMatchMin(1); $associableChoice2->setContent(new FlowStaticCollection(array(new TextRun('This is choice2')))); $simpleMatchSet = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($associableChoice1, $associableChoice2))); $marshaller = $this->getMarshallerFactory()->createMarshaller($simpleMatchSet); $element = $marshaller->marshall($simpleMatchSet); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<simpleMatchSet><simpleAssociableChoice identifier="choice1" matchMax="1">This is choice1</simpleAssociableChoice><simpleAssociableChoice identifier="choice2" matchMax="2" matchMin="1">This is choice2</simpleAssociableChoice></simpleMatchSet>', $dom->saveXML($element)); }
private function buildOptionCollection(choicematrix $question, $stemCount) { $optionIndexIdentifierMap = []; $optionCollection = new SimpleAssociableChoiceCollection(); foreach ($question->get_options() as $key => $optionValue) { // Learnosity's `choicematrix` always have its options to have any number of associable choice, thus setting to stems count // Same as above, won't validate upon empty response, thus setting match min to 1 $optionChoice = new SimpleAssociableChoice('OPTION_' . $key, $stemCount); $optionChoice->setMatchMin(1); $optionChoice->setContent(ContentCollectionBuilder::buildFlowStaticCollectionContent(QtiMarshallerUtil::unmarshallElement($optionValue))); $optionCollection->attach($optionChoice); $optionIndexIdentifierMap[$key] = $optionChoice->getIdentifier(); } return [$optionCollection, $optionIndexIdentifierMap]; }
public function testMarshall() { $choice1 = new SimpleAssociableChoice('choice_1', 1); $choice1->setContent(new FlowStaticCollection(array(new TextRun('Choice #1')))); $choice2 = new SimpleAssociableChoice('choice_2', 2); $choice2->setMatchMin(1); $choice2->setContent(new FlowStaticCollection(array(new TextRun('Choice #2')))); $choices = new SimpleAssociableChoiceCollection(array($choice1, $choice2)); $component = new AssociateInteraction('RESPONSE', $choices); $component->setMaxAssociations(2); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $component->setPrompt($prompt); $marshaller = $this->getMarshallerFactory()->createMarshaller($component); $element = $marshaller->marshall($component); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<associateInteraction responseIdentifier="RESPONSE" maxAssociations="2"><prompt>Prompt...</prompt><simpleAssociableChoice identifier="choice_1" matchMax="1">Choice #1</simpleAssociableChoice><simpleAssociableChoice identifier="choice_2" matchMax="2" matchMin="1">Choice #2</simpleAssociableChoice></associateInteraction>', $dom->saveXML($element)); }
/** * @depends testMarshall20 */ public function testMarshallNoTemplateIdentifierNoShowHideNoMatchMin20() { // Aims at testing that attributes templateIdentifier, showHide, matchMin // are never in the output in a QTI 2.0 context. $simpleChoice = new SimpleAssociableChoice('choice_1', 3); $simpleChoice->setMatchMin(2); $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('Choice #1')))); $simpleChoice->setTemplateIdentifier('XTEMPLATE'); $simpleChoice->setShowHide(ShowHide::HIDE); $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($simpleChoice); $element = $marshaller->marshall($simpleChoice); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<simpleAssociableChoice identifier="choice_1" matchMax="3">Choice #1</simpleAssociableChoice>', $dom->saveXML($element)); }