mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-03 18:58:24 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			117 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Chill\PersonBundle\Tests\Controller;
 | 
						|
 | 
						|
use Chill\PersonBundle\Entity\Household\Household;
 | 
						|
use Doctrine\ORM\EntityManagerInterface;
 | 
						|
use Symfony\Component\HttpFoundation\Request;
 | 
						|
use Chill\MainBundle\Test\PrepareClientTrait;
 | 
						|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 | 
						|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
 | 
						|
 | 
						|
class HouseholdControllerTest extends WebTestCase
 | 
						|
{
 | 
						|
    use PrepareClientTrait;
 | 
						|
 | 
						|
    private ?KernelBrowser $client = null;
 | 
						|
 | 
						|
    protected function setUp()
 | 
						|
    {
 | 
						|
        $this->client = $this->getClientAuthenticated();
 | 
						|
    } 
 | 
						|
 | 
						|
    /**
 | 
						|
     * @dataProvider generateValidHouseholdIds
 | 
						|
     */
 | 
						|
    public function testSummary($householdId)
 | 
						|
    {
 | 
						|
        $this->client->request(
 | 
						|
            Request::METHOD_GET,
 | 
						|
            "/fr/person/household/{$householdId}/summary"
 | 
						|
        );
 | 
						|
 | 
						|
        $this->assertResponseIsSuccessful();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @dataProvider generateValidHouseholdIds
 | 
						|
     */
 | 
						|
    public function testEditMetadata($householdId)
 | 
						|
    {
 | 
						|
 | 
						|
        $crawler = $this->client->request(
 | 
						|
            Request::METHOD_GET,
 | 
						|
            "/fr/person/household/{$householdId}/summary",
 | 
						|
            [
 | 
						|
                'edit' => true
 | 
						|
            ]
 | 
						|
        );
 | 
						|
 | 
						|
        $this->assertResponseIsSuccessful();
 | 
						|
 | 
						|
        $form = $crawler->selectButton('Enregistrer')
 | 
						|
            ->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
 | 
						|
     */
 | 
						|
    public function testAddresses($householdId)
 | 
						|
    {
 | 
						|
        $this->client->request(
 | 
						|
            Request::METHOD_GET,
 | 
						|
            "/fr/person/household/{$householdId}/addresses"
 | 
						|
        );
 | 
						|
 | 
						|
        $this->assertResponseIsSuccessful();
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @dataProvider generateValidHouseholdIds
 | 
						|
     */
 | 
						|
    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
 | 
						|
    }
 | 
						|
 | 
						|
    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'] ]; 
 | 
						|
    }
 | 
						|
}
 |