From 7e1fc7945f41a9b46c4e35b94da464276a1bade1 Mon Sep 17 00:00:00 2001 From: Stella Lie Date: Wed, 10 Aug 2016 17:36:21 +1000 Subject: [PATCH] Add more tests and fix few bugs and update latest qti version --- composer.json | 2 +- composer.lock | 113 +++++++++--------- .../Interactions/MatchInteractionMapper.php | 14 ++- src/Processors/QtiV2/In/TestMapper.php | 57 ++------- .../TextEntryInteractionValidationBuilder.php | 15 ++- .../QtiV2/Out/QuestionTypes/HotspotMapper.php | 3 +- src/Utils/SimpleHtmlDom/simple_html_dom.php | 44 +++---- tests/Fixtures/tests/rtest01.xml | 16 +++ tests/Fixtures/tests/rtest02.xml | 38 ++++++ tests/Fixtures/tests/rtest03.xml | 38 ++++++ tests/Integration/ConverterTest.php | 6 + .../Processors/QtiV2/In/TestMapperTest.php | 43 +++++++ .../In/Fixtures/HotspotInteractionBuilder.php | 4 +- .../Interactions/HotspotInteractionTest.php | 2 +- 14 files changed, 259 insertions(+), 136 deletions(-) create mode 100644 tests/Fixtures/tests/rtest01.xml create mode 100644 tests/Fixtures/tests/rtest02.xml create mode 100644 tests/Fixtures/tests/rtest03.xml create mode 100644 tests/Integration/Processors/QtiV2/In/TestMapperTest.php diff --git a/composer.json b/composer.json index db03b02e..d57b7070 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "symfony/dependency-injection": "v2.6.8", "jms/aop-bundle": "1.0.1", "jms/di-extra-bundle": "1.5.0", - "qtism/qtism": "3.2.3" + "qtism/qtism": "4.2.0" }, "require-dev": { "phpunit/phpunit": "4.8.4" diff --git a/composer.lock b/composer.lock index 011a34d3..4469f77c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "73ec6819cd6a6ab284fc9ffecb2db34d", - "content-hash": "bcb2cf4e09c0d4b326ae9d44c24cd120", + "hash": "aa9b86795b162e6a00750d19bb569b24", + "content-hash": "a26cd62e6415f57b8632a899895ab9a3", "packages": [ { "name": "doctrine/annotations", @@ -469,16 +469,16 @@ }, { "name": "qtism/qtism", - "version": "3.2.3", + "version": "4.2.0", "source": { "type": "git", "url": "https://github.com/oat-sa/qti-sdk.git", - "reference": "ba25bee79f055c762716c632c1b7e5a85c9b3013" + "reference": "6dada5a4d83aa4cdfbbbb21a6137a385055bcd14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/oat-sa/qti-sdk/zipball/ba25bee79f055c762716c632c1b7e5a85c9b3013", - "reference": "ba25bee79f055c762716c632c1b7e5a85c9b3013", + "url": "https://api.github.com/repos/oat-sa/qti-sdk/zipball/6dada5a4d83aa4cdfbbbb21a6137a385055bcd14", + "reference": "6dada5a4d83aa4cdfbbbb21a6137a385055bcd14", "shasum": "" }, "require": { @@ -530,7 +530,7 @@ "QTI", "TAO" ], - "time": "2016-05-09 10:51:41" + "time": "2016-08-03 15:33:47" }, { "name": "symfony/config", @@ -585,16 +585,16 @@ }, { "name": "symfony/debug", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "2477199ad1dd1c43fe18a84d7907fffa025eff10" + "reference": "f7c5256f43debdabec79146a5db226fd15aedbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/2477199ad1dd1c43fe18a84d7907fffa025eff10", - "reference": "2477199ad1dd1c43fe18a84d7907fffa025eff10", + "url": "https://api.github.com/repos/symfony/debug/zipball/f7c5256f43debdabec79146a5db226fd15aedbea", + "reference": "f7c5256f43debdabec79146a5db226fd15aedbea", "shasum": "" }, "require": { @@ -638,7 +638,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:29:29" + "time": "2016-07-30 07:20:35" }, { "name": "symfony/dependency-injection", @@ -703,16 +703,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "b180b70439dca70049b6b9b7e21d75e6e5d7aca9" + "reference": "889983a79a043dfda68f38c38b6dba092dd49cd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b180b70439dca70049b6b9b7e21d75e6e5d7aca9", - "reference": "b180b70439dca70049b6b9b7e21d75e6e5d7aca9", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/889983a79a043dfda68f38c38b6dba092dd49cd8", + "reference": "889983a79a043dfda68f38c38b6dba092dd49cd8", "shasum": "" }, "require": { @@ -759,20 +759,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:29:29" + "time": "2016-07-28 16:56:28" }, { "name": "symfony/filesystem", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "7258ddd6f987053f21fa43d03430580ba54e6096" + "reference": "ab4c3f085c8f5a56536845bf985c4cef30bf75fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/7258ddd6f987053f21fa43d03430580ba54e6096", - "reference": "7258ddd6f987053f21fa43d03430580ba54e6096", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/ab4c3f085c8f5a56536845bf985c4cef30bf75fd", + "reference": "ab4c3f085c8f5a56536845bf985c4cef30bf75fd", "shasum": "" }, "require": { @@ -808,7 +808,7 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:31:50" + "time": "2016-07-20 05:41:28" }, { "name": "symfony/finder", @@ -945,16 +945,16 @@ }, { "name": "symfony/http-foundation", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "7a55440a2bebd37b8bd06f99f5def1ddf0aa9249" + "reference": "f20bea598906c990eebe3c70a63ca5ed18cdbc11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/7a55440a2bebd37b8bd06f99f5def1ddf0aa9249", - "reference": "7a55440a2bebd37b8bd06f99f5def1ddf0aa9249", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/f20bea598906c990eebe3c70a63ca5ed18cdbc11", + "reference": "f20bea598906c990eebe3c70a63ca5ed18cdbc11", "shasum": "" }, "require": { @@ -996,7 +996,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-06-29 07:02:14" + "time": "2016-07-30 07:20:35" }, { "name": "symfony/http-kernel", @@ -1418,16 +1418,16 @@ }, { "name": "symfony/process", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "89f33c16796415ccfd8bb3cf8d520cbb79899bfe" + "reference": "d20332e43e8774ff8870b394f3dd6020cc7f8e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/89f33c16796415ccfd8bb3cf8d520cbb79899bfe", - "reference": "89f33c16796415ccfd8bb3cf8d520cbb79899bfe", + "url": "https://api.github.com/repos/symfony/process/zipball/d20332e43e8774ff8870b394f3dd6020cc7f8e0c", + "reference": "d20332e43e8774ff8870b394f3dd6020cc7f8e0c", "shasum": "" }, "require": { @@ -1463,7 +1463,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:29:29" + "time": "2016-07-28 11:13:19" }, { "name": "symfony/routing", @@ -1536,16 +1536,16 @@ }, { "name": "symfony/security-core", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/security-core.git", - "reference": "885f98ee7c4d136db2672a4f02ccb412f15d8921" + "reference": "d9c25d42e002203ab93805f0a59a5b7c5a7dbec9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/security-core/zipball/885f98ee7c4d136db2672a4f02ccb412f15d8921", - "reference": "885f98ee7c4d136db2672a4f02ccb412f15d8921", + "url": "https://api.github.com/repos/symfony/security-core/zipball/d9c25d42e002203ab93805f0a59a5b7c5a7dbec9", + "reference": "d9c25d42e002203ab93805f0a59a5b7c5a7dbec9", "shasum": "" }, "require": { @@ -1600,20 +1600,20 @@ ], "description": "Symfony Security Component - Core Library", "homepage": "https://symfony.com", - "time": "2016-06-29 05:29:29" + "time": "2016-07-05 11:05:26" }, { "name": "symfony/security-csrf", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/security-csrf.git", - "reference": "817f35960621fdf3e29ce557cfcb70d3dae903c9" + "reference": "02087a07e04f97351d9337868d07b690eef10d60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/security-csrf/zipball/817f35960621fdf3e29ce557cfcb70d3dae903c9", - "reference": "817f35960621fdf3e29ce557cfcb70d3dae903c9", + "url": "https://api.github.com/repos/symfony/security-csrf/zipball/02087a07e04f97351d9337868d07b690eef10d60", + "reference": "02087a07e04f97351d9337868d07b690eef10d60", "shasum": "" }, "require": { @@ -1658,11 +1658,11 @@ ], "description": "Symfony Security Component - CSRF Library", "homepage": "https://symfony.com", - "time": "2016-03-07 14:04:32" + "time": "2016-07-05 11:05:26" }, { "name": "symfony/stopwatch", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -1711,16 +1711,16 @@ }, { "name": "symfony/templating", - "version": "v2.8.8", + "version": "v2.8.9", "source": { "type": "git", "url": "https://github.com/symfony/templating.git", - "reference": "9a3eb3202f6d2feab53e77b97e3ed10c339972d7" + "reference": "b7e1ea8268c6bb57b50f0f0f950088d1573fedb1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/templating/zipball/9a3eb3202f6d2feab53e77b97e3ed10c339972d7", - "reference": "9a3eb3202f6d2feab53e77b97e3ed10c339972d7", + "url": "https://api.github.com/repos/symfony/templating/zipball/b7e1ea8268c6bb57b50f0f0f950088d1573fedb1", + "reference": "b7e1ea8268c6bb57b50f0f0f950088d1573fedb1", "shasum": "" }, "require": { @@ -1762,7 +1762,7 @@ ], "description": "Symfony Templating Component", "homepage": "https://symfony.com", - "time": "2016-03-27 09:27:49" + "time": "2016-07-30 07:20:35" }, { "name": "symfony/translation", @@ -3041,28 +3041,29 @@ }, { "name": "webmozart/assert", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3|^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.2-dev" } }, "autoload": { @@ -3086,7 +3087,7 @@ "check", "validate" ], - "time": "2015-08-24 13:29:44" + "time": "2016-08-09 15:02:57" } ], "aliases": [], diff --git a/src/Processors/QtiV2/In/Interactions/MatchInteractionMapper.php b/src/Processors/QtiV2/In/Interactions/MatchInteractionMapper.php index 42203188..60da7dd3 100644 --- a/src/Processors/QtiV2/In/Interactions/MatchInteractionMapper.php +++ b/src/Processors/QtiV2/In/Interactions/MatchInteractionMapper.php @@ -44,7 +44,7 @@ public function getQuestionType() $uiStyle = new choicematrix_ui_style(); $uiStyle->set_type('table'); - $isMultipleResponse = $this->isMultipleResponse($interaction->getTargetChoices()); + $isMultipleResponse = $this->isMultipleResponse($interaction); $question = new choicematrix('choicematrix', $options, $stems); $question->set_multiple_responses($isMultipleResponse); $question->set_stimulus($this->getPrompt()); @@ -55,11 +55,17 @@ public function getQuestionType() return $question; } - private function isMultipleResponse(SimpleMatchSet $targetChoices) + private function isMultipleResponse(QtiMatchInteraction $interaction) { // We determine whether the question shall be mapped to `multiple_responses` as true - // if any the target choices (options) can be mapped to be more than 1 - foreach ($targetChoices->getSimpleAssociableChoices() as $choice) { + // if any the source choices (stems or options) can be mapped to be more than 1 + foreach ($interaction->getSourceChoices()->getSimpleAssociableChoices() as $choice) { + /** @var SimpleAssociableChoice $choice */ + if ($choice->getMatchMax() !== 1) { + return true; + } + } + foreach ($interaction->getTargetChoices()->getSimpleAssociableChoices() as $choice) { /** @var SimpleAssociableChoice $choice */ if ($choice->getMatchMax() !== 1) { return true; diff --git a/src/Processors/QtiV2/In/TestMapper.php b/src/Processors/QtiV2/In/TestMapper.php index 999d7c47..b3c72190 100644 --- a/src/Processors/QtiV2/In/TestMapper.php +++ b/src/Processors/QtiV2/In/TestMapper.php @@ -2,21 +2,12 @@ namespace LearnosityQti\Processors\QtiV2\In; -use LearnosityQti\AppContainer; use LearnosityQti\Entities\Activity\activity; use LearnosityQti\Entities\Activity\activity_data; -use LearnosityQti\Entities\Activity\activity_data_sections_item; -use LearnosityQti\Entities\Activity\activity_data_sections_item_config; use LearnosityQti\Exceptions\MappingException; -use LearnosityQti\Processors\QtiV2\In\Processings\ProcessingInterface; use LearnosityQti\Services\LogService; use qtism\data\AssessmentItem; -use qtism\data\AssessmentItemRef; -use qtism\data\AssessmentSection; -use qtism\data\AssessmentSectionCollection; use qtism\data\AssessmentTest; -use qtism\data\content\ItemBody; -use qtism\data\processing\ResponseProcessing; use qtism\data\storage\xml\XmlDocument; class TestMapper @@ -38,44 +29,20 @@ public function parse($xmlString, $validate = true) throw new MappingException('XML is not a valid document'); } - // TODO: Write up the exceptions! - return [$this->buildActivity($assessmentTest), []]; - } + // Ignore `testPart` and `assessmentSection`. Grab every item references and merge in array + $itemReferences = []; + foreach ($assessmentTest->getComponentsByClassName('assessmentItemRef', true) as $assessmentItemRef) { + $itemReferences[] = $assessmentItemRef->getIdentifier(); + } + LogService::log('Support for mapping is very limited. Elements such `testPart`, `assessmentSections`, `seclection`, `rubricBlock`, ' + . 'etc are ignored. Please see developer docs for more details'); - private function buildActivity(AssessmentTest $assessmentTest) - { $data = new activity_data(); + $data->set_items($itemReferences); + $activity = new activity($assessmentTest->getIdentifier(), $data); - // Support on sections first - $sectionCollection = $assessmentTest->getComponentsByClassName('assessmentSection', true); - $sections = []; - /** @var AssessmentSection $assessmentSection */ - foreach ($sectionCollection as $assessmentSection) { - $references = []; - - // Populate item references - $itemRefCollection = $assessmentSection->getComponentsByClassName('assessmentItemRef', true); - /** @var AssessmentItemRef $assessmentItemRef */ - foreach ($itemRefCollection as $assessmentItemRef) { - $references[] = $assessmentItemRef->getIdentifier(); - } - $section = new activity_data_sections_item(); - $section->set_items($references); - - // Set assessment section title if exists - if (!empty($assessmentSection->getTitle())) { - $sectionConfig = new activity_data_sections_item_config(); - $sectionConfig->set_subtitle($assessmentSection->getTitle()); - $section->set_config($sectionConfig); - } - - $sections[] = $section; - } - $data->set_sections($sections); - $reference = $assessmentTest->getIdentifier(); - $activity = new activity($reference, $data); - - // Return dah` activity~! - return $activity; + // Flush out all the error messages stored in this static class, also ensure they are unique + $messages = array_values(array_unique(LogService::flush())); + return [$activity, $messages]; } } diff --git a/src/Processors/QtiV2/In/Validation/TextEntryInteractionValidationBuilder.php b/src/Processors/QtiV2/In/Validation/TextEntryInteractionValidationBuilder.php index 69525e94..c1c113df 100644 --- a/src/Processors/QtiV2/In/Validation/TextEntryInteractionValidationBuilder.php +++ b/src/Processors/QtiV2/In/Validation/TextEntryInteractionValidationBuilder.php @@ -3,6 +3,7 @@ use LearnosityQti\Processors\Learnosity\In\ValidationBuilder\ValidationBuilder; use LearnosityQti\Processors\Learnosity\In\ValidationBuilder\ValidResponse; +use LearnosityQti\Services\LogService; use LearnosityQti\Utils\ArrayUtil; use qtism\data\state\MapEntry; use qtism\data\state\ResponseDeclaration; @@ -31,11 +32,15 @@ protected function getMatchCorrectTemplateValidation() $interactionResponses = []; foreach ($this->responseDeclarations as $responseIdentifier => $responseDeclaration) { /** @var ResponseDeclaration $responseDeclaration */ - $correctResponses = $responseDeclaration->getCorrectResponse()->getValues()->getArrayCopy(true); - $interactionResponses[] = array_map(function ($value) { - /** @var Value $value */ - return new ValidResponse(1, [$value->getValue()]); - }, $correctResponses); + if (!empty($responseDeclaration->getCorrectResponse())) { + $correctResponses = $responseDeclaration->getCorrectResponse()->getValues()->getArrayCopy(true); + $interactionResponses[] = array_map(function ($value) { + /** @var Value $value */ + return new ValidResponse(1, [$value->getValue()]); + }, $correctResponses); + } else { + LogService::log('Response declaration has no correct response values. Thus, validation ignored'); + } } $responses = ArrayUtil::cartesianProductForResponses($interactionResponses); return ValidationBuilder::build('clozetext', 'exactMatch', $responses); diff --git a/src/Processors/QtiV2/Out/QuestionTypes/HotspotMapper.php b/src/Processors/QtiV2/Out/QuestionTypes/HotspotMapper.php index b09c4ab0..cc67e64f 100644 --- a/src/Processors/QtiV2/Out/QuestionTypes/HotspotMapper.php +++ b/src/Processors/QtiV2/Out/QuestionTypes/HotspotMapper.php @@ -45,7 +45,8 @@ public function convert(BaseQuestionType $questionType, $interactionIdentifier, $imageObject = $this->buildMainImageObject($question->get_image()); $hasMultiResponses = !empty($question->get_multiple_responses()) && $question->get_multiple_responses(); $maxChoices = $hasMultiResponses ? $choicesCollection->count() : 1; - $interaction = new HotspotInteraction($interactionIdentifier, $imageObject, $maxChoices, $choicesCollection); + $interaction = new HotspotInteraction($interactionIdentifier, $imageObject, $choicesCollection); + $interaction->setMaxChoices($maxChoices); // Set min choices are 0 because we allow no responses $interaction->setMinChoices(0); diff --git a/src/Utils/SimpleHtmlDom/simple_html_dom.php b/src/Utils/SimpleHtmlDom/simple_html_dom.php index 990f7de1..9c29e264 100644 --- a/src/Utils/SimpleHtmlDom/simple_html_dom.php +++ b/src/Utils/SimpleHtmlDom/simple_html_dom.php @@ -46,27 +46,29 @@ * All of the Defines for the classes below. * @author S.C. Chen */ -define('HDOM_TYPE_ELEMENT', 1); -define('HDOM_TYPE_COMMENT', 2); -define('HDOM_TYPE_TEXT', 3); -define('HDOM_TYPE_ENDTAG', 4); -define('HDOM_TYPE_ROOT', 5); -define('HDOM_TYPE_UNKNOWN', 6); -define('HDOM_QUOTE_DOUBLE', 0); -define('HDOM_QUOTE_SINGLE', 1); -define('HDOM_QUOTE_NO', 3); -define('HDOM_INFO_BEGIN', 0); -define('HDOM_INFO_END', 1); -define('HDOM_INFO_QUOTE', 2); -define('HDOM_INFO_SPACE', 3); -define('HDOM_INFO_TEXT', 4); -define('HDOM_INFO_INNER', 5); -define('HDOM_INFO_OUTER', 6); -define('HDOM_INFO_ENDSPACE',7); -define('DEFAULT_TARGET_CHARSET', 'UTF-8'); -define('DEFAULT_BR_TEXT', "\r\n"); -define('DEFAULT_SPAN_TEXT', " "); -define('MAX_FILE_SIZE', 600000); +if (!defined('HDOM_TYPE_ELEMENT')) { + define('HDOM_TYPE_ELEMENT', 1); + define('HDOM_TYPE_COMMENT', 2); + define('HDOM_TYPE_TEXT', 3); + define('HDOM_TYPE_ENDTAG', 4); + define('HDOM_TYPE_ROOT', 5); + define('HDOM_TYPE_UNKNOWN', 6); + define('HDOM_QUOTE_DOUBLE', 0); + define('HDOM_QUOTE_SINGLE', 1); + define('HDOM_QUOTE_NO', 3); + define('HDOM_INFO_BEGIN', 0); + define('HDOM_INFO_END', 1); + define('HDOM_INFO_QUOTE', 2); + define('HDOM_INFO_SPACE', 3); + define('HDOM_INFO_TEXT', 4); + define('HDOM_INFO_INNER', 5); + define('HDOM_INFO_OUTER', 6); + define('HDOM_INFO_ENDSPACE',7); + define('DEFAULT_TARGET_CHARSET', 'UTF-8'); + define('DEFAULT_BR_TEXT', "\r\n"); + define('DEFAULT_SPAN_TEXT', " "); + define('MAX_FILE_SIZE', 600000); +} // helper functions // ----------------------------------------------------------------------------- // get html dom from file diff --git a/tests/Fixtures/tests/rtest01.xml b/tests/Fixtures/tests/rtest01.xml new file mode 100644 index 00000000..58730db8 --- /dev/null +++ b/tests/Fixtures/tests/rtest01.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/tests/Fixtures/tests/rtest02.xml b/tests/Fixtures/tests/rtest02.xml new file mode 100644 index 00000000..495c2f40 --- /dev/null +++ b/tests/Fixtures/tests/rtest02.xml @@ -0,0 +1,38 @@ + + + + + + + +

Instructions for Section A

+
+ + + +
+ + + + + +

Instructions for Section B

+
+ + + + + + + + +
+
+
diff --git a/tests/Fixtures/tests/rtest03.xml b/tests/Fixtures/tests/rtest03.xml new file mode 100644 index 00000000..9134084a --- /dev/null +++ b/tests/Fixtures/tests/rtest03.xml @@ -0,0 +1,38 @@ + + + + + + + +

Instructions for Section A

+
+ + + +
+ + +

Instructions for Section B

+
+ + + + + + +
+
+ + + + + + + +
diff --git a/tests/Integration/ConverterTest.php b/tests/Integration/ConverterTest.php index 9c5e5aa5..3f8bd3a8 100644 --- a/tests/Integration/ConverterTest.php +++ b/tests/Integration/ConverterTest.php @@ -20,6 +20,12 @@ public function testConvertRegularQtiXmlToLearnosityJson() list($item, $questions, $manifest) = Converter::convertQtiItemToLearnosity($xmlString); } + public function testConvertRegularQtiTestXmlToLearnosityJson() + { + $xmlString = $this->getFixtureFileContents('tests/rtest01.xml'); + list($activity, $manifest) = Converter::convertQtiTestToLearnosity($xmlString); + } + public function testConvertRegularQtiXmlWithCdataToLearnosityJson() { $xmlString = $this->getFixtureFileContents('otherqtis/withcdata.xml'); diff --git a/tests/Integration/Processors/QtiV2/In/TestMapperTest.php b/tests/Integration/Processors/QtiV2/In/TestMapperTest.php new file mode 100644 index 00000000..25079e3d --- /dev/null +++ b/tests/Integration/Processors/QtiV2/In/TestMapperTest.php @@ -0,0 +1,43 @@ +getFixtureFileContents('tests/rtest01.xml'); + $testMapper = AppContainer::getApplicationContainer()->get('qtiv2_test_mapper'); + list($activity, $manifest) = $testMapper->parse($xml); + + /** @var activity $activity */ + $this->assertTrue($activity instanceof activity); + $this->assertCount(3, $activity->get_data()->get_items()); + } + + public function testParseWithSectionsTwo() + { + $xml = $this->getFixtureFileContents('tests/rtest02.xml'); + $testMapper = AppContainer::getApplicationContainer()->get('qtiv2_test_mapper'); + list($activity, $manifest) = $testMapper->parse($xml); + + /** @var activity $activity */ + $this->assertTrue($activity instanceof activity); + $this->assertCount(9, $activity->get_data()->get_items()); + } + + public function testParseWithSectionsThree() + { + $xml = $this->getFixtureFileContents('tests/rtest03.xml'); + $testMapper = AppContainer::getApplicationContainer()->get('qtiv2_test_mapper'); + list($activity, $manifest) = $testMapper->parse($xml); + + /** @var activity $activity */ + $this->assertTrue($activity instanceof activity); + $this->assertCount(9, $activity->get_data()->get_items()); + } +} diff --git a/tests/Unit/Processors/QtiV2/In/Fixtures/HotspotInteractionBuilder.php b/tests/Unit/Processors/QtiV2/In/Fixtures/HotspotInteractionBuilder.php index 9ea002fc..44168554 100644 --- a/tests/Unit/Processors/QtiV2/In/Fixtures/HotspotInteractionBuilder.php +++ b/tests/Unit/Processors/QtiV2/In/Fixtures/HotspotInteractionBuilder.php @@ -17,7 +17,7 @@ public static function buildWithRectShapesChoices($responseIdentifier) $imageObject->setWidth(131); $imageObject->setHeight(37); $collection = self::buildRectShapesChoices(); - return new HotspotInteraction($responseIdentifier, $imageObject, 0, $collection); + return new HotspotInteraction($responseIdentifier, $imageObject, $collection); } public static function buildWithCircleShapesChoices($responseIdentifier) @@ -31,7 +31,7 @@ public static function buildWithCircleShapesChoices($responseIdentifier) $collection->attach(new HotspotChoice('B', QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, [118, 184, 8]))); $collection->attach(new HotspotChoice('C', QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, [150, 235, 8]))); $collection->attach(new HotspotChoice('D', QtiShape::CIRCLE, new QtiCoords(QtiShape::CIRCLE, [96, 114, 8]))); - return new HotspotInteraction($responseIdentifier, $imageObject, 0, $collection); + return new HotspotInteraction($responseIdentifier, $imageObject, $collection); } public static function buildWithPolyShapesChoices($responseIdentifier) diff --git a/tests/Unit/Processors/QtiV2/In/Interactions/HotspotInteractionTest.php b/tests/Unit/Processors/QtiV2/In/Interactions/HotspotInteractionTest.php index a04428da..805bc1a4 100644 --- a/tests/Unit/Processors/QtiV2/In/Interactions/HotspotInteractionTest.php +++ b/tests/Unit/Processors/QtiV2/In/Interactions/HotspotInteractionTest.php @@ -17,7 +17,7 @@ public function testImageWithoutWidth() $imageObject = new Object('http://anyurl.com', 'image/png'); $collection = HotspotInteractionBuilder::buildRectShapesChoices(); - $interaction = new HotspotInteraction('thisJustWontWork', $imageObject, 0, $collection); + $interaction = new HotspotInteraction('thisJustWontWork', $imageObject, $collection); $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect(); $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('thisJustWontWork', ['A']);