test element child list
This commit is contained in:
parent
d950fe55dd
commit
aa746fe3f0
4 changed files with 137 additions and 15 deletions
|
|
@ -26,17 +26,76 @@ class GetElementTest extends TestCase
|
|||
|
||||
public function testReturnsElementWhenFound(): void
|
||||
{
|
||||
$element = $this->createElement('Baderech HaAvodah');
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
null,
|
||||
);
|
||||
|
||||
$foundElement = $this->getElement->execute(new GetElementRequest(
|
||||
$result = $this->getElement->execute(new GetElementRequest(
|
||||
id: $element->getId(),
|
||||
));
|
||||
$foundElement = $result->getElement();
|
||||
|
||||
$this->assertInstanceOf(Element::class, $foundElement);
|
||||
$this->assertSame($element->getId(), $foundElement->getId());
|
||||
$this->assertSame('Baderech HaAvodah', $foundElement->getTitle());
|
||||
}
|
||||
|
||||
public function testReturnsDirectChildElements(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$parentElement = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
null,
|
||||
);
|
||||
$firstChildElement = $this->createElement(
|
||||
$set,
|
||||
'Avodah Foundations',
|
||||
$parentElement,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
$set,
|
||||
'Daily Practice',
|
||||
$parentElement,
|
||||
);
|
||||
$this->createElement(
|
||||
$set,
|
||||
'Nested Practice',
|
||||
$firstChildElement,
|
||||
);
|
||||
$otherSet = $this->createSet(2, 'Daily Learning');
|
||||
$otherParentElement = $this->createElement(
|
||||
$otherSet,
|
||||
'Other Parent',
|
||||
null,
|
||||
);
|
||||
$this->createElement(
|
||||
$otherSet,
|
||||
'Other Child',
|
||||
$otherParentElement,
|
||||
);
|
||||
|
||||
$result = $this->getElement->execute(new GetElementRequest(
|
||||
id: $parentElement->getId(),
|
||||
));
|
||||
$childElements = $result->getChildElements();
|
||||
|
||||
$this->assertCount(2, $childElements);
|
||||
$this->assertSame(
|
||||
$firstChildElement->getId(),
|
||||
$childElements[0]->getId(),
|
||||
);
|
||||
$this->assertSame('Avodah Foundations', $childElements[0]->getTitle());
|
||||
$this->assertSame(
|
||||
$secondChildElement->getId(),
|
||||
$childElements[1]->getId(),
|
||||
);
|
||||
$this->assertSame('Daily Practice', $childElements[1]->getTitle());
|
||||
}
|
||||
|
||||
public function testThrowsWhenIdMissing(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
|
|
@ -53,19 +112,25 @@ class GetElementTest extends TestCase
|
|||
$this->getElement->execute(new GetElementRequest(id: 999));
|
||||
}
|
||||
|
||||
private function createElement(string $title): Element
|
||||
private function createSet(int $id, string $name): DomainSet
|
||||
{
|
||||
$set = new DomainSet(
|
||||
id: 1,
|
||||
name: 'Baderech',
|
||||
description: 'Baderech description',
|
||||
return new DomainSet(
|
||||
id: $id,
|
||||
name: $name,
|
||||
description: "$name description",
|
||||
iconImageUrl: '/assets/baderech-icon.png',
|
||||
);
|
||||
}
|
||||
|
||||
private function createElement(
|
||||
DomainSet $set,
|
||||
string $title,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
return $this->elementRepo->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: $title,
|
||||
parentElement: null,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue