mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Tests\Entity\SocialWork;
|
|
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SocialIssueTest extends TestCase
|
|
{
|
|
public function testIsDescendantOf()
|
|
{
|
|
$parent = new SocialIssue();
|
|
$child = (new SocialIssue())->setParent($parent);
|
|
$grandChild = (new SocialIssue())->setParent($child);
|
|
$grandGrandChild = (new SocialIssue())->setParent($grandChild);
|
|
$unrelated = new SocialIssue();
|
|
|
|
$this->assertTrue($grandGrandChild->isDescendantOf($parent));
|
|
$this->assertTrue($grandGrandChild->isDescendantOf($grandChild));
|
|
$this->assertTrue($grandGrandChild->isDescendantOf($child));
|
|
$this->assertFalse($grandGrandChild->isDescendantOf($unrelated));
|
|
|
|
$this->assertTrue($grandChild->isDescendantOf($parent));
|
|
$this->assertTrue($grandChild->isDescendantOf($child));
|
|
$this->assertFalse($grandChild->isDescendantOf($unrelated));
|
|
$this->assertFalse($grandChild->isDescendantOf($grandChild));
|
|
|
|
$this->assertFalse($unrelated->isDescendantOf($parent));
|
|
|
|
$this->assertFalse($child->isDescendantOf($grandChild));
|
|
}
|
|
|
|
public function testFindSocialIssuesAncestors()
|
|
{
|
|
$socialIssues = new ArrayCollection([
|
|
$parent = new SocialIssue(),
|
|
$child = (new SocialIssue())->setParent($parent),
|
|
$grandChild = (new SocialIssue())->setParent($child),
|
|
$grandGrandChild = (new SocialIssue())->setParent($grandChild),
|
|
$unrelated = new SocialIssue(),
|
|
]);
|
|
|
|
$ancestors = SocialIssue::findAncestorSocialIssues($socialIssues);
|
|
|
|
$this->assertCount(3, $ancestors);
|
|
$this->assertContains($parent, $ancestors);
|
|
$this->assertContains($child, $ancestors);
|
|
$this->assertContains($grandChild, $ancestors);
|
|
}
|
|
}
|