review: fix stuffs on socialAction and socialIssue filters:

* filters call static entity method
* add renderString option to manage add_children
* add tests on new entity method getDescendantsWithThisFor..()
* rename function in repository
* rename 'Select2..' classes by 'Pick..' and replace all occurences
This commit is contained in:
2022-10-17 09:52:29 +02:00
parent 71f989f00e
commit 32ddc5465c
22 changed files with 244 additions and 151 deletions

View File

@@ -0,0 +1,53 @@
<?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\PersonBundle\Tests\Entity\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
final class SocialActionTest extends TestCase
{
public function testGetDescendantsWithThisForActions()
{
$parentA = new SocialAction();
$childA = (new SocialAction())->setParent($parentA);
$grandChildA = (new SocialAction())->setParent($childA);
$grandGrandChildA = (new SocialAction())->setParent($grandChildA);
$unrelatedA = new SocialAction();
$parentB = new SocialAction();
$childB = (new SocialAction())->setParent($parentB);
$grandChildB = (new SocialAction())->setParent($childB);
$grandGrandChildB = (new SocialAction())->setParent($grandChildB);
$unrelatedB = new SocialAction();
$actual = SocialAction::getDescendantsWithThisForActions([$parentA, $parentB]);
$this->assertContains($parentA, $actual);
$this->assertContains($parentB, $actual);
$this->assertContains($childA, $actual);
$this->assertContains($childB, $actual);
$this->assertContains($grandChildA, $actual);
$this->assertContains($grandChildB, $actual);
$this->assertContains($grandGrandChildA, $actual);
$this->assertContains($grandGrandChildB, $actual);
$this->assertCount(8, $actual);
$this->assertNotContains($unrelatedA, $actual);
$this->assertNotContains($unrelatedB, $actual);
}
}

View File

@@ -77,4 +77,33 @@ final class SocialIssueTest extends TestCase
$this->assertFalse($child->isDescendantOf($grandChild));
}
public function testGetDescendantsWithThisForIssues()
{
$parentA = new SocialIssue();
$childA = (new SocialIssue())->setParent($parentA);
$grandChildA = (new SocialIssue())->setParent($childA);
$grandGrandChildA = (new SocialIssue())->setParent($grandChildA);
$unrelatedA = new SocialIssue();
$parentB = new SocialIssue();
$childB = (new SocialIssue())->setParent($parentB);
$grandChildB = (new SocialIssue())->setParent($childB);
$grandGrandChildB = (new SocialIssue())->setParent($grandChildB);
$unrelatedB = new SocialIssue();
$actual = SocialIssue::getDescendantsWithThisForIssues([$parentA, $parentB]);
$this->assertContains($parentA, $actual);
$this->assertContains($parentB, $actual);
$this->assertContains($childA, $actual);
$this->assertContains($childB, $actual);
$this->assertContains($grandChildA, $actual);
$this->assertContains($grandChildB, $actual);
$this->assertContains($grandGrandChildA, $actual);
$this->assertContains($grandGrandChildB, $actual);
$this->assertCount(8, $actual);
$this->assertNotContains($unrelatedA, $actual);
$this->assertNotContains($unrelatedB, $actual);
}
}