Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Sep 26, 2016
2 parents 83103f9 + 6165ec2 commit aaaf6fd
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $c
}

$media = null;
$isAudio = false;

if (in_array($component->getObject()->getType(), $this->getVideoTypes()) === true) {
// Transform the object element representing the video.
Expand All @@ -190,6 +191,7 @@ protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $c
$source->setAttribute('type', $component->getObject()->getType());
$source->setAttribute('src', $component->getObject()->getData());
$media->appendChild($source);
$isAudio = true;
} elseif (in_array($component->getObject()->getType(), $this->getImageTypes()) === true) {
$media = $fragment->ownerDocument->createElement('img');
$media->setAttribute('src', $component->getObject()->getData());
Expand All @@ -200,12 +202,14 @@ protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $c
$objects = $fragment->firstChild->getElementsByTagName('object');
$fragment->firstChild->replaceChild($media, $objects->item(0));

if (empty($width) !== true) {
$media->setAttribute('width', $width);
}
if ($isAudio === false) {
if (empty($width) !== true) {
$media->setAttribute('width', $width);
}

if (empty($height) !== true) {
$media->setAttribute('height', $height);
if (empty($height) !== true) {
$media->setAttribute('height', $height);
}
}
}
}
Expand Down
81 changes: 81 additions & 0 deletions test/qtismtest/runtime/processing/ResponseProcessingEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,85 @@ public function testSetOutcomeValueWithSum() {
$this->assertEquals(1., $state['SCORE']->getValue());
$this->assertEquals(1., $state['MAXSCORE']->getValue());
}

public function testWrongComponentType()
{
$responseProcessing = $this->createComponentFromXml(
'<responseIf>
<isNull>
<variable identifier="response-X" />
</isNull>
<setOutcomeValue identifier="score-X">
<baseValue baseType="integer">0</baseValue>
</setOutcomeValue>
</responseIf>'
);

$this->setExpectedException(
'\\InvalidArgumentException',
'The ResponseProcessingEngine class only accepts ResponseProcessing objects to be executed.'
);

$engine = new ResponseProcessingEngine($responseProcessing);
}

