mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch 'features/household-editor' into features/household-validation
This commit is contained in:
@@ -67,6 +67,116 @@ class HouseholdMemberControllerTest extends WebTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidDataMove
|
||||
*/
|
||||
public function testMoveMemberToNewHousehold($personId, $householdId, $positionId, \DateTimeInterface $date)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(
|
||||
Request::METHOD_POST,
|
||||
'/api/1.0/person/household/members/move.json',
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server
|
||||
\json_encode(
|
||||
[
|
||||
'concerned' =>
|
||||
[
|
||||
[
|
||||
'person' =>
|
||||
[
|
||||
'type' => 'person',
|
||||
'id' => $personId
|
||||
],
|
||||
'start_date' =>
|
||||
[
|
||||
'datetime' => $date->format(\DateTimeInterface::RFC3339)
|
||||
],
|
||||
'position' =>
|
||||
[
|
||||
'type' => 'household_position',
|
||||
'id' => $positionId
|
||||
],
|
||||
'holder' => false,
|
||||
'comment' => "Introduced by automated test",
|
||||
],
|
||||
],
|
||||
'destination' =>
|
||||
[
|
||||
'type' => 'household',
|
||||
]
|
||||
],
|
||||
true)
|
||||
);
|
||||
|
||||
$this->assertEquals(Response::HTTP_OK,
|
||||
$client->getResponse()->getStatusCode()
|
||||
);
|
||||
|
||||
$data = \json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($data);
|
||||
$this->assertArrayHasKey('members', $data);
|
||||
$this->assertIsArray($data['members']);
|
||||
$this->assertEquals(1, count($data['members']),
|
||||
"assert new household count one member");
|
||||
$this->assertArrayHasKey('person', $data['members'][0]);
|
||||
$this->assertArrayHasKey('id', $data['members'][0]['person']);
|
||||
$this->assertEquals($personId, $data['members'][0]['person']['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidDataMove
|
||||
*/
|
||||
public function testLeaveWithoutHousehold($personId, $householdId, $positionId, \DateTimeInterface $date)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(
|
||||
Request::METHOD_POST,
|
||||
'/api/1.0/person/household/members/move.json',
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server
|
||||
\json_encode(
|
||||
[
|
||||
'concerned' =>
|
||||
[
|
||||
[
|
||||
'person' =>
|
||||
[
|
||||
'type' => 'person',
|
||||
'id' => $personId
|
||||
],
|
||||
'start_date' =>
|
||||
[
|
||||
'datetime' => $date->format(\DateTimeInterface::RFC3339)
|
||||
],
|
||||
'position' =>
|
||||
[
|
||||
'type' => 'household_position',
|
||||
'id' => $positionId
|
||||
],
|
||||
'holder' => false,
|
||||
'comment' => "Introduced by automated test",
|
||||
],
|
||||
],
|
||||
'destination' => null
|
||||
],
|
||||
true)
|
||||
);
|
||||
|
||||
$this->assertEquals(Response::HTTP_OK,
|
||||
$client->getResponse()->getStatusCode()
|
||||
);
|
||||
|
||||
$data = \json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals(null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidDataEditMember
|
||||
*/
|
||||
@@ -97,7 +207,13 @@ class HouseholdMemberControllerTest extends WebTestCase
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$personIds = $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
||||
"JOIN p.center c WHERE c.name = :center")
|
||||
"JOIN p.center c ".
|
||||
"JOIN p.householdParticipations hp ".
|
||||
"WHERE ".
|
||||
"c.name = :center ".
|
||||
"AND hp.startDate < CURRENT_DATE() ".
|
||||
"AND hp.endDate IS NULL "
|
||||
)
|
||||
->setParameter('center', "Center A")
|
||||
->setMaxResults(100)
|
||||
->getScalarResult()
|
||||
|
@@ -22,6 +22,9 @@
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
@@ -205,4 +208,39 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
$this::assertEquals($address3, $p->getLastAddress($addressDate3));
|
||||
}
|
||||
|
||||
public function testIsSharingHousehold()
|
||||
{
|
||||
$person = new Person();
|
||||
$household = new Household();
|
||||
$positionShare = (new Position())
|
||||
->setShareHousehold(true);
|
||||
$positionNotShare = (new Position())
|
||||
->setShareHousehold(false);
|
||||
|
||||
$membership1 = (new HouseholdMember())
|
||||
->setStartDate(new \DateTimeImmutable('10 years ago'))
|
||||
->setEndDate(new \DateTimeImmutable('5 years ago'))
|
||||
->setPerson($person)
|
||||
->setPosition($positionShare)
|
||||
;
|
||||
$household->addMember($membership1);
|
||||
|
||||
$membership2 = (new HouseholdMember())
|
||||
->setStartDate(new \DateTimeImmutable('4 years ago'))
|
||||
->setEndDate(new \DateTimeImmutable('2 years ago'))
|
||||
->setPerson($person)
|
||||
->setPosition($positionNotShare)
|
||||
;
|
||||
$household->addMember($membership2);
|
||||
|
||||
$this->assertEquals(2, $person->getHouseholdParticipations()
|
||||
->count());
|
||||
|
||||
$this->assertFalse($person->isSharingHousehold());
|
||||
$this->assertTrue($person->isSharingHousehold(
|
||||
new \DateTimeImmutable('6 years ago')));
|
||||
$this->assertFalse($person->isSharingHousehold(
|
||||
new \DateTimeImmutable('3 years ago')));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user