magento/magento2 — pull request #65 by amenk (2012-08-15 08:36:03+00:00)
Title: Implemented toplogical sorting for totals

The sorting of totals is incorrect with causes lots of problem when new modules that define own totals are added.

For details see http://stackoverflow.com/a/9258826/288568

This patch implementes a toplogic sort to fix this problem.

For a unit test I suggest the following code ($result is the result of the _getSortedCollectorCodes array for any input)

$this->assertEquals(count($configArray), count($result));

// check if all conditions where matched
// as we do have only a partial order, it does not make sense
// to check the definite result
foreach($configArray as $code=>$data) {
$_code = $data['_code'];
$codeIndex = array_search($_code, $result);
if (!isset($configArray[$_code])) continue;
foreach($data['before'] as $beforeCode) {
if (!isset($configArray[$beforeCode])) continue;
$bIndex = array_search($beforeCode, $result);
$this->assertTrue($codeIndex < $bIndex, "Condition not fullfilled: $codeIndex < $bIndex");
}
foreach($data['after'] as $afterCode) {
if (!isset($configArray[$afterCode])) continue;
$aIndex = array_search($afterCode, $result);
$this->assertTrue($codeIndex > $aIndex, "Condition not fullfilled: $codeIndex > $aIndex");
}
}