private static function buildSimpleMatchSet(array $matchSets, $matchMax)
 {
     $matchChoiceAssociation = new SimpleAssociableChoiceCollection();
     foreach ($matchSets as $identifier => $value) {
         $choice = new SimpleAssociableChoice($identifier, $matchMax);
         $contentCollection = new FlowStaticCollection();
         $contentCollection->attach(new TextRun($value));
         $choice->setContent($contentCollection);
         $matchChoiceAssociation->attach($choice);
     }
     return new SimpleMatchSet($matchChoiceAssociation);
 }
 public function testMarshall()
 {
     $simpleChoice = new SimpleAssociableChoice('choice_1', 1);
     $simpleChoice->setClass('qti-simpleAssociableChoice');
     $strong = new Strong();
     $strong->setContent(new InlineCollection(array(new TextRun('strong'))));
     $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('This is ... '), $strong, new TextRun('!'))));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($simpleChoice);
     $element = $marshaller->marshall($simpleChoice);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<simpleAssociableChoice class="qti-simpleAssociableChoice" identifier="choice_1" matchMax="1">This is ... <strong>strong</strong>!</simpleAssociableChoice>', $dom->saveXML($element));
 }
 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];
 }
 /**
  * @depends testMarshallSimple20
  */
 public function testMarshallMinAssociationAvoided20()
 {
     // Aims at testing that minAssociation is not in the output
     // in a QTI 2.0 context.
     $choice1 = new SimpleAssociableChoice('choice_1', 1);
     $choice1->setContent(new FlowStaticCollection(array(new TextRun('Choice #1'))));
     $choices = new SimpleAssociableChoiceCollection(array($choice1));
     $component = new AssociateInteraction('RESPONSE', $choices);
     $component->setMinAssociations(1);
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<associateInteraction responseIdentifier="RESPONSE" shuffle="false" maxAssociations="1"><simpleAssociableChoice identifier="choice_1" matchMax="1">Choice #1</simpleAssociableChoice></associateInteraction>', $dom->saveXML($element));
 }
 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));
 }
 public function testMarshall()
 {
     $choice1A = new SimpleAssociableChoice('choice1A', 1);
     $choice1A->setContent(new FlowStaticCollection(array(new TextRun('choice1A'))));
     $choice1B = new SimpleAssociableChoice('choice1B', 1);
     $choice1B->setContent(new FlowStaticCollection(array(new TextRun('choice1B'))));
     $choice2A = new SimpleAssociableChoice('choice2A', 1);
     $choice2A->setContent(new FlowStaticCollection(array(new TextRun('choice2A'))));
     $choice2B = new SimpleAssociableChoice('choice2B', 1);
     $choice2B->setContent(new FlowStaticCollection(array(new TextRun('choice2B'))));
     $set1 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice1A, $choice1B)));
     $set2 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice2A, $choice2B)));
     $matchInteraction = new MatchInteraction('RESPONSE', new SimpleMatchSetCollection(array($set1, $set2)));
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $matchInteraction->setPrompt($prompt);
     $matchInteraction->setShuffle(true);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($matchInteraction);
     $element = $marshaller->marshall($matchInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<matchInteraction responseIdentifier="RESPONSE" shuffle="true"><prompt>Prompt...</prompt><simpleMatchSet><simpleAssociableChoice identifier="choice1A" matchMax="1">choice1A</simpleAssociableChoice><simpleAssociableChoice identifier="choice1B" matchMax="1">choice1B</simpleAssociableChoice></simpleMatchSet><simpleMatchSet><simpleAssociableChoice identifier="choice2A" matchMax="1">choice2A</simpleAssociableChoice><simpleAssociableChoice identifier="choice2B" matchMax="1">choice2B</simpleAssociableChoice></simpleMatchSet></matchInteraction>', $dom->saveXML($element));
 }
 /**
  * @depends testMarshall20
  */
 public function testMarshallNoMinAssociations()
 {
     // Aims at testing that minAssociations is never in the output
     // in a QTI 2.0 context.
     $choice1A = new SimpleAssociableChoice('choice1A', 1);
     $choice1A->setContent(new FlowStaticCollection(array(new TextRun('choice1A'))));
     $choice2A = new SimpleAssociableChoice('choice2A', 1);
     $choice2A->setContent(new FlowStaticCollection(array(new TextRun('choice2A'))));
     $set1 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice1A)));
     $set2 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice2A)));
     $matchInteraction = new MatchInteraction('RESPONSE', new SimpleMatchSetCollection(array($set1, $set2)));
     $matchInteraction->setMinAssociations(1);
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($matchInteraction);
     $element = $marshaller->marshall($matchInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<matchInteraction responseIdentifier="RESPONSE" shuffle="false" maxAssociations="1"><simpleMatchSet><simpleAssociableChoice identifier="choice1A" matchMax="1">choice1A</simpleAssociableChoice></simpleMatchSet><simpleMatchSet><simpleAssociableChoice identifier="choice2A" matchMax="1">choice2A</simpleAssociableChoice></simpleMatchSet></matchInteraction>', $dom->saveXML($element));
 }
 /**
  * @depends testMarshall20
  */
 public function testMarshallMatchGroup20()
 {
     // Aims at testing that matchGroup is in the output
     // in a QTI 2.0 context.
     $simpleChoice = new SimpleAssociableChoice('choice_1', 0);
     $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('Choice #1'))));
     $simpleChoice->setMatchGroup(new IdentifierCollection(array('identifier1', 'identifier2')));
     $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="0" matchGroup="identifier1 identifier2">Choice #1</simpleAssociableChoice>', $dom->saveXML($element));
 }