-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More XInclude support in XmlDocument.
Conflicts: src/qtism/data/content/AtomicInline.php src/qtism/data/storage/xml/XmlDocument.php src/qtism/data/storage/xml/marshalling/ImgMarshaller.php test/qtismtest/data/storage/xml/XmlAssessmentItemDocumentTest.php
- Loading branch information
Showing
7 changed files
with
178 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
namespace qtismtest\data\storage\xml; | ||
|
||
use qtism\data\storage\xml\XmlDocument; | ||
use qtism\data\storage\xml\XmlStorageException; | ||
|
||
class XmlDocumentXIncludeTest extends \QtiSmTestCase { | ||
|
||
public function testLoadAndSaveXIncludeNsInTag() { | ||
$doc = new XmlDocument(); | ||
$doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag.xml', true); | ||
|
||
$includes = $doc->getDocumentComponent()->getComponentsByClassName('include'); | ||
$this->assertEquals(1, count($includes)); | ||
$this->assertEquals('xinclude_ns_in_tag_content1.xml', $includes[0]->getHref()); | ||
|
||
$file = tempnam('/tmp', 'qsm'); | ||
$doc->save($file); | ||
|
||
// Does it validate again? | ||
$doc = new XmlDocument(); | ||
try { | ||
$doc->load($file, true); | ||
$this->assertTrue(true); | ||
} catch (XmlStorageException $e) { | ||
$this->assertFalse(true, "The document using xinclude should validate after being saved."); | ||
} | ||
} | ||
|
||
/** | ||
* @depends testLoadAndSaveXIncludeNsInTag | ||
*/ | ||
public function testLoadAndResolveXIncludeSameBase() { | ||
$doc = new XmlDocument(); | ||
$doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag.xml', true); | ||
|
||
// At this moment, includes are not resolved. | ||
$includes = $doc->getDocumentComponent()->getComponentsByClassName('include'); | ||
$this->assertEquals(1, count($includes)); | ||
// So no img components can be found... | ||
$imgs = $doc->getDocumentComponent()->getComponentsByClassName('img'); | ||
$this->assertEquals(0, count($imgs)); | ||
|
||
$doc->xInclude(); | ||
|
||
// Now they are! | ||
$includes = $doc->getDocumentComponent()->getComponentsByClassName('include'); | ||
$this->assertEquals(0, count($includes)); | ||
|
||
// And we should find an img component then! | ||
$imgs = $doc->getDocumentComponent()->getComponentsByClassName('img'); | ||
$this->assertEquals(1, count($imgs)); | ||
|
||
// Check that xml:base was appropriately resolved. In this case, | ||
// no content for xml:base because 'xinclude_ns_in_tag_content1.xml' is in the | ||
// same directory as the main xml file. | ||
$this->assertEquals('', $imgs[0]->getXmlBase()); | ||
} | ||
|
||
/** | ||
* @depends testLoadAndResolveXIncludeSameBase | ||
*/ | ||
public function testLoadAndResolveXIncludeDifferentBase() { | ||
$doc = new XmlDocument(); | ||
$doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag_subfolder.xml', true); | ||
$doc->xInclude(); | ||
|
||
$includes = $doc->getDocumentComponent()->getComponentsByClassName('include'); | ||
$this->assertEquals(0, count($includes)); | ||
|
||
// And we should find an img component then! | ||
$imgs = $doc->getDocumentComponent()->getComponentsByClassName('img'); | ||
$this->assertEquals(1, count($imgs)); | ||
|
||
// Check that xml:base was appropriately resolved. In this case, | ||
// no content for xml:base because 'xinclude_ns_in_tag_content1.xml' is in the | ||
// same directory as the main xml file. | ||
$this->assertEquals('subfolder/', $imgs[0]->getXmlBase()); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test/samples/custom/items/xinclude/subfolder/xinclude_ns_in_tag_content1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<img xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd" src="images/sign.png" alt="NEVER LEAVE LUGGAGE UNATTENDED"/> |
31 changes: 31 additions & 0 deletions
31
test/samples/custom/items/xinclude/xinclude_ns_in_tag_subfolder.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Thie example adapted from the PET Handbook, copyright University of Cambridge ESOL Examinations --> | ||
<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd" | ||
identifier="choice" title="Unattended Luggage" adaptive="false" timeDependent="false"> | ||
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> | ||
<correctResponse> | ||
<value>ChoiceA</value> | ||
</correctResponse> | ||
</responseDeclaration> | ||
<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float"> | ||
<defaultValue> | ||
<value>0</value> | ||
</defaultValue> | ||
</outcomeDeclaration> | ||
<itemBody> | ||
<p>Look at the text in the picture.</p> | ||
<p> | ||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="subfolder/xinclude_ns_in_tag_content1.xml"/> | ||
</p> | ||
<choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1"> | ||
<prompt>What does it say?</prompt> | ||
<simpleChoice identifier="ChoiceA">You must stay with your luggage at all times.</simpleChoice> | ||
<simpleChoice identifier="ChoiceB">Do not let someone else look after your luggage.</simpleChoice> | ||
<simpleChoice identifier="ChoiceC">Remember your luggage when you leave.</simpleChoice> | ||
</choiceInteraction> | ||
</itemBody> | ||
<responseProcessing | ||
template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct"/> | ||
</assessmentItem> |