Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi authored and Rémi committed Feb 27, 2025
1 parent 4931505 commit ea10960
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/DataFixtures/ORM/LoadAdherentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function load(ObjectManager $manager): void
// Create adherent users list
$adherent1 = $this->adherentFactory->createFromArray([
'uuid' => self::ADHERENT_1_UUID,
'public_id' => '123-456',
'password' => self::DEFAULT_PASSWORD,
'email' => '[email protected]',
'gender' => 'female',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Tests\App\Controller\Renaissance\NationalEvent;

use App\Entity\NationalEvent\EventInscription;
use App\Repository\NationalEvent\EventInscriptionRepository;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Tests\App\AbstractWebTestCase;
use Tests\App\Controller\ControllerTestTrait;

#[Group('functional')]
class EventInscriptionControllerTest extends AbstractWebTestCase
{
use ControllerTestTrait;

private ?EventInscriptionRepository $eventInscriptionRepository = null;

#[DataProvider('provideReferrerCodes')]
public function testEventInscriptionWithReferral(string $referrerCode, ?string $referrerEmail): void
{
$crawler = $this->client->request(Request::METHOD_GET, "/grand-rassemblement/event-national-1/$referrerCode");
$this->assertStatusCode(Response::HTTP_OK, $this->client);

$buttonCrawlerNode = $crawler->selectButton('Je réserve ma place');

$form = $buttonCrawlerNode->form();

$form['event_inscription[acceptCgu]']->tick();
$form['event_inscription[acceptMedia]']->tick();

$this->client->submit($form, [
'event_inscription' => [
'email' => '[email protected]',
'civility' => 'male',
'firstName' => 'John',
'lastName' => 'Doe',
'birthPlace' => 'Paris',
'birthdate' => ['year' => '2000', 'month' => '10', 'day' => '2'],
'postalCode' => '75001',
],
]);
$this->assertClientIsRedirectedTo('/grand-rassemblement/event-national-1/confirmation', $this->client);

$this->client->followRedirect();
$this->assertStatusCode(Response::HTTP_OK, $this->client);

$eventInscription = $this->eventInscriptionRepository->findOneBy(['addressEmail' => '[email protected]']);
$this->assertInstanceOf(EventInscription::class, $eventInscription);
$this->assertEquals($referrerCode, $eventInscription->referrerCode);
$this->assertEquals($referrerEmail, $eventInscription->referrer?->getEmailAddress());
}

public static function provideReferrerCodes(): iterable
{
yield ['123-456', '[email protected]'];
yield ['invalid', null];
}

protected function setUp(): void
{
parent::setUp();

$this->eventInscriptionRepository = $this->getRepository(EventInscription::class);

$this->client->setServerParameter('HTTP_HOST', static::getContainer()->getParameter('user_vox_host'));
}

protected function tearDown(): void
{
parent::tearDown();

$this->eventInscriptionRepository = null;
}
}

0 comments on commit ea10960

Please sign in to comment.