Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ORM/Hierarchy/MarkedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ protected function getSubtree($node, $depth = 0)
'expanded' => $expanded,
'opened' => $opened,
'depth' => $depth,
'level' => $depth,
'count' => $count, // Count of DB children
'limited' => $limited, // Flag whether 'items' has been limited
'children' => [], // Children to return in this request
Expand Down
42 changes: 42 additions & 0 deletions tests/php/ORM/MarkedSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,32 @@ public function testGetChildrenAsULNodeDeletedOnStage()
$this->assertEquals('unexpanded jstree-closed closed', $nodeClass, 'obj2 should have children in the sitetree');
}

public function testGetChildrenAsArrayIncludesLevel(): void
{
$obj3 = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3');
$obj3a = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3a');
$obj3aa = $this->objFromFixture(HierarchyTest\TestObject::class, 'obj3aa');

$set = new MarkedSet(HierarchyTest\TestObject::singleton(), 'AllChildrenIncludingDeleted', 'numChildren');
$set->markPartialTree();
$set->markToExpose($obj3aa);

$tree = $set->getChildrenAsArray(function ($node) {
return [
'id' => $node->ID,
'title' => $node->Title,
];
});
$node3 = $this->findTreeNodeById($tree, $obj3->ID);
$node3a = $this->findTreeNodeById($tree, $obj3a->ID);
$node3aa = $this->findTreeNodeById($tree, $obj3aa->ID);

$this->assertSame(0, $tree['level']);
$this->assertSame(1, $node3['level']);
$this->assertSame(2, $node3a['level']);
$this->assertSame(3, $node3aa['level']);
}


/**
* @param string $html [description]
Expand Down Expand Up @@ -436,6 +462,22 @@ protected function getNodeClassFromTree($html, $node)
return '';
}

protected function findTreeNodeById(array $tree, int $id): array
{
if (($tree['id'] ?? null) === $id) {
return $tree;
}

foreach ($tree['children'] ?? [] as $child) {
$result = $this->findTreeNodeById($child, $id);
if ($result) {
return $result;
}
}

return [];
}

protected function assertHTMLSame($expected, $actual, $message = '')
{
// Trim each line, strip empty lines
Expand Down
Loading