test ordered element queries
This commit is contained in:
parent
588a3ecb40
commit
88c8a018ad
1 changed files with 59 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue