2021-11-30 13:54:58 +01:00

142 lines
3.5 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\Household\Household;
use DateInterval;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use function array_pop;
use function shuffle;
/**
* @internal
* @coversNothing
*/
final class HouseholdControllerTest extends WebTestCase
{
use PrepareClientTrait;
private ?KernelBrowser $client = null;
protected function setUp()
{
$this->client = $this->getClientAuthenticated();
}
public function generateValidHouseholdIds()
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$ids = $em->createQuery(
'SELECT DISTINCT h.id FROM ' . Household::class . ' h ' .
'JOIN h.members m ' .
'JOIN m.person p ' .
'JOIN p.center c ' .
'WHERE c.name = :center'
)
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
shuffle($ids);
yield [array_pop($ids)['id']];
yield [array_pop($ids)['id']];
yield [array_pop($ids)['id']];
}
/**
* @dataProvider generateValidHouseholdIds
*
* @param mixed $householdId
*/
public function testAddresses($householdId)
{
$this->client->request(
Request::METHOD_GET,
"/fr/person/household/{$householdId}/addresses"
);
$this->assertResponseIsSuccessful();
}
/**
* @dataProvider generateValidHouseholdIds
*
* @param mixed $householdId
*/
public function testAddressMove($householdId)
{
$this->client->request(
Request::METHOD_GET,
"/fr/person/household/{$householdId}/address/move"
);
$this->assertResponseIsSuccessful();
// ici, il faudrait tester la requête POST
}
/**
* @dataProvider generateValidHouseholdIds
*
* @param mixed $householdId
*/
public function testEditMetadata($householdId)
{
$crawler = $this->client->request(
Request::METHOD_GET,
"/fr/person/household/{$householdId}/summary",
[
'edit' => true,
]
);
$this->assertResponseIsSuccessful();
$form = $crawler->filter('#form_household_comment_confirm')
->form();
$form['household[commentMembers][comment]'] = 'This is a text **generated** by automatic tests';
$form['household[waitingForBirth]']->tick();
$form['household[waitingForBirthDate]'] = (new DateTime('today'))
->add(new DateInterval('P1M'))->format('Y-m-d');
$this->client->submit($form);
$this->assertResponseRedirects("/fr/person/household/{$householdId}/summary");
}
/**
* @dataProvider generateValidHouseholdIds
*
* @param mixed $householdId
*/
public function testSummary($householdId)
{
$this->client->request(
Request::METHOD_GET,
"/fr/person/household/{$householdId}/summary"
);
$this->assertResponseIsSuccessful();
}
}