Support for parent/children motives

This commit is contained in:
2025-09-30 13:12:06 +00:00
parent 0eff1d2e79
commit e57d1ac696
25 changed files with 724 additions and 136 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TicketBundle\Tests\Entity;
use Chill\TicketBundle\Entity\Motive;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @covers \Chill\TicketBundle\Entity\Motive::getWithDescendants
*/
final class MotiveTest extends TestCase
{
public function testGetDescendantsOnLeafReturnsSelfOnly(): void
{
$leaf = new Motive();
$leaf->setLabel(['fr' => 'Feuille']);
$collection = $leaf->getDescendants();
self::assertCount(1, $collection);
self::assertSame($leaf, $collection->first());
self::assertContains($leaf, $collection->toArray());
}
public function testGetWithDescendantsReturnsSelfAndAllDescendants(): void
{
$parent = new Motive();
$parent->setLabel(['fr' => 'Parent']);
$childA = new Motive();
$childA->setLabel(['fr' => 'Enfant A']);
$childA->setParent($parent);
$childB = new Motive();
$childB->setLabel(['fr' => 'Enfant B']);
$childB->setParent($parent);
$grandChildA1 = new Motive();
$grandChildA1->setLabel(['fr' => 'Petit-enfant A1']);
$grandChildA1->setParent($childA);
$descendants = $parent->getDescendants();
$asArray = $descendants->toArray();
// It should contain the parent itself, both children and the grand child
self::assertCount(4, $descendants, 'Expected parent + 2 children + 1 grandchild');
self::assertContains($parent, $asArray);
self::assertContains($childA, $asArray);
self::assertContains($childB, $asArray);
self::assertContains($grandChildA1, $asArray);
}
}