Skip to content

Commit

Permalink
Strict fixes for e_tree_model::flattenTree()
Browse files Browse the repository at this point in the history
- FIX: Null check during child recursion of e_tree_model::flattenTree()
- FIX: TreeModelTest::testTreeParentsAreAssignedCorrectly() apparently never worked until now because the wrong index was used
  • Loading branch information
Deltik committed Jan 18, 2020
1 parent d6eafdc commit a1560b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion e107_handlers/model_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ protected static function flattenTree($tree, $sort_field = null, $sort_order = 1

foreach($tree as $item)
{
$children = $item['_children'];
$children = isset($item['_children']) ? $item['_children'] : null;
unset($item['_children']);
$item['_depth'] = $depth;
if($depth > 0)
Expand Down
10 changes: 5 additions & 5 deletions e107_tests/tests/unit/TreeModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public function testTreeParentsAreAssignedCorrectly()
{
$key = $this->sample_key;
$parent_key = $this->sample_parent_key;
$l0_id = $this->tree[1][$key];
$l1_id = $this->tree[1]['_children'][0][$key];
$l1_parent = $this->tree[1]['_children'][0][$parent_key];
$l2_id = $this->tree[1]['_children'][0]['_children'][0][$key];
$l2_parent = $this->tree[1]['_children'][0]['_children'][0][$parent_key];
$l0_id = $this->tree[0][$key];
$l1_id = $this->tree[0]['_children'][0][$key];
$l1_parent = $this->tree[0]['_children'][0][$parent_key];
$l2_id = $this->tree[0]['_children'][0]['_children'][0][$key];
$l2_parent = $this->tree[0]['_children'][0]['_children'][0][$parent_key];

$this->assertEquals($l0_id, $l1_parent);
$this->assertEquals($l1_id, $l2_parent);
Expand Down

0 comments on commit a1560b1

Please sign in to comment.