/**
  * @depends testMarshallNoTitle
  */
 public function testMarshallTitle()
 {
     $mf = new ModalFeedbackRule('SHOW_HIM', ShowHide::SHOW, 'SHOW_MEH', 'Beautiful Feedback!');
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($mf);
     $elt = $marshaller->marshall($mf);
     $this->assertEquals('Beautiful Feedback!', $elt->getAttribute('title'));
 }
 public function testFromDomElement()
 {
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML('<assessmentItemRef xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" identifier="Q01" href="./q01.xml"/>');
     $element = $dom->documentElement;
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($element);
     $this->assertInstanceOf('qtism\\data\\storage\\xml\\marshalling\\ExtendedAssessmentItemRefMarshaller', $marshaller);
 }
 public function testUnmarshallMissingHref()
 {
     $this->setExpectedException('qtism\\data\\storage\\xml\\marshalling\\UnmarshallingException', "The mandatory 'href' attribute is missing from element 'testFeedbackRef'");
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML('<testFeedbackRef identifier="showme" outcomeIdentifier="SHOW_FEEDBACK" access="during" showHide="show"/>');
     $element = $dom->documentElement;
     $factory = new CompactMarshallerFactory();
     $ref = $factory->createMarshaller($element)->unmarshall($element);
 }
 public function testMarshall()
 {
     $ref = new RubricBlockRef('R01', './R01.xml');
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($ref);
     $elt = $marshaller->marshall($ref);
     $this->assertEquals('rubricBlockRef', $elt->nodeName);
     $this->assertEquals('R01', $elt->getAttribute('identifier'));
     $this->assertEquals('./R01.xml', $elt->getAttribute('href'));
 }
 public function testUnmarshall()
 {
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML('<shufflingGroup identifiers="id1 id2 id3"/>');
     $element = $dom->documentElement;
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($element);
     $component = $marshaller->unmarshall($element);
     $this->assertInstanceOf('qtism\\data\\state\\ShufflingGroup', $component);
     $identifiers = $component->getIdentifiers();
     $this->assertEquals(array('id1', 'id2', 'id3'), $identifiers->getArrayCopy());
 }
    public function testUnmarshall()
    {
        $element = $this->createDOMElement('
	        <shuffling responseIdentifier="RESPONSE"><shufflingGroup identifiers="id1 id2 id3"/><shufflingGroup identifiers="id4 id5 id6"/></shuffling>                
	    ');
        $factory = new CompactMarshallerFactory();
        $component = $factory->createMarshaller($element)->unmarshall($element);
        $this->assertInstanceOf('\\qtism\\data\\state\\Shuffling', $component);
        $this->assertEquals('RESPONSE', $component->getResponseIdentifier());
        $groups = $component->getShufflingGroups();
        $this->assertEquals(2, count($groups));
        $this->assertEquals(array('id1', 'id2', 'id3'), $groups[0]->getIdentifiers()->getArrayCopy());
        $this->assertEquals(array('id4', 'id5', 'id6'), $groups[1]->getIdentifiers()->getArrayCopy());
    }
    public function testUnmarshallModerate()
    {
        $factory = new CompactMarshallerFactory();
        $dom = new DOMDocument('1.0', 'UTF-8');
        $dom->loadXML('
			<assessmentItemRef xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" identifier="Q01" href="./q01.xml" timeDependent="true" adaptive="true">
				<weight identifier="W01" value="1.0"/>
				<weight identifier="W02" value="2.0"/>
				<responseDeclaration identifier="R01" baseType="integer" cardinality="single"/>
				<responseDeclaration identifier="R02" baseType="boolean" cardinality="single"/>
				<outcomeDeclaration identifier="O01" baseType="float" cardinality="single"/>
				<outcomeDeclaration identifier="O02" baseType="float" cardinality="single"/>
			</assessmentItemRef>
			');
        $element = $dom->documentElement;
        $marshaller = $factory->createMarshaller($element);
        $component = $marshaller->unmarshall($element);
        $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentItemRef', $component);
        $this->assertEquals('Q01', $component->getIdentifier());
        $this->assertTrue($component->isTimeDependent());
        $this->assertTrue($component->isAdaptive());
        $this->assertEquals('./q01.xml', $component->getHref());
        $weights = $component->getWeights();
        $this->assertEquals('W01', $weights['W01']->getIdentifier());
        $this->assertEquals('W02', $weights['W02']->getIdentifier());
        $responseDeclarations = $component->getResponseDeclarations();
        $this->assertEquals('R01', $responseDeclarations['R01']->getIdentifier());
        $this->assertEquals('R02', $responseDeclarations['R02']->getIdentifier());
        $outcomeDeclarations = $component->getOutcomeDeclarations();
        $this->assertEquals('O01', $outcomeDeclarations['O01']->getIdentifier());
        $this->assertEquals('O02', $outcomeDeclarations['O02']->getIdentifier());
    }
 public function testMarshall()
 {
     $section = new ExtendedAssessmentSection('S01', 'Section 01', true);
     $section->setSectionParts(new SectionPartCollection(array(new AssessmentSectionRef('SR01', './SR01.xml'))));
     $section->setRubricBlockRefs(new RubricBlockRefCollection(array(new RubricBlockRef('R01', './R01.xml'))));
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($section);
     $elt = $marshaller->marshall($section);
     $this->assertEquals('assessmentSection', $elt->nodeName);
     $this->assertEquals('S01', $elt->getAttribute('identifier'));
     $this->assertEquals('Section 01', $elt->getAttribute('title'));
     $this->assertEquals('true', $elt->getAttribute('visible'));
     $assessmentSectionRefElts = $elt->getElementsByTagName('assessmentSectionRef');
     $this->assertEquals(1, $assessmentSectionRefElts->length);
     $assessmentSectionRefElt = $assessmentSectionRefElts->item(0);
     $this->assertEquals('SR01', $assessmentSectionRefElt->getAttribute('identifier'));
     $this->assertEquals('./SR01.xml', $assessmentSectionRefElt->getAttribute('href'));
     $rubricBlockRefElts = $elt->getElementsByTagName('rubricBlockRef');
     $this->assertEquals(1, $rubricBlockRefElts->length);
     $rubricBlockRefElt = $rubricBlockRefElts->item(0);
     $this->assertEquals('R01', $rubricBlockRefElt->getAttribute('identifier'));
     $this->assertEquals('./R01.xml', $rubricBlockRefElt->getAttribute('href'));
 }
    public function testUnmarshallMaximal()
    {
        $dom = new DOMDocument('1.0', 'UTF-8');
        $dom->loadXML('<testPart xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" identifier="part1" navigationMode="linear" submissionMode="individual">
		        <preCondition>
		            <baseValue baseType="boolean">true</baseValue>
		        </preCondition>
		        <branchRule target="EXIT_TESTPART">
		            <baseValue baseType="boolean">true</baseValue>
		        </branchRule>
		        <itemSessionControl showSolution="true"/>
		        <timeLimits maxTime="100"/>
				<assessmentSection identifier="section1" title="My Section 1" visible="true"/>
				<assessmentSection identifier="section2" title="My Section 2" visible="false"/>
		        <testFeedback outcomeIdentifier="feedback1" identifier="show" showHide="show" title="hello!" access="atEnd">
		            <p>Prima!</p>
		        </testFeedback>
		        <testFeedbackRef outcomeIdentifier="feedback2" identifier="show" showHide="show" access="atEnd" href="./TF01.xml"/>
			</testPart>');
        $element = $dom->documentElement;
        $factory = new CompactMarshallerFactory();
        $marshaller = $factory->createMarshaller($element);
        $component = $marshaller->unmarshall($element);
        $this->assertInstanceOf('qtism\\data\\ExtendedTestPart', $component);
        $this->assertEquals(1, count($component->getPreConditions()));
        $this->assertEquals(1, count($component->getBranchRules()));
        $this->assertTrue($component->getItemSessionControl()->mustShowSolution());
        $this->assertTrue($component->getTimeLimits()->getMaxTime()->equals(new QtiDuration('PT1M40S')));
        $this->assertEquals(1, count($component->getTestFeedbacks()));
        $this->assertEquals(1, count($component->getTestFeedbackRefs()));
        $this->assertEquals(2, count($component->getAssessmentSections()));
        // Check that we got ExtendedAssessmentSections.
        $assessmentSections = $component->getAssessmentSections();
        $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentSection', $assessmentSections['section1']);
        $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentSection', $assessmentSections['section2']);
        // Check that we got TestFeedbackRef instances.
        $testFeedbackRefs = $component->getTestFeedbackRefs();
        $this->assertInstanceOf('qtism\\data\\TestFeedbackRef', $testFeedbackRefs[0]);
    }
 public function testUnmarshallMaximal()
 {
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML('<assessmentTest identifier="test1" title="A Test" toolName="qtisdk" toolVersion="0.0.0">
               <timeLimits maxTime="600" allowLateSubmission="false"/>
               <outcomeDeclaration identifier="COUNT" cardinality="single" baseType="integer"/>
               <testPart identifier="part1" navigationMode="linear" submissionMode="individual">
                 <preCondition>
                   <baseValue baseType="boolean">true</baseValue>
                 </preCondition>
                 <branchRule target="EXIT_TESTPART">
                   <baseValue baseType="boolean">true</baseValue>
                 </branchRule>
                 <itemSessionControl maxAttempts="1" showFeedback="false" allowReview="true" showSolution="true" allowComment="false" allowSkipping="true" validateResponses="false"/>
                 <timeLimits maxTime="100" allowLateSubmission="false"/>
                 <assessmentSection identifier="section1" required="false" fixed="false" title="My Section 1" visible="true" keepTogether="true"/>
                 <assessmentSection identifier="section2" required="false" fixed="false" title="My Section 2" visible="true" keepTogether="true"/>
                 <testFeedback access="atEnd" outcomeIdentifier="show" showHide="show" identifier="feedback1" title="hello!">
                   <p>Prima!</p>
                 </testFeedback>
                 <testFeedbackRef identifier="feedback1" outcomeIdentifier="show" access="atEnd" showHide="show" href="./TF01.xml"/>
               </testPart>
               <outcomeProcessing>
                 <setOutcomeValue identifier="COUNT">
                   <baseValue baseType="integer">1</baseValue>
                 </setOutcomeValue>
               </outcomeProcessing>
               <testFeedback access="atEnd" outcomeIdentifier="show" showHide="show" identifier="feedbackTest" title="hello!">
                 <p>Good!</p>
               </testFeedback>
               <testFeedbackRef identifier="feedbackTest" outcomeIdentifier="show" access="atEnd" showHide="show" href="./TF02.xml"/>
          </assessmentTest>');
     $element = $dom->documentElement;
     $factory = new CompactMarshallerFactory();
     $marshaller = $factory->createMarshaller($element);
     $component = $marshaller->unmarshall($element);
     $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentTest', $component);
     $this->assertEquals('test1', $component->getIdentifier());
     $this->assertEquals('A Test', $component->getTitle());
     $this->assertEquals('qtisdk', $component->getToolName());
     $this->assertEquals('0.0.0', $component->getToolVersion());
     $this->assertTrue($component->hasTimeLimits());
     $this->assertEquals(1, count($component->getOutcomeDeclarations()));
     $this->assertEquals(1, count($component->getTestFeedbacks()));
     $this->assertEquals(1, count($component->getTestFeedbackRefs()));
     $this->assertTrue($component->hasOutcomeProcessing());
     $testParts = $component->getTestParts();
     $testPart = $testParts['part1'];
     $this->assertInstanceOf('qtism\\data\\ExtendedTestPart', $testPart);
     $this->assertEquals(1, count($testPart->getPreConditions()));
     $this->assertEquals(1, count($testPart->getBranchRules()));
     $this->assertTrue($testPart->getItemSessionControl()->mustShowSolution());
     $this->assertTrue($testPart->getTimeLimits()->getMaxTime()->equals(new Duration('PT1M40S')));
     $this->assertEquals(1, count($testPart->getTestFeedbacks()));
     $this->assertEquals(1, count($testPart->getTestFeedbackRefs()));
     $this->assertEquals(2, count($testPart->getAssessmentSections()));
     // Check that we got ExtendedAssessmentSections.
     $assessmentSections = $testPart->getAssessmentSections();
     $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentSection', $assessmentSections['section1']);
     $this->assertInstanceOf('qtism\\data\\ExtendedAssessmentSection', $assessmentSections['section2']);
     // Check that we got TestFeedbackRef instances.
     $testFeedbackRefs = $testPart->getTestFeedbackRefs();
     $this->assertInstanceOf('qtism\\data\\TestFeedbackRef', $testFeedbackRefs[0]);
 }
 /**
  * @depends testUnmarshallMinimal
  */
 public function testUnmarshallShufflingGroups()
 {
     $factory = new CompactMarshallerFactory();
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML('
         <assessmentItemRef xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" identifier="Q01" href="./q01.xml" timeDependent="true">
             <shuffling responseIdentifier="RESPONSE">
                 <shufflingGroup identifiers="id1 id2 id3"/>
                 <shufflingGroup identifiers="id4 id5 id6"/>
             </shuffling>
         </assessmentItemRef>
     ');
     $element = $dom->documentElement;
     $marshaller = $factory->createMarshaller($element);
     $component = $marshaller->unmarshall($element);
     $shufflings = $component->getShufflings();
     $this->assertEquals(1, count($shufflings));
     $this->assertEquals('RESPONSE', $shufflings[0]->getResponseIdentifier());
     $shufflingGroups = $shufflings[0]->getShufflingGroups();
     $this->assertEquals(2, count($shufflingGroups));
     $this->assertEquals(array('id1', 'id2', 'id3'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy());
     $this->assertEquals(array('id4', 'id5', 'id6'), $shufflingGroups[1]->getIdentifiers()->getArrayCopy());
 }