From 71ed15a01b25a518c90693cead9beba1bbf8c09d Mon Sep 17 00:00:00 2001 From: = Date: Thu, 10 Mar 2016 15:11:31 +0100 Subject: [PATCH] Added more meaningful information when dereferencing malformed assessmentItemRefs. --- src/qtism/data/state/VariableDeclaration.php | 1 + .../data/storage/xml/XmlCompactDocument.php | 6 ++-- .../xml/XmlCompactAssessmentDocumentTest.php | 14 ++++++++ .../custom/tests/invalidassessmentitemref.xml | 11 +++++++ .../invalid/invalidresponseidentifier.xml | 32 +++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/samples/custom/tests/invalidassessmentitemref.xml create mode 100644 test/samples/invalid/invalidresponseidentifier.xml diff --git a/src/qtism/data/state/VariableDeclaration.php b/src/qtism/data/state/VariableDeclaration.php index 3aa22dbb3..4a330783c 100644 --- a/src/qtism/data/state/VariableDeclaration.php +++ b/src/qtism/data/state/VariableDeclaration.php @@ -30,6 +30,7 @@ use qtism\common\enums\Cardinality; use \SplObserver; use \SplObjectStorage; +use \InvalidArgumentException; /** * From IMS QTI: diff --git a/src/qtism/data/storage/xml/XmlCompactDocument.php b/src/qtism/data/storage/xml/XmlCompactDocument.php index 5e571dec0..4f8fa335b 100644 --- a/src/qtism/data/storage/xml/XmlCompactDocument.php +++ b/src/qtism/data/storage/xml/XmlCompactDocument.php @@ -310,7 +310,7 @@ protected static function resolveAssessmentItemRef(ExtendedAssessmentItemRef $co $compactAssessmentItemRef->setTimeDependent($item->isTimeDependent()); $compactAssessmentItemRef->setEndAttemptIdentifiers($item->getEndAttemptIdentifiers()); } catch (Exception $e) { - $msg = "An error occured while unreferencing file '${href}'."; + $msg = "An error occured while unreferencing item reference with identifier '" . $compactAssessmentItemRef->getIdentifier() . "'."; throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } } @@ -333,8 +333,8 @@ protected static function resolveAssessmentSectionRef(AssessmentSectionRef $asse return $doc->getDocumentComponent(); } catch (XmlStorageException $e) { - $msg = "An error occured while unreferencing file '${href}'."; - throw new XmlStorageException($msg, XmlStorageException::RESOLUTION); + $msg = "An error occured while unreferencing section reference with identifier '" . $assessmentSectionRef->getIdentifier() . "'."; + throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } } diff --git a/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php b/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php index 4f141d613..7efeeb63e 100644 --- a/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php +++ b/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php @@ -9,6 +9,7 @@ use qtism\data\NavigationMode; use qtism\data\storage\xml\XmlDocument; use qtism\data\AssessmentTest; +use qtism\data\storage\xml\XmlStorageException; use \DOMDocument; class XmlCompactAssessmentDocumentTest extends QtiSmTestCase { @@ -505,4 +506,17 @@ public function testCreateFromAssessmentTestEndAttemptIdentifiers() { $this->assertEquals('LOST', $endAttemptIdentifiers[0]); $this->assertEquals('LOST2', $endAttemptIdentifiers[1]); } + + public function testCreateFromAssessmentTestInvalidAssessmentItemRefResolution() { + $this->setExpectedException( + '\\qtism\\data\\storage\\xml\\XmlStorageException', + "An error occured while unreferencing item reference with identifier 'Q01'.", + XmlStorageException::RESOLUTION + ); + + $doc = new XmlDocument('2.1'); + $file = self::samplesDir() . 'custom/tests/invalidassessmentitemref.xml'; + $doc->load($file); + $compactDoc = XmlCompactDocument::createFromXmlAssessmentTestDocument($doc, new LocalFileResolver()); + } } diff --git a/test/samples/custom/tests/invalidassessmentitemref.xml b/test/samples/custom/tests/invalidassessmentitemref.xml new file mode 100644 index 000000000..dc5cd513d --- /dev/null +++ b/test/samples/custom/tests/invalidassessmentitemref.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/test/samples/invalid/invalidresponseidentifier.xml b/test/samples/invalid/invalidresponseidentifier.xml new file mode 100644 index 000000000..3b8552f6d --- /dev/null +++ b/test/samples/invalid/invalidresponseidentifier.xml @@ -0,0 +1,32 @@ + + + + + + H + O + + + + + + + + + + + Which of the following elements are used to form water? + Hydrogen + Helium + Carbon + Oxygen + Nitrogen + Chlorine + + + +