mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
142 lines
4.3 KiB
PHP
142 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Bundle\ChillPersonBundle\Tests\Controller;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\Entity\Household\Household;
|
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
|
use Chill\PersonBundle\Entity\Household\Position;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
|
class HouseholdMemberControllerTest extends WebTestCase
|
|
{
|
|
use PrepareClientTrait;
|
|
|
|
/**
|
|
* @dataProvider provideValidDataMove
|
|
*/
|
|
public function testMoveMember($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',
|
|
'id' => $householdId
|
|
]
|
|
],
|
|
true)
|
|
);
|
|
|
|
$this->assertEquals(Response::HTTP_OK,
|
|
$client->getResponse()->getStatusCode()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideValidDataEditMember
|
|
*/
|
|
public function testEditMember($memberId)
|
|
{
|
|
$client = $this->getClientAuthenticated();
|
|
|
|
$crawler = $client->request(
|
|
Request::METHOD_GET,
|
|
"/fr/person/household/member/{$memberId}/edit"
|
|
);
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$form = $crawler->selectButton('Enregistrer')
|
|
->form();
|
|
$form['household_member[endDate]'] = (new \DateTime('tomorrow'))
|
|
->format('d-m-Y');
|
|
|
|
$crawler = $client->submit($form);
|
|
|
|
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
|
}
|
|
|
|
public function provideValidDataMove(): \Iterator
|
|
{
|
|
self::bootKernel();
|
|
$em = self::$container->get(EntityManagerInterface::class);
|
|
|
|
$personIds = $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
|
"JOIN p.center c WHERE c.name = :center")
|
|
->setParameter('center', "Center A")
|
|
->setMaxResults(100)
|
|
->getScalarResult()
|
|
;
|
|
\shuffle($personIds);
|
|
|
|
$household = new Household();
|
|
$em->persist($household);
|
|
$em->flush();
|
|
|
|
$positions = $em->createQuery("SELECT pos.id FROM ".Position::class." pos ".
|
|
"WHERE pos.shareHouseHold = TRUE")
|
|
->getResult()
|
|
;
|
|
|
|
yield [
|
|
\array_pop($personIds)['id'],
|
|
$household->getId(),
|
|
$positions[\random_int(0, count($positions) - 1)]['id'],
|
|
new \DateTimeImmutable('today')
|
|
];
|
|
}
|
|
|
|
public function provideValidDataEditMember(): \Iterator
|
|
{
|
|
self::bootKernel();
|
|
$em = self::$container->get(EntityManagerInterface::class);
|
|
|
|
$membershipIds = $em->createQuery("SELECT m.id FROM ".HouseholdMember::class." m ".
|
|
"JOIN m.person p ".
|
|
"JOIN p.center c ".
|
|
"WHERE c.name = :center AND m.endDate IS NULL")
|
|
->setParameter('center', 'Center A')
|
|
->getScalarResult()
|
|
;
|
|
|
|
\shuffle($membershipIds);
|
|
|
|
yield [ \array_pop($membershipIds)['id'] ];
|
|
}
|
|
}
|