Add admin panel, Meilisearch buyer search, email redesign, and multiple features
Admin panel (/admin, ROLE_ROOT): - Dashboard with CA HT Global/Commission cards and Meilisearch sync button - Buyers page with search (Meilisearch), create form, pagination (KnpPaginator) - Buyer actions: resend verification, force verify, reset password, delete - Organizers page with tabs (pending/approved), approve/reject with emails - Neo-brutalist design matching main site theme - Vite admin entry point with dedicated SCSS - CSP-compatible confirm dialogs via data-confirm attributes Meilisearch integration: - Auto-index buyers on email verification - Remove from index on buyer deletion - Manual sync button on dashboard - Search bar on buyers page - Add Meilisearch service to CI/SonarQube workflows - Add MEILISEARCH env vars to .env.test - Fix MeilisearchMessageHandler infinite loop: use request() directly instead of service methods that re-dispatch messages Email templates: - Redesign base email template to neo-brutalist style (borders, shadows, yellow footer) - Add E-Cosplay logo, "E-Ticket solution proposee par e-cosplay.fr" - Add admin_reset_password, organizer_approved, organizer_rejected templates Other: - Install knplabs/knp-paginator-bundle - Add ^/admin access_control for ROLE_ROOT in security.yaml - Update site footer with E-Ticket branding - 18 admin tests, updated MeilisearchMessageHandler tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
350
tests/Controller/AdminControllerTest.php
Normal file
350
tests/Controller/AdminControllerTest.php
Normal file
@@ -0,0 +1,350 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Service\MailerService;
|
||||
use App\Service\MeilisearchService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AdminControllerTest extends WebTestCase
|
||||
{
|
||||
public function testDashboardRedirectsWhenNotAuthenticated(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('GET', '/admin');
|
||||
|
||||
self::assertResponseRedirects();
|
||||
}
|
||||
|
||||
public function testDashboardDeniedForNonRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser();
|
||||
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', '/admin');
|
||||
|
||||
self::assertResponseStatusCodeSame(403);
|
||||
}
|
||||
|
||||
public function testDashboardReturnsSuccessForRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', '/admin');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testUsersPageReturnsSuccessForRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', '/admin/utilisateurs');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testUsersPageDeniedForNonRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser();
|
||||
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', '/admin/utilisateurs');
|
||||
|
||||
self::assertResponseStatusCodeSame(403);
|
||||
}
|
||||
|
||||
public function testBuyersPageReturnsSuccessForRoot(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', '/admin/acheteurs');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testBuyersSearchWithQuery(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||
$meilisearch->expects(self::once())->method('search')->willReturn([
|
||||
'hits' => [],
|
||||
'estimatedTotalHits' => 0,
|
||||
]);
|
||||
static::getContainer()->set(MeilisearchService::class, $meilisearch);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('GET', '/admin/acheteurs?q=test');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testSyncMeilisearch(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$meilisearch = $this->createMock(MeilisearchService::class);
|
||||
$meilisearch->expects(self::once())->method('createIndexIfNotExists');
|
||||
static::getContainer()->set(MeilisearchService::class, $meilisearch);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/sync-meilisearch');
|
||||
|
||||
self::assertResponseRedirects('/admin');
|
||||
}
|
||||
|
||||
public function testCreateBuyerWithValidData(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$mailer = $this->createMock(MailerService::class);
|
||||
$mailer->expects(self::once())->method('sendEmail');
|
||||
static::getContainer()->set(MailerService::class, $mailer);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteurs/creer', [
|
||||
'first_name' => 'Nouveau',
|
||||
'last_name' => 'Acheteur',
|
||||
'email' => 'new-buyer-'.uniqid().'@example.com',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
}
|
||||
|
||||
public function testCreateBuyerWithDuplicateEmail(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteurs/creer', [
|
||||
'first_name' => 'Dup',
|
||||
'last_name' => 'Test',
|
||||
'email' => $admin->getEmail(),
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
}
|
||||
|
||||
public function testResendVerificationEmail(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$buyer = new User();
|
||||
$buyer->setEmail('test-buyer-'.uniqid().'@example.com');
|
||||
$buyer->setFirstName('Buyer');
|
||||
$buyer->setLastName('Test');
|
||||
$buyer->setPassword('$2y$13$hashed');
|
||||
$em->persist($buyer);
|
||||
$em->flush();
|
||||
|
||||
$mailer = $this->createMock(MailerService::class);
|
||||
$mailer->expects(self::once())->method('sendEmail');
|
||||
static::getContainer()->set(MailerService::class, $mailer);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteur/'.$buyer->getId().'/renvoyer-verification');
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
|
||||
$em->refresh($buyer);
|
||||
self::assertNotNull($buyer->getEmailVerificationToken());
|
||||
}
|
||||
|
||||
public function testResetPasswordSendsEmail(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$buyer = new User();
|
||||
$buyer->setEmail('test-reset-admin-'.uniqid().'@example.com');
|
||||
$buyer->setFirstName('Reset');
|
||||
$buyer->setLastName('Test');
|
||||
$buyer->setPassword('$2y$13$hashed');
|
||||
$buyer->setIsVerified(true);
|
||||
$em->persist($buyer);
|
||||
$em->flush();
|
||||
|
||||
$mailer = $this->createMock(MailerService::class);
|
||||
$mailer->expects(self::once())->method('sendEmail');
|
||||
static::getContainer()->set(MailerService::class, $mailer);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteur/'.$buyer->getId().'/reset-password');
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
}
|
||||
|
||||
public function testDeleteBuyer(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$buyer = new User();
|
||||
$buyer->setEmail('test-delete-'.uniqid().'@example.com');
|
||||
$buyer->setFirstName('Delete');
|
||||
$buyer->setLastName('Test');
|
||||
$buyer->setPassword('$2y$13$hashed');
|
||||
$em->persist($buyer);
|
||||
$em->flush();
|
||||
$buyerId = $buyer->getId();
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteur/'.$buyerId.'/supprimer');
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
|
||||
$deleted = $em->getRepository(User::class)->find($buyerId);
|
||||
self::assertNull($deleted);
|
||||
}
|
||||
|
||||
public function testForceVerification(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$buyer = new User();
|
||||
$buyer->setEmail('test-force-'.uniqid().'@example.com');
|
||||
$buyer->setFirstName('Force');
|
||||
$buyer->setLastName('Test');
|
||||
$buyer->setPassword('$2y$13$hashed');
|
||||
$em->persist($buyer);
|
||||
$em->flush();
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/acheteur/'.$buyer->getId().'/forcer-verification');
|
||||
|
||||
self::assertResponseRedirects('/admin/acheteurs');
|
||||
|
||||
$em->refresh($buyer);
|
||||
self::assertTrue($buyer->isVerified());
|
||||
self::assertNotNull($buyer->getEmailVerifiedAt());
|
||||
self::assertNull($buyer->getEmailVerificationToken());
|
||||
}
|
||||
|
||||
public function testOrganizersPagePendingTab(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('GET', '/admin/organisateurs');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testOrganizersPageApprovedTab(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('GET', '/admin/organisateurs?tab=approved');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testApproveOrganizer(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
$orga = $this->createOrganizer($em);
|
||||
|
||||
$mailer = $this->createMock(MailerService::class);
|
||||
$mailer->expects(self::once())->method('sendEmail');
|
||||
static::getContainer()->set(MailerService::class, $mailer);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/organisateur/'.$orga->getId().'/approuver');
|
||||
|
||||
self::assertResponseRedirects('/admin/organisateurs');
|
||||
|
||||
$em->refresh($orga);
|
||||
self::assertTrue($orga->isApproved());
|
||||
}
|
||||
|
||||
public function testRejectOrganizer(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$admin = $this->createUser(['ROLE_ROOT']);
|
||||
$orga = $this->createOrganizer($em);
|
||||
$orgaId = $orga->getId();
|
||||
|
||||
$mailer = $this->createMock(MailerService::class);
|
||||
$mailer->expects(self::once())->method('sendEmail');
|
||||
static::getContainer()->set(MailerService::class, $mailer);
|
||||
|
||||
$client->loginUser($admin);
|
||||
$client->request('POST', '/admin/organisateur/'.$orgaId.'/refuser');
|
||||
|
||||
self::assertResponseRedirects('/admin/organisateurs');
|
||||
|
||||
$deleted = $em->getRepository(User::class)->find($orgaId);
|
||||
self::assertNull($deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
private function createUser(array $roles = []): User
|
||||
{
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$user = new User();
|
||||
$user->setEmail('test-admin-'.uniqid().'@example.com');
|
||||
$user->setFirstName('Admin');
|
||||
$user->setLastName('User');
|
||||
$user->setPassword('$2y$13$hashed');
|
||||
$user->setRoles($roles);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function createOrganizer(EntityManagerInterface $em): User
|
||||
{
|
||||
$orga = new User();
|
||||
$orga->setEmail('test-orga-'.uniqid().'@example.com');
|
||||
$orga->setFirstName('Orga');
|
||||
$orga->setLastName('Test');
|
||||
$orga->setPassword('$2y$13$hashed');
|
||||
$orga->setRoles(['ROLE_ORGANIZER']);
|
||||
$orga->setIsVerified(true);
|
||||
$orga->setCompanyName('Mon Asso');
|
||||
$orga->setSiret('12345678901234');
|
||||
|
||||
$em->persist($orga);
|
||||
$em->flush();
|
||||
|
||||
return $orga;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
public function testHandleCreateIndex(): void
|
||||
{
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('createIndex')
|
||||
->with('events', 'uid');
|
||||
->method('request')
|
||||
->with('POST', '/indexes', ['uid' => 'events', 'primaryKey' => 'uid']);
|
||||
|
||||
($this->handler)(new MeilisearchMessage('createIndex', 'events', ['primaryKey' => 'uid']));
|
||||
}
|
||||
@@ -30,8 +30,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
public function testHandleDeleteIndex(): void
|
||||
{
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('deleteIndex')
|
||||
->with('events');
|
||||
->method('request')
|
||||
->with('DELETE', '/indexes/events');
|
||||
|
||||
($this->handler)(new MeilisearchMessage('deleteIndex', 'events'));
|
||||
}
|
||||
@@ -40,8 +40,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
{
|
||||
$docs = [['id' => 1]];
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('addDocuments')
|
||||
->with('events', $docs);
|
||||
->method('request')
|
||||
->with('POST', '/indexes/events/documents', $docs);
|
||||
|
||||
($this->handler)(new MeilisearchMessage('addDocuments', 'events', ['documents' => $docs]));
|
||||
}
|
||||
@@ -50,8 +50,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
{
|
||||
$docs = [['id' => 1, 'title' => 'Updated']];
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('updateDocuments')
|
||||
->with('events', $docs);
|
||||
->method('request')
|
||||
->with('PUT', '/indexes/events/documents', $docs);
|
||||
|
||||
($this->handler)(new MeilisearchMessage('updateDocuments', 'events', ['documents' => $docs]));
|
||||
}
|
||||
@@ -59,8 +59,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
public function testHandleDeleteDocument(): void
|
||||
{
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('deleteDocument')
|
||||
->with('events', 42);
|
||||
->method('request')
|
||||
->with('DELETE', '/indexes/events/documents/42');
|
||||
|
||||
($this->handler)(new MeilisearchMessage('deleteDocument', 'events', ['documentId' => 42]));
|
||||
}
|
||||
@@ -68,8 +68,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
public function testHandleDeleteDocuments(): void
|
||||
{
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('deleteDocuments')
|
||||
->with('events', [1, 2, 3]);
|
||||
->method('request')
|
||||
->with('POST', '/indexes/events/documents/delete-batch', [1, 2, 3]);
|
||||
|
||||
($this->handler)(new MeilisearchMessage('deleteDocuments', 'events', ['ids' => [1, 2, 3]]));
|
||||
}
|
||||
@@ -78,8 +78,8 @@ class MeilisearchMessageHandlerTest extends TestCase
|
||||
{
|
||||
$settings = ['searchableAttributes' => ['title']];
|
||||
$this->meilisearch->expects(self::once())
|
||||
->method('updateSettings')
|
||||
->with('events', $settings);
|
||||
->method('request')
|
||||
->with('PATCH', '/indexes/events/settings', $settings);
|
||||
|
||||
($this->handler)(new MeilisearchMessage('updateSettings', 'events', ['settings' => $settings]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user