/** * @depends testMarshallSimple20 */ public function testMarshallNoTemplateIdentifierNoShowHide20() { // Aims at testing that templateIdentifier and showHide attributes // are not taken into accoun in a QTI 2.0 context. $simpleChoice = new SimpleChoice('choice_1'); $simpleChoice->setFixed(true); $simpleChoice->setTemplateIdentifier('XTEMPLATE'); $simpleChoice->setShowHide(ShowHide::HIDE); $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('Choice #1')))); $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('<simpleChoice identifier="choice_1" fixed="true">Choice #1</simpleChoice>', $dom->saveXML($element)); }
public function testCreateShufflingFromInteractionChoice() { $choice1 = new SimpleChoice('id1'); $choice2 = new SimpleChoice('id2'); $choice3 = new SimpleChoice('id3'); $choice1->setFixed(true); $choice3->setFixed(true); $choiceCollection = new SimpleChoiceCollection(array($choice1, $choice2, $choice3)); $choiceInteraction = new ChoiceInteraction('RESPONSE', $choiceCollection); $choiceInteraction->setShuffle(true); $shuffling = StateUtils::createShufflingFromInteraction($choiceInteraction); $this->assertEquals('RESPONSE', $shuffling->getResponseIdentifier()); $shufflingGroups = $shuffling->getShufflingGroups(); $this->assertEquals(1, count($shufflingGroups)); $this->assertEquals(array('id1', 'id2', 'id3'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy()); $this->assertEquals(array('id1', 'id3'), $shufflingGroups[0]->getFixedIdentifiers()->getArrayCopy()); }
public function testShuffleWithFixed() { // It is difficult to test a random algorithm. // In this way, we just check it runs. Deeper // analysis can be done in /test/scripts/. // DOM creation... $dom = new DOMDocument('1.0', 'UTF-8'); $node = $dom->createElement('fakenode'); $dom->appendChild($node); $choice = $dom->createElement('div'); $choice->setAttribute('fixed', 'false'); $choice->setAttribute('id', 'choice1'); $choice->setAttribute('class', 'qti-simpleChoice'); $node->appendChild($choice); $choice = $dom->createElement('div'); $choice->setAttribute('fixed', 'true'); $choice->setAttribute('id', 'choice2'); $choice->setAttribute('class', 'qti-simpleChoice qti-hide'); $node->appendChild($choice); $choice = $dom->createElement('div'); $choice->setAttribute('fixed', 'false'); $choice->setAttribute('id', 'choice3'); $choice->setAttribute('class', 'qti-simpleChoice'); $node->appendChild($choice); // In memory model creation ... $shufflables = new ShufflableCollection(); $choice = new SimpleChoice('choice1'); $choice->setFixed(false); $choice->setId('choice1'); $shufflables[] = $choice; $choice = new SimpleChoice('choice2'); $choice->setFixed(true); $choice->setId('choice2'); $shufflables[] = $choice; $choice = new SimpleChoice('choice3'); $choice->setFixed(false); $choice->setId('choice3'); $shufflables[] = $choice; Utils::shuffle($node, $shufflables); // Let's check if 'choice2' is still in place... $this->assertEquals('choice2', $node->getElementsByTagName('div')->item(1)->getAttribute('id')); $node0Id = $node->getElementsByTagName('div')->item(0)->getAttribute('id'); $node1Id = $node->getElementsByTagName('div')->item(2)->getAttribute('id'); $this->assertTrue($node0Id === 'choice1' && $node1Id === 'choice3' || $node0Id === 'choice3' && $node1Id === 'choice1'); }