Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 2, 2016
2 parents f73c989 + f00e54e commit 770013e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/qtism/data/QtiIdentifiableCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -29,8 +29,9 @@
use \SplSubject;

/**
* This extension of QtiComponentCollection can retrieve items it contains
* by identifier.
* This extension of QtiComponentCollection can retrieve items it contains by QTI identifier.
*
* This collection implementation aims at storing QTI components having an "identifier" attribute.
*
* @author Jérôme Bogaerts <[email protected]>
*
Expand Down Expand Up @@ -177,7 +178,7 @@ public function replace($object, $replacement)

if (($search = array_search($object, $this->dataPlaceHolder, true)) !== false) {

$objectKey = $object->getIdentifier();
$objectKey = $search;
$replacementKey = $replacement->getIdentifier();

if ($objectKey === $replacementKey) {
Expand Down Expand Up @@ -215,13 +216,7 @@ public function update(SplSubject $subject)
{
// -- case 1 (QtiIdentifiable)
// If it is a QtiIdentifiable, it has changed its identifier.
$data = &$this->getDataPlaceHolder();
foreach (array_keys($data) as $k) {
if ($data[$k] === $subject && $k !== $subject->getIdentifier()) {
unset($data[$k]);
$this->offsetSet(null, $subject);
}
}
$this->replace($subject, $subject);
}

public function __clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,25 @@ public function testEventsUnset()
$weight1->setIdentifier('weight2');
$this->assertFalse($weight1 === $weights['weight2']);
}

public function testRenamingOrder()
{
$weight1 = new Weight('weight1', 1.0);
$weight2 = new Weight('weight2', 1.2);
$weight3 = new Weight('weight3', 1.2);
$weights = new WeightCollection(array($weight1, $weight2, $weight3));

// If weight2 gets a new identifier "weight4", it should still be in second position in the collection.
$this->assertSame(
array('weight1', 'weight2', 'weight3'),
$weights->getKeys()
);

$weight2->setIdentifier('weight4');

$this->assertSame(
array('weight1', 'weight4', 'weight3'),
$weights->getKeys()
);
}
}

0 comments on commit 770013e

Please sign in to comment.