From d681b388cf679da1fd46793cbbfb1c6bf98165f3 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 27 Jul 2016 11:05:48 +0200 Subject: [PATCH 1/2] Use the same resolver for assessmentSectionRef and assessmentItemRef. --- .../data/storage/xml/XmlCompactDocument.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/qtism/data/storage/xml/XmlCompactDocument.php b/src/qtism/data/storage/xml/XmlCompactDocument.php index 5b601cac6..7d4b9de29 100644 --- a/src/qtism/data/storage/xml/XmlCompactDocument.php +++ b/src/qtism/data/storage/xml/XmlCompactDocument.php @@ -144,10 +144,11 @@ protected function createMarshallerFactory() * Create a new instance of XmlCompactDocument from an XmlAssessmentTestDocument. * * @param \qtism\data\storage\xml\XmlDocument $xmlAssessmentTestDocument An XmlAssessmentTestDocument object you want to store as a compact XML file. + * @param \qtism\data\storage\FileResolver (optional) $resolver A resolver aiming at resolving assessmentSectionRef and assessmentItemRef components. * @return \qtism\data\storage\xml\XmlCompactDocument An XmlCompactAssessmentTestDocument object. * @throws \qtism\data\storage\xml\XmlStorageException If an error occurs while transforming the XmlAssessmentTestDocument object into an XmlCompactAssessmentTestDocument object. */ - public static function createFromXmlAssessmentTestDocument(XmlDocument $xmlAssessmentTestDocument, FileResolver $itemResolver = null) + public static function createFromXmlAssessmentTestDocument(XmlDocument $xmlAssessmentTestDocument, FileResolver $resolver = null) { $compactAssessmentTest = new XmlCompactDocument(); $identifier = $xmlAssessmentTestDocument->getDocumentComponent()->getIdentifier(); @@ -162,13 +163,10 @@ public static function createFromXmlAssessmentTestDocument(XmlDocument $xmlAsses $assessmentTest->setToolName($xmlAssessmentTestDocument->getDocumentComponent()->getToolName()); $assessmentTest->setToolVersion($xmlAssessmentTestDocument->getDocumentComponent()->getToolVersion()); - // File resolution. - $sectionResolver = new LocalFileResolver($xmlAssessmentTestDocument->getUrl()); - - if (is_null($itemResolver) === true) { - $itemResolver = new LocalFileResolver($xmlAssessmentTestDocument->getUrl()); + if (is_null($resolver) === true) { + $resolver = new LocalFileResolver($xmlAssessmentTestDocument->getUrl()); } else { - $itemResolver->setBasePath($xmlAssessmentTestDocument->getUrl()); + $resolver->setBasePath($xmlAssessmentTestDocument->getUrl()); } // It simply consists of replacing assessmentItemRef and assessmentSectionRef elements. @@ -216,8 +214,8 @@ public static function createFromXmlAssessmentTestDocument(XmlDocument $xmlAsses $baseUri = $component->getUrl(); } - $itemResolver->setBasePath($baseUri); - self::resolveAssessmentItemRef($compactRef, $itemResolver); + $resolver->setBasePath($baseUri); + self::resolveAssessmentItemRef($compactRef, $resolver); $previousParts->replace($component, $compactRef); break; @@ -226,7 +224,7 @@ public static function createFromXmlAssessmentTestDocument(XmlDocument $xmlAsses } elseif ($component instanceof AssessmentSectionRef) { // We follow the unreferenced AssessmentSection as if it was // the 1st pass. - $assessmentSection = self::resolveAssessmentSectionRef($component, $sectionResolver); + $assessmentSection = self::resolveAssessmentSectionRef($component, $resolver); $previousParts = $previous->getSectionParts(); foreach ($previousParts as $k => $previousPart) { if ($previousParts[$k] === $component) { From 06aec9c2a837d21b14dded67ecd809787c1a3238 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 27 Jul 2016 11:06:13 +0200 Subject: [PATCH 2/2] Some more unit tests for XmlCompactDocument. --- .../data/storage/xml/XmlCompactAssessmentDocumentTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php b/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php index e76298fa3..b8c41f374 100644 --- a/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php +++ b/test/qtismtest/data/storage/xml/XmlCompactAssessmentDocumentTest.php @@ -123,6 +123,13 @@ public function testCreateFromExploded(XmlCompactDocument $compactDoc = null) { $assessmentItemRefs = $assessmentSections2ndLvl['Sektion_181865064']->getSectionParts(); $this->assertEquals(13, count($assessmentItemRefs)); + + // Globally, we should have only one testPart, 2 sections, 13 items + $this->assertEquals(1, count($compactDoc->getDocumentComponent()->getComponentsByClassName('testPart'))); + $this->assertEquals(2, count($compactDoc->getDocumentComponent()->getComponentsByClassName('assessmentSection'))); + $this->assertEquals(13, count($compactDoc->getDocumentComponent()->getComponentsByClassName('assessmentItemRef'))); + // And no more assessmentSectionRef, as they have been resolved! + $this->assertEquals(0, count($compactDoc->getDocumentComponent()->getComponentsByClassName('assessmentSectionRef'))); // Pick up 4 for a test... $assessmentItemRef = $assessmentItemRefs['Hotspot_278940407'];