From 88c8a018adc2d014af3ed41ae0c9730ad5282d6e Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 8 Aug 2026 22:22:55 +0300 Subject: [PATCH] test ordered element queries --- .../Element/EloquentElementRepositoryTest.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/backend/tests/Feature/Element/EloquentElementRepositoryTest.php b/backend/tests/Feature/Element/EloquentElementRepositoryTest.php index c339903..737403a 100644 --- a/backend/tests/Feature/Element/EloquentElementRepositoryTest.php +++ b/backend/tests/Feature/Element/EloquentElementRepositoryTest.php @@ -97,6 +97,65 @@ class EloquentElementRepositoryTest extends TestCase )); } + public function testItListsOrderedElementsWithinTheirTreeScope(): void + { + $bible = $this->createSet('Bible'); + $course = $this->createSet('Course'); + $repository = app(ElementRepository::class); + $genesisBook = $repository->create(new CreateElementDto( + set: $bible, + name: 'Genesis', + kind: 'book', + parentElement: null, + )); + $exodusBook = $repository->create(new CreateElementDto( + set: $bible, + name: 'Exodus', + kind: 'book', + parentElement: null, + )); + $repository->create(new CreateElementDto( + set: $course, + name: 'Module 1', + kind: 'module', + parentElement: null, + )); + $repository->create(new CreateElementDto( + set: $bible, + name: 'Genesis', + kind: 'portion', + parentElement: $genesisBook, + )); + $repository->create(new CreateElementDto( + set: $bible, + name: 'Noah', + kind: 'portion', + parentElement: $genesisBook, + )); + $repository->create(new CreateElementDto( + set: $bible, + name: 'Shemot', + kind: 'portion', + parentElement: $exodusBook, + )); + + $topLevelElements = $repository->findTopLevelBySet($bible); + $childElements = $repository->findByParentElement($genesisBook); + + $this->assertSame( + ['Genesis', 'Exodus'], + array_map(function ($element): string { + return $element->getName(); + }, $topLevelElements), + ); + $this->assertSame( + ['Genesis', 'Noah'], + array_map(function ($element): string { + return $element->getName(); + }, $childElements), + ); + } + private function createSet(string $name): Set { $creator = app(UserRepository::class)->create(new CreateUserDto(