tests/TestUserProvider.php (nouveau): - Implementation de UserProviderInterface pour l'environnement test - loadUserByIdentifier(), refreshUser(), supportsClass() - Le service etait reference dans security.yaml when@test mais n'existait pas config/services_test.yaml (nouveau): - Enregistrement de App\Tests\TestUserProvider comme service public pour que le container test puisse le resoudre tests/Controller/LegalControllerTest.php: - Selecteurs CSS mis a jour: .border-red-600 remplace par .border-red-300 et .border-green-600 par .border-green-300 (glassmorphism) tests/Controller/Admin/AdminControllersTest.php: - testSyncIndex(): ajout de PriceAutomaticRepository et StripeWebhookSecretRepository dans les arguments de SyncController::index() (4 arguments au lieu de 2) tests/Controller/MainControllersTest.php: - testForgotPasswordFullFlow(): sendEmail attendu 2 fois au lieu de 1 (step 2 envoie le code, step 3 envoie la confirmation de changement) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
180 lines
6.1 KiB
PHP
180 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use App\Service\RgpdService;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
class LegalControllerTest extends WebTestCase
|
|
{
|
|
#[DataProvider('provideLegalRoutes')]
|
|
public function testLegalPages(string $url): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('GET', $url);
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
public static function provideLegalRoutes(): iterable
|
|
{
|
|
yield ['/legal/mention-legal'];
|
|
yield ['/legal/conditions-general-utilisation'];
|
|
yield ['/legal/conditions-general-de-vente'];
|
|
yield ['/legal/cookie'];
|
|
yield ['/legal/hebergement'];
|
|
yield ['/legal/conformite'];
|
|
yield ['/legal/tarif'];
|
|
yield ['/legal/rgpd'];
|
|
}
|
|
|
|
public function testRgpdAccessValidation(): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('POST', '/legal/rgpd/acces', [
|
|
'ip' => '',
|
|
'email' => '',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-red-300', 'Veuillez remplir tous les champs.');
|
|
}
|
|
|
|
public function testRgpdAccessSuccess(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleAccessRequest')
|
|
->willReturn(['found' => true]);
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/acces', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-green-300', 'Vos donnees ont ete envoyees par email.');
|
|
}
|
|
|
|
public function testRgpdAccessNotFound(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleAccessRequest')
|
|
->willReturn(['found' => false]);
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/acces', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-green-300', 'Aucune donnee trouvee pour cette adresse IP.');
|
|
}
|
|
|
|
public function testRgpdAccessError(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleAccessRequest')
|
|
->willThrowException(new \Exception('Error'));
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/acces', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-red-300', 'Une erreur est survenue lors du traitement de votre demande.');
|
|
}
|
|
|
|
public function testRgpdDeletionValidation(): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('POST', '/legal/rgpd/suppression', [
|
|
'ip' => '',
|
|
'email' => '',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-red-300', 'Veuillez remplir tous les champs.');
|
|
}
|
|
|
|
public function testRgpdDeletionSuccess(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleDeletionRequest')
|
|
->willReturn(['found' => true]);
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/suppression', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-green-300', 'Vos donnees ont ete supprimees.');
|
|
}
|
|
|
|
public function testRgpdDeletionNotFound(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleDeletionRequest')
|
|
->willReturn(['found' => false]);
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/suppression', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-green-300', 'Aucune donnee trouvee pour cette adresse IP.');
|
|
}
|
|
|
|
public function testRgpdDeletionError(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('handleDeletionRequest')
|
|
->willThrowException(new \Exception('Error'));
|
|
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/suppression', [
|
|
'ip' => '127.0.0.1',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
$client->followRedirect();
|
|
$this->assertSelectorTextContains('.border-red-300', 'Une erreur est survenue lors du traitement de votre demande.');
|
|
}
|
|
}
|