public function testAddTemplateMappingWrongFirstParam()
{
$responseProcessing = $this->createComponentFromXml('
<responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct"/>
');

$engine = new ResponseProcessingEngine($responseProcessing);

$this->setExpectedException(
'\\InvalidArgumentException',
"The uri argument must be a string, 'integer' given."
);

$engine->addTemplateMapping(10, 'http://taotesting.com');
}

public function testAddTemplateMappingWrongSecondParam()
{
$responseProcessing = $this->createComponentFromXml('
<responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct"/>
');

$engine = new ResponseProcessingEngine($responseProcessing);

$this->setExpectedException(
'\\InvalidArgumentException',
"The url argument must be a string, 'string' given."
);

$engine->addTemplateMapping('http://taotesting.com', 10);
}

public function testRemoveTemplateMappingWrongUrl()
{
$responseProcessing = $this->createComponentFromXml('
<responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct"/>
');

$engine = new ResponseProcessingEngine($responseProcessing);

$this->setExpectedException(
'\\InvalidArgumentException',
"The uri argument must be a string, 'integer' given."
);

$engine->removeTemplateMapping(10);
}

public function testRemoveTemplateMapping()
{
$responseProcessing = $this->createComponentFromXml('
<responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct"/>
');

$engine = new ResponseProcessingEngine($responseProcessing);
$engine->removeTemplateMapping('http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct');

$this->assertTrue(true, "The template mapping removal should not produce any error.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ public function testRenderingProvider()
GoldilocksRenderingEngine::STYLESHEET_INLINE,
GoldilocksRenderingEngine::CSSCLASS_CONCRETE
),
// mediaInteraction-0
array(
self::samplesDir() . 'custom/items/media_audio.xml',
self::samplesDir() . 'rendering/goldilocks/rendered/mediaInteraction-0.html',
GoldilocksRenderingEngine::CONTEXT_STATIC,
GoldilocksRenderingEngine::XMLBASE_IGNORE,
GoldilocksRenderingEngine::STYLESHEET_INLINE,
GoldilocksRenderingEngine::CSSCLASS_CONCRETE
),
// mediaInteraction-1
array(
self::samplesDir() . 'custom/items/media_video.xml',
self::samplesDir() . 'rendering/goldilocks/rendered/mediaInteraction-1.html',
GoldilocksRenderingEngine::CONTEXT_STATIC,
GoldilocksRenderingEngine::XMLBASE_IGNORE,
GoldilocksRenderingEngine::STYLESHEET_INLINE,
GoldilocksRenderingEngine::CSSCLASS_CONCRETE
),
// mediaInteraction-2
array(
self::samplesDir() . 'custom/items/media_image.xml',
self::samplesDir() . 'rendering/goldilocks/rendered/mediaInteraction-2.html',
GoldilocksRenderingEngine::CONTEXT_STATIC,
GoldilocksRenderingEngine::XMLBASE_IGNORE,
GoldilocksRenderingEngine::STYLESHEET_INLINE,
GoldilocksRenderingEngine::CSSCLASS_CONCRETE
),
);
}

Expand All @@ -259,10 +286,10 @@ public function testRenderingProvider()
$engine->setCssClassPolicy($cssClassPolicy);
$doc = new XmlDocument();
$doc->load(self::samplesDir() . 'ims/items/2_2/text_entry.xml');
$doc->load(self::samplesDir() . 'custom/items/media_image.xml');
$rendered = $engine->render($doc->getDocumentComponent());
$strRendered = $rendered->saveXML($rendered->documentElement);
file_put_contents(self::samplesDir() . 'rendering/goldilocks/rendered/textEntryInteraction-0.html', $strRendered . "\n");
file_put_contents(self::samplesDir() . 'rendering/goldilocks/rendered/mediaInteraction-2.html', $strRendered . "\n");
}*/
}
14 changes: 14 additions & 0 deletions test/samples/custom/items/media_audio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="media-audio" title="Media with Audio" adaptive="false" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="integer"/>
<itemBody>
<p>A Media Interaction with some audio.</p>
<mediaInteraction responseIdentifier="RESPONSE" autostart="true" minPlays="1" maxPlays="1" loop="false">
<!-- width and height will be ignored for audio types. -->
<object type="audio/ogg" data="audio.ogg" width="640" height="480"/>
</mediaInteraction>
</itemBody>
</assessmentItem>
13 changes: 13 additions & 0 deletions test/samples/custom/items/media_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="media-image" title="Media with Image" adaptive="false" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="integer"/>
<itemBody>
<p>A Media Interaction with some images.</p>
<mediaInteraction responseIdentifier="RESPONSE" autostart="true" minPlays="1" maxPlays="1" loop="false">
<object type="image/jpeg" data="image.jpg" width="640" height="480"/>
</mediaInteraction>
</itemBody>
</assessmentItem>
13 changes: 13 additions & 0 deletions test/samples/custom/items/media_video.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="media-video" title="Media with Video" adaptive="false" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="integer"/>
<itemBody>
<p>A Media Interaction with some video.</p>
<mediaInteraction responseIdentifier="RESPONSE" autostart="true" minPlays="1" maxPlays="1" loop="false">
<object type="video/mp4" data="video.mp4" width="640" height="480"/>
</mediaInteraction>
</itemBody>
</assessmentItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-identifier="media-audio" data-title="Media with Audio" data-adaptive="false" data-time-dependent="false" class="qti-assessmentItem"><div class="qti-itemBody"><p class="qti-p">A Media Interaction with some audio.</p><div data-response-identifier="RESPONSE" data-autostart="true" data-min-plays="1" data-max-plays="1" data-loop="false" class="qti-mediaInteraction"><audio><source type="audio/ogg" src="audio.ogg"/></audio></div></div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-identifier="media-video" data-title="Media with Video" data-adaptive="false" data-time-dependent="false" class="qti-assessmentItem"><div class="qti-itemBody"><p class="qti-p">A Media Interaction with some video.</p><div data-response-identifier="RESPONSE" data-autostart="true" data-min-plays="1" data-max-plays="1" data-loop="false" class="qti-mediaInteraction"><video width="640" height="480"><source type="video/mp4" src="video.mp4"/></video></div></div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-identifier="media-image" data-title="Media with Image" data-adaptive="false" data-time-dependent="false" class="qti-assessmentItem"><div class="qti-itemBody"><p class="qti-p">A Media Interaction with some images.</p><div data-response-identifier="RESPONSE" data-autostart="true" data-min-plays="1" data-max-plays="1" data-loop="false" class="qti-mediaInteraction"><img src="image.jpg" width="640" height="480"/></div></div></div>

0 comments on commit aaaf6fd

Please sign in to comment.