From 5fd03158627e7946e7a64aa3a152383cd2ad42ac Mon Sep 17 00:00:00 2001 From: Benoit Galati Date: Fri, 15 Jun 2018 14:44:06 +0200 Subject: [PATCH] Speed up tests for CI - Store MySQL data in memory - Authenticate user without going to /login --- docker-compose.ci.yml | 6 +- docker-compose.yml | 2 + docker/dev/my.cnf | 2 + tests/Controller/ControllerTestTrait.php | 67 +++++++------------ .../EnMarche/AdherentControllerTest.php | 17 +++-- .../EnMarche/CitizenProjectControllerTest.php | 3 +- .../EnMarche/CommitteeControllerTest.php | 15 +++-- .../CommitteeManagerControllerTest.php | 39 +++++++---- .../EnMarche/CoordinatorControllerTest.php | 3 + .../EnMarche/EventControllerTest.php | 3 +- tests/TestHelperTrait.php | 7 ++ 11 files changed, 95 insertions(+), 69 deletions(-) create mode 100644 docker/dev/my.cnf diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index a0a99ac2313..7453a7501b6 100755 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -6,14 +6,14 @@ services: environment: - SYMFONY_ENV=test - APP_ENV=test - volumes: - - ./var/cache:/app/var/cache - - ./var/logs:/app/var/logs build: cache_from: - ${APP_DOCKER_IMAGE_NAME}:${APP_DOCKER_IMAGE_MD5} - ${APP_DOCKER_IMAGE_NAME}:dev + db: + tmpfs: /var/lib/mysql + selenium: ports: - 5900:5900 diff --git a/docker-compose.yml b/docker-compose.yml index 9ebae078c95..2176be0fc53 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,8 @@ services: db: image: mysql:5.7 + volumes: + - ./docker/dev/my.cnf:/etc/mysql/conf.d/my.cnf environment: MYSQL_ROOT_PASSWORD: root diff --git a/docker/dev/my.cnf b/docker/dev/my.cnf new file mode 100644 index 00000000000..6a6407009e7 --- /dev/null +++ b/docker/dev/my.cnf @@ -0,0 +1,2 @@ +# https://stackoverflow.com/questions/10386037/how-can-i-speed-up-my-phpunit-dbunit-test-suite-execution +innodb_flush_log_at_trx_commit = 2 diff --git a/tests/Controller/ControllerTestTrait.php b/tests/Controller/ControllerTestTrait.php index e232d3554ee..b96645c4274 100644 --- a/tests/Controller/ControllerTestTrait.php +++ b/tests/Controller/ControllerTestTrait.php @@ -2,17 +2,18 @@ namespace Tests\AppBundle\Controller; -use AppBundle\DataFixtures\ORM\LoadAdherentData; use AppBundle\Entity\Adherent; use AppBundle\Entity\EventCategory; use AppBundle\Entity\ReferentTag; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bundle\FrameworkBundle\Client; +use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Form; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\User\UserInterface; use Tests\AppBundle\TestHelperTrait; /** @@ -50,57 +51,42 @@ public function assertClientIsRedirectedTo(string $path, Client $client, bool $w ); } - public function logout(Client $client): Crawler + public function logout(Client $client): void { - $client->request(Request::METHOD_GET, '/deconnexion'); + $session = $client->getContainer()->get('session'); - return $client->followRedirect(); + $client->getCookieJar()->clear(); + $session->set('_security_main_context', null); + $session->save(); } - public function authenticateAsAdherent(Client $client, string $emailAddress, string $password = LoadAdherentData::DEFAULT_PASSWORD): Crawler + public function authenticateAsAdherent(Client $client, string $emailAddress): void { - $crawler = $client->request(Request::METHOD_GET, '/connexion'); - - $this->assertResponseStatusCode(Response::HTTP_OK, $client->getResponse()); - - $client->submit($crawler->selectButton('Connexion')->form([ - '_login_email' => $emailAddress, - '_login_password' => $password, - ])); - - $shouldBeRedirectedTo = 'http://'.$this->hosts['app'].'/evenements'; - - if ($shouldBeRedirectedTo !== $client->getResponse()->headers->get('location')) { - $this->fail( - 'Authentication as '.$emailAddress.' failed: check the credentials used in authenticateAsAdherent() '. - 'and ensure you are properly loading adherents fixtures.' - ); + if (!$user = $this->getAdherentRepository()->findOneBy(['emailAddress' => $emailAddress])) { + throw new \Exception(sprintf('Adherent %s not found', $emailAddress)); } - return $client->followRedirect(); + $this->authenticate($client, $user); } - public function authenticateAsAdmin(Client $client, string $emailAddress = 'admin@en-marche-dev.fr', string $password = 'admin'): Crawler + public function authenticateAsAdmin(Client $client, string $email = 'admin@en-marche-dev.fr'): void { - $crawler = $client->request(Request::METHOD_GET, '/admin/login'); - - $this->assertResponseStatusCode(Response::HTTP_OK, $client->getResponse()); + if (!$user = $this->getAdministratorRepository()->loadUserByUsername($email)) { + throw new \Exception(sprintf('Admin %s not found', $email)); + } - $client->submit($crawler->selectButton('Connexion')->form([ - '_login_email' => $emailAddress, - '_login_password' => $password, - ])); + $this->authenticate($client, $user); + } - $shouldBeRedirectedTo = 'http://'.$this->hosts['app'].'/admin/dashboard'; + private function authenticate(Client $client, UserInterface $user): void + { + $session = $client->getContainer()->get('session'); - if ($shouldBeRedirectedTo !== $client->getResponse()->headers->get('location')) { - $this->fail( - 'Authentication as '.$emailAddress.' failed: check the credentials used in authenticateAsAdmin() '. - 'and ensure you are properly loading adherents fixtures.' - ); - } + $token = new UsernamePasswordToken($user, null, 'main_context', $user->getRoles()); + $session->set('_security_main_context', serialize($token)); + $session->save(); - return $client->followRedirect(); + $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); } protected function getFirstPrefixForm(Form $form): ?string @@ -186,10 +172,9 @@ protected function init(array $fixtures = [], string $host = 'app') protected function kill() { - $this->loadFixtures([]); $this->client = null; + $this->container->get('doctrine')->getConnection()->close(); $this->container = null; - $this->manager->getConnection()->close(); $this->manager = null; $this->hosts = []; diff --git a/tests/Controller/EnMarche/AdherentControllerTest.php b/tests/Controller/EnMarche/AdherentControllerTest.php index ca934dba8ee..f64e47111ba 100644 --- a/tests/Controller/EnMarche/AdherentControllerTest.php +++ b/tests/Controller/EnMarche/AdherentControllerTest.php @@ -53,7 +53,8 @@ public function testMyEventsPageIsProtected(): void public function testAuthenticatedAdherentCanSeeHisUpcomingAndPastEvents(): void { - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/'); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); $crawler = $this->client->click($crawler->selectLink('Mes activités')->link()); @@ -358,6 +359,7 @@ public function testEditAdherentInterests(): void $this->assertClientIsRedirectedTo('/espace-adherent/mon-compte/centres-d-interet', $this->client); /* @var Adherent $adherent */ + $this->container->get('doctrine.orm.entity_manager')->clear(); $adherent = $this->getAdherentRepository()->findOneByEmail('carl999@example.fr'); $this->assertSame(array_values($chosenInterests), $adherent->getInterests()); @@ -619,7 +621,9 @@ public function testAnonymousUserCannotCreateCitizenProject(): void public function testAdherentCanCreateNewCitizenProject(): void { - $crawler = $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + + $crawler = $this->client->request(Request::METHOD_GET, '/'); $this->assertSame(3, $crawler->selectLink('Lancer mon projet')->count()); $this->client->request(Request::METHOD_GET, '/espace-adherent/creer-mon-projet-citoyen'); @@ -628,7 +632,8 @@ public function testAdherentCanCreateNewCitizenProject(): void public function testCitizenProjectAdministratorCannotCreateAnotherCitizenProject(): void { - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/'); $this->assertSame(0, $crawler->selectLink('Lancer mon projet')->count()); $this->client->request(Request::METHOD_GET, '/espace-adherent/creer-mon-projet-citoyen'); @@ -731,7 +736,8 @@ public function testCreateCitizenProjectSuccessful(): void */ public function testCommitteesAdherentsHostsAreNotAllowedToCreateNewCommittees(string $emailAddress): void { - $crawler = $this->authenticateAsAdherent($this->client, $emailAddress); + $this->authenticateAsAdherent($this->client, $emailAddress); + $crawler = $this->client->request(Request::METHOD_GET, '/'); $this->assertSame(0, $crawler->selectLink('Créer un comité')->count()); // Try to cheat the system with a direct URL access. @@ -758,7 +764,8 @@ public function provideCommitteesHostsAdherentsCredentials(): array */ public function testRegularAdherentCanCreateOneNewCommittee(string $emaiLAddress, string $phone): void { - $crawler = $this->authenticateAsAdherent($this->client, $emaiLAddress); + $this->authenticateAsAdherent($this->client, $emaiLAddress); + $crawler = $this->client->request(Request::METHOD_GET, '/'); $crawler = $this->client->click($crawler->selectLink('Créer un comité')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); diff --git a/tests/Controller/EnMarche/CitizenProjectControllerTest.php b/tests/Controller/EnMarche/CitizenProjectControllerTest.php index 85af931f70c..e4c31846553 100644 --- a/tests/Controller/EnMarche/CitizenProjectControllerTest.php +++ b/tests/Controller/EnMarche/CitizenProjectControllerTest.php @@ -287,7 +287,8 @@ public function testCommitteeSupportCitizenProject() public function testCitizenProjectContactActors() { // Authenticate as the administrator (host) - $crawler = $this->authenticateAsAdherent($this->client, 'lolodie.dutemps@hotnix.tld'); + $this->authenticateAsAdherent($this->client, 'lolodie.dutemps@hotnix.tld'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche - Projet citoyen')->link()); $crawler = $this->client->click($crawler->selectLink('Voir')->link()); diff --git a/tests/Controller/EnMarche/CommitteeControllerTest.php b/tests/Controller/EnMarche/CommitteeControllerTest.php index 7c0c7a27c17..1ecaca8e407 100644 --- a/tests/Controller/EnMarche/CommitteeControllerTest.php +++ b/tests/Controller/EnMarche/CommitteeControllerTest.php @@ -38,7 +38,8 @@ public function testRedirectionComiteFromOldUrl() public function testAuthenticatedCommitteeSupervisorCannotUnfollowCommittee() { // Login as supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -53,7 +54,8 @@ public function testAuthenticatedCommitteeSupervisorCannotUnfollowCommittee() public function testAuthenticatedCommitteeHostCanUnfollowCommittee() { // Login as host - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -80,7 +82,8 @@ public function testAuthenticatedCommitteeHostCanUnfollowCommittee() $this->client->getCookieJar()->clear(); // Login again as supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); @@ -252,7 +255,8 @@ public function testAuthenticatedAdherentCanShowCommitteePage() public function testAuthenticatedCommitteeFollowerCanShowCommitteePage() { - $crawler = $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -269,7 +273,8 @@ public function testAuthenticatedCommitteeFollowerCanShowCommitteePage() public function testAuthenticatedCommitteeHostCanShowCommitteePage() { - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); diff --git a/tests/Controller/EnMarche/CommitteeManagerControllerTest.php b/tests/Controller/EnMarche/CommitteeManagerControllerTest.php index 0fca0f2709d..0a2a4e09f40 100644 --- a/tests/Controller/EnMarche/CommitteeManagerControllerTest.php +++ b/tests/Controller/EnMarche/CommitteeManagerControllerTest.php @@ -42,7 +42,8 @@ class CommitteeManagerControllerTest extends WebTestCase public function testCommitteeFollowerIsNotAllowedToEditCommitteeInformation() { - $crawler = $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -54,7 +55,8 @@ public function testCommitteeFollowerIsNotAllowedToEditCommitteeInformation() public function testCommitteeHostCanEditCommitteeInformation() { - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -125,7 +127,8 @@ public function testCommitteeHostCanEditCommitteeInformation() public function testCommitteeHostCannotEditNoneditableCommitteeName() { - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Dammarie-les-Lys')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -161,7 +164,8 @@ public function testCommitteeHostCannotEditNoneditableCommitteeName() public function testCommitteeHostCanEditCompletelyAddressOfPendingCommittee() { - $crawler = $this->authenticateAsAdherent($this->client, 'benjyd@aol.com'); + $this->authenticateAsAdherent($this->client, 'benjyd@aol.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Marseille 3')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -196,7 +200,8 @@ public function testCommitteeHostCanEditCompletelyAddressOfPendingCommittee() public function testCommitteeFollowerIsNotAllowedToPublishNewEvent() { - $crawler = $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $this->authenticateAsAdherent($this->client, 'carl999@example.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -208,7 +213,8 @@ public function testCommitteeFollowerIsNotAllowedToPublishNewEvent() public function testCommitteeHostCanPublishNewEvent() { - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse()); @@ -334,7 +340,8 @@ public function testCommitteeHostCanPublishNewEvent() public function testAuthenticatedCommitteeHostCanPostMessages() { - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $committeeUrl = $this->client->getRequest()->getPathInfo(); @@ -401,7 +408,8 @@ public function testAuthenticatedCommitteeHostCanPostMessages() public function testAuthenticatedFollowerCannotSeeCommitteeMembers(string $username) { // Authenticate as a committee follower - $crawler = $this->authenticateAsAdherent($this->client, $username); + $this->authenticateAsAdherent($this->client, $username); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $this->client->request(Request::METHOD_GET, sprintf('%s/membres', $this->client->getRequest()->getPathInfo())); @@ -422,7 +430,8 @@ public function provideFollowerCredentials() public function testAuthenticatedHostCanSeeCommitteeMembers(string $username) { // Authenticate as the committee supervisor - $crawler = $this->authenticateAsAdherent($this->client, $username); + $this->authenticateAsAdherent($this->client, $username); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $crawler = $this->client->click($crawler->selectLink('Gérer les adhérents')->link()); @@ -445,7 +454,8 @@ public function provideHostCredentials() public function testAuthenticatedCommitteeSupervisorCanPromoteNewHostsAmongMembers() { // Authenticate as the committee supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $crawler = $this->client->click($crawler->selectLink('Gérer les adhérents')->link()); @@ -462,7 +472,8 @@ public function testAuthenticatedCommitteeSupervisorCanPromoteNewHostsAmongMembe public function testAuthenticatedCommitteeHostCannotPromoteNewHostsAmongMembers() { // Authenticate as the committee supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $this->authenticateAsAdherent($this->client, 'gisele-berthoux@caramail.com'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $crawler = $this->client->click($crawler->selectLink('Gérer les adhérents')->link()); @@ -472,7 +483,8 @@ public function testAuthenticatedCommitteeHostCannotPromoteNewHostsAmongMembers( public function testCommitteeExportMembers() { // Authenticate as the committee supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $crawler = $this->client->click($crawler->selectLink('Gérer les adhérents')->link()); @@ -512,7 +524,8 @@ public function testCommitteeExportMembers() public function testCommitteeContactMembers() { // Authenticate as the committee supervisor - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/evenements'); $crawler = $this->client->click($crawler->selectLink('En Marche Paris 8')->link()); $crawler = $this->client->click($crawler->selectLink('Gérer les adhérents')->link()); diff --git a/tests/Controller/EnMarche/CoordinatorControllerTest.php b/tests/Controller/EnMarche/CoordinatorControllerTest.php index 5eba25fe301..9860859d884 100644 --- a/tests/Controller/EnMarche/CoordinatorControllerTest.php +++ b/tests/Controller/EnMarche/CoordinatorControllerTest.php @@ -56,6 +56,7 @@ public function testValidationCommitteeFailed() { $this->authenticateAsAdherent($this->client, 'coordinateur@en-marche-dev.fr'); + $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($this->client->getCrawler()->selectLink('Espace coordinateur régional')->link()); $this->assertStatusCode(Response::HTTP_OK, $this->client); @@ -91,6 +92,7 @@ public function testPreAcceptCommitteeWithSuccess() { $this->authenticateAsAdherent($this->client, 'coordinateur@en-marche-dev.fr'); + $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($this->client->getCrawler()->selectLink('Espace coordinateur régional')->link()); $this->assertStatusCode(Response::HTTP_OK, $this->client); @@ -121,6 +123,7 @@ public function testPreRefuseCommitteeWithSuccess() { $this->authenticateAsAdherent($this->client, 'coordinateur@en-marche-dev.fr'); + $this->client->request(Request::METHOD_GET, '/evenements'); $this->client->click($this->client->getCrawler()->selectLink('Espace coordinateur régional')->link()); $this->assertStatusCode(Response::HTTP_OK, $this->client); diff --git a/tests/Controller/EnMarche/EventControllerTest.php b/tests/Controller/EnMarche/EventControllerTest.php index 99b0fe3f96d..5c6c49506df 100644 --- a/tests/Controller/EnMarche/EventControllerTest.php +++ b/tests/Controller/EnMarche/EventControllerTest.php @@ -91,7 +91,8 @@ public function testAnonymousUserCanRegisterToEvent() public function testRegisteredAdherentUserCanRegisterToEvent() { - $crawler = $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $this->authenticateAsAdherent($this->client, 'jacques.picard@en-marche.fr'); + $crawler = $this->client->request(Request::METHOD_GET, '/'); $crawler = $this->client->click($crawler->selectLink('Rejoindre un comité')->link()); diff --git a/tests/TestHelperTrait.php b/tests/TestHelperTrait.php index dc81f7fb88c..d84cc6557e1 100644 --- a/tests/TestHelperTrait.php +++ b/tests/TestHelperTrait.php @@ -6,6 +6,7 @@ use AppBundle\DataFixtures\ORM\LoadAdherentData; use AppBundle\Entity\Adherent; use AppBundle\Entity\AdherentActivationToken; +use AppBundle\Entity\Administrator; use AppBundle\Entity\Reporting\EmailSubscriptionHistory; use AppBundle\Entity\AdherentResetPasswordToken; use AppBundle\Entity\CitizenAction; @@ -36,6 +37,7 @@ use AppBundle\Repository\AdherentActivationTokenRepository; use AppBundle\Repository\AdherentRepository; use AppBundle\Repository\AdherentResetPasswordTokenRepository; +use AppBundle\Repository\AdministratorRepository; use AppBundle\Repository\CitizenActionRepository; use AppBundle\Repository\CitizenProjectCommentRepository; use AppBundle\Repository\CitizenProjectRepository; @@ -142,6 +144,11 @@ public function getAdherentRepository(): AdherentRepository return $this->getRepository(Adherent::class); } + protected function getAdministratorRepository(): AdministratorRepository + { + return $this->getRepository(Administrator::class); + } + public function getCommitteeRepository(): CommitteeRepository { return $this->getRepository(Committee::class);