mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
122 lines
3.7 KiB
PHP
122 lines
3.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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\Household;
|
|
|
|
use Chill\PersonBundle\Entity\Household\Household;
|
|
use Chill\PersonBundle\Entity\Household\Position;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\Household\MembersEditorFactory;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
class MembersEditorTest extends TestCase
|
|
{
|
|
private MembersEditorFactory $factory;
|
|
|
|
protected function setUp()
|
|
{
|
|
$validator = $this->createMock(ValidatorInterface::class);
|
|
|
|
$this->factory = new MembersEditorFactory($validator);
|
|
}
|
|
|
|
public function testMovePersonWithoutSharedHousehold()
|
|
{
|
|
$person = new Person();
|
|
$position = (new Position())
|
|
->setShareHousehold(false);
|
|
$household1 = new Household();
|
|
$household2 = new Household();
|
|
$editor = $this->factory->createEditor($household1);
|
|
|
|
$editor->addMovement(
|
|
DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
|
$person,
|
|
$position
|
|
);
|
|
|
|
$persistables = $editor->getPersistable();
|
|
$this->assertEquals(1, count($persistables));
|
|
|
|
$membership1 = $person->getHouseholdParticipations()->first();
|
|
$this->assertSame($household1, $membership1->getHousehold());
|
|
$this->assertNull($membership1->getEndDate());
|
|
|
|
// move to another household
|
|
$date = DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
|
$editor = $this->factory->createEditor($household2);
|
|
$editor->addMovement(
|
|
$date,
|
|
$person,
|
|
$position
|
|
);
|
|
|
|
$persistables = $editor->getPersistable();
|
|
$this->assertEquals(1, count($persistables));
|
|
|
|
$membership2 = $person->getHouseholdParticipations()->last();
|
|
$this->assertNull($membership2->getEndDate());
|
|
$this->assertSame($household2, $membership2->getHousehold());
|
|
$this->assertNull(
|
|
$membership1->getEndDate(),
|
|
'assert that the membership1 is not closed'
|
|
);
|
|
}
|
|
|
|
public function testMovePersonWithSharedHousehold()
|
|
{
|
|
$person = new Person();
|
|
$position = (new Position())
|
|
->setShareHousehold(true);
|
|
$household1 = new Household();
|
|
$household2 = new Household();
|
|
$editor = $this->factory->createEditor($household1);
|
|
|
|
$editor->addMovement(
|
|
DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
|
$person,
|
|
$position
|
|
);
|
|
|
|
$persistables = $editor->getPersistable();
|
|
$this->assertEquals(\count($persistables), 1);
|
|
|
|
$membership1 = $persistables[0];
|
|
$this->assertSame($household1, $membership1->getHousehold());
|
|
$this->assertNull($membership1->getEndDate());
|
|
|
|
// move to another household
|
|
$date = DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
|
$editor = $this->factory->createEditor($household2);
|
|
$editor->addMovement(
|
|
$date,
|
|
$person,
|
|
$position
|
|
);
|
|
|
|
$persistables = $editor->getPersistable();
|
|
$this->assertEquals(1, count($persistables));
|
|
|
|
$membership2 = $persistables[0];
|
|
$this->assertSame($household2, $membership2->getHousehold());
|
|
$this->assertNull($membership2->getEndDate());
|
|
$this->assertNotNull(
|
|
$membership1->getEndDate(),
|
|
'assert that the membership1 is closed'
|
|
);
|
|
$this->assertEquals($date, $membership1->getEndDate());
|
|
}
|
|
}
|