Skip to content

Commit

Permalink
staudenmeir#259: Added initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernathanreed committed Sep 6, 2024
1 parent 75dac50 commit 5c0ba5c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Tree/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,33 @@ public function testToTreeWithEmptyCollection()

$this->assertEmpty($tree);
}

public function testLoadTreePathRelations()
{
$limit = User::count();

$loaded = 0;

User::retrieved(function () use (&$count) {
$count++;
});

$tree = User::query()
->tree()
->get()
->loadTreePathRelations()
->each(fn ($s) => $s->setAppends(['slug_path', 'reverse_slug_path']))
->toTree();

$this->assertLessThanOrEqual($limit, $loaded);

$this->assertEquals('user-1', $tree[0]->slug_path);
$this->assertEquals('user-11', $tree[1]->slug_path);
$this->assertEquals('user-1 > user-2', $tree[0]->children[0]->slug_path);
$this->assertEquals('user-1 > user-3', $tree[0]->children[1]->slug_path);
$this->assertEquals('user-1 > user-4', $tree[0]->children[2]->slug_path);
$this->assertEquals('user-1 > user-2 > user-5', $tree[0]->children[0]->children[0]->slug_path);
$this->assertEquals('user-1 > user-2 > user-5 > user-8', $tree[0]->children[0]->children[0]->children[0]->slug_path);
$this->assertEquals('user-11 > user-12', $tree[1]->children[0]->slug_path);
}
}

0 comments on commit 5c0ba5c

Please sign in to comment.