Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jul 27, 2016
2 parents 705af31 + 06aec9c commit b17a5bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/qtism/data/storage/xml/XmlCompactDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit b17a5bd

Please sign in to comment.