Entites completes a 100% : - AdvertTest : 12 nouveaux (state, customer, totals, hmac, lines, payments) - CustomerTest : 3 nouveaux (isPendingDelete, revendeurCode, updatedAt) - DevisTest : 6 nouveaux (customer, submissionId, lines, state constants) - FactureTest : 10 nouveaux (state, totals, isPaid, lines, hmac, splitIndex) - OrderNumberTest : 1 nouveau (markAsUnused) - WebsiteTest : 1 nouveau (revendeurCode) Services completes/ameliores : - DocuSealServiceTest : 30 nouveaux (sendDevis, resendDevis, download, compta) - AdvertServiceTest : 6 nouveaux (isTvaEnabled, getTvaRate, computeTotals) - DevisServiceTest : 6 nouveaux (idem) - FactureServiceTest : 8 nouveaux (idem + createPaidFactureFromAdvert) - MailerServiceTest : 7 nouveaux (unsubscribe headers, VCF, formatFileSize) - MeilisearchServiceTest : 42 nouveaux (index/remove/search tous types) - RgpdServiceTest : 6 nouveaux (sendVerificationCode, verifyCode) - OrderNumberServiceTest : 2 nouveaux (preview/generate unused) - TarificationServiceTest : 1 nouveau (stripe error logger) - ComptaPdfTest : 4 nouveaux (totaux, colonnes numeriques, signature) - FacturePdfTest : 6 nouveaux (QR code, RIB, CGV Twig, footer skip) Controllers ameliores : - ComptabiliteControllerTest : 13 nouveaux (JSON, PDF, sign, callback) - StatsControllerTest : 2 nouveaux (rich data, 6-month evolution) - SyncControllerTest : 13 nouveaux (sync 6 types + purge) - ClientsControllerTest : 7 nouveaux (show, delete, resendWelcome) - FactureControllerTest : 2 nouveaux (generatePdf 404, send success) - LegalControllerTest : 6 nouveaux (rgpdVerify GET/POST) - TarificationControllerTest : 3 nouveaux (purge paths) - AdminControllersTest : 9 nouveaux (dashboard search, services) - WebhookStripeControllerTest : 3 nouveaux (invalid signatures) - KeycloakAuthenticatorTest : 4 nouveaux (groups, domain check) Commands : - PaymentReminderCommandTest : 1 nouveau (formalNotice step) - TestMailCommandTest : 2 nouveaux (force-dsn success/failure) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
259 lines
8.7 KiB
PHP
259 lines
8.7 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('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'access');
|
|
|
|
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/verify?type=access&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
public function testRgpdAccessNotFound(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'access');
|
|
|
|
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/verify?type=access&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
public function testRgpdAccessError(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'access');
|
|
|
|
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/verify?type=access&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
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('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'deletion');
|
|
|
|
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/verify?type=deletion&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
public function testRgpdDeletionNotFound(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'deletion');
|
|
|
|
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/verify?type=deletion&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
public function testRgpdDeletionError(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->expects($this->once())
|
|
->method('sendVerificationCode')
|
|
->with('test@example.com', '127.0.0.1', 'deletion');
|
|
|
|
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/verify?type=deletion&email=test@example.com&ip=127.0.0.1');
|
|
}
|
|
|
|
public function testRgpdVerifyGetShowsForm(): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('GET', '/legal/rgpd/verify', [
|
|
'type' => 'access',
|
|
'email' => 'test@example.com',
|
|
'ip' => '127.0.0.1',
|
|
]);
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
public function testRgpdVerifyGetMissingParams(): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('GET', '/legal/rgpd/verify', []);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
}
|
|
|
|
public function testRgpdVerifyPostInvalidCode(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->method('verifyCode')->willReturn(false);
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/verify', [
|
|
'type' => 'access',
|
|
'email' => 'test@example.com',
|
|
'ip' => '127.0.0.1',
|
|
'code' => 'BADCODE',
|
|
]);
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
public function testRgpdVerifyPostValidAccessCode(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->method('verifyCode')->willReturn(true);
|
|
$rgpdService->method('handleAccessRequest')->willReturn(['found' => true]);
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/verify', [
|
|
'type' => 'access',
|
|
'email' => 'test@example.com',
|
|
'ip' => '127.0.0.1',
|
|
'code' => 'VALIDCODE',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
}
|
|
|
|
public function testRgpdVerifyPostValidDeletionCode(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->method('verifyCode')->willReturn(true);
|
|
$rgpdService->method('handleDeletionRequest')->willReturn(['found' => false]);
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/verify', [
|
|
'type' => 'deletion',
|
|
'email' => 'test@example.com',
|
|
'ip' => '127.0.0.1',
|
|
'code' => 'VALIDCODE',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
}
|
|
|
|
public function testRgpdVerifyPostHandlerThrows(): void
|
|
{
|
|
$client = static::createClient();
|
|
$rgpdService = $this->createMock(RgpdService::class);
|
|
$rgpdService->method('verifyCode')->willReturn(true);
|
|
$rgpdService->method('handleAccessRequest')->willThrowException(new \RuntimeException('Service down'));
|
|
static::getContainer()->set(RgpdService::class, $rgpdService);
|
|
|
|
$client->request('POST', '/legal/rgpd/verify', [
|
|
'type' => 'access',
|
|
'email' => 'test@example.com',
|
|
'ip' => '127.0.0.1',
|
|
'code' => 'CODE',
|
|
]);
|
|
|
|
$this->assertResponseRedirects('/legal/rgpd#exercer-droits');
|
|
}
|
|
}
|