Billetterie: - Partial refund support (STATUS_PARTIALLY_REFUNDED, refundedAmount field, migration) - Race condition fix: PESSIMISTIC_WRITE lock on stock decrement in transaction - Idempotency key on PaymentIntent::create, reuse existing PI if stripeSessionId set - Disable checkout when event ended (server 400 + template hide) - Webhook deduplication via cache (24h TTL on stripe event.id) - Email validation (filter_var) in OrderController guest flow - JSON cart validation (structure check before processing) - Invitation expiration after 7 days (isExpired method + landing page message) - Stripe Checkout fallback when JS fails to load (noscript + redirect) Config externalization: - Move Stripe fees (STRIPE_FEE_RATE, STRIPE_FEE_FIXED) and admin email (ADMIN_EMAIL) to .env/services.yaml - Replace all hardcoded contact@e-cosplay.fr across 13 files - MailerService: getAdminEmail()/getAdminFrom(), default $from=null resolves to admin UX & Accessibility: - ARIA tabs: role=tablist/tab/tabpanel, aria-selected, keyboard nav (arrows, Home, End) - aria-label on cart +/- buttons and editor toolbar buttons - tabindex=0 on editor toolbar buttons for keyboard access - data-confirm handler in app.js (was only in admin.js) - Cart error feedback on checkout failure - Billet designer save feedback (loading/success/error states) - Stock polling every 30s with rupture/low stock badges - Back to event link on payment page Security: - HTML sanitizer: BLOCKED_TAGS list (script, style, iframe, svg, etc.) - content fully removed - Stripe polling timeout (15s max) with fallback redirect - Rate limiting on public order access (20/5min) - .catch() on all fetch() calls (sortable, billet-designer) Tests (92% PHP, 100% JS lines): - PCOV added to dev Dockerfile - Test DB setup: .env.test with DATABASE_URL, Redis auth, Meilisearch key - Rate limiter disabled in test env - Makefile: test_db_setup, test_db_reset, run_test_php, run_test_coverage_php/js - New tests: InvitationFlowTest (21), AuditServiceTest (4), ExportServiceTest (9), InvoiceServiceTest (4) - New tests: SuspendedUserSubscriberTest, RateLimiterSubscriberTest, MeilisearchServiceTest - New tests: Stripe webhook payment_failed (6) + charge.refunded (6) - New tests: BilletBuyer refund, User suspended, OrganizerInvitation expiration - JS tests: stock polling (6), data-confirm (2), copy-url restore (1), editor ARIA (2), XSS (9), tabs keyboard (9) - ESLint + PHP CS Fixer: 0 errors - SonarQube exclusions aligned with vitest coverage config Infra: - Meilisearch consistency command (app:meilisearch:check-consistency --fix) + cron daily 3am - MeilisearchService: getAllDocumentIds(), listIndexes() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
118 lines
4.3 KiB
PHP
118 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\Entity\AuditLog;
|
|
use App\Service\AuditService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
class AuditServiceTest extends TestCase
|
|
{
|
|
public function testLogCreatesAuditLogWithUserAndIp(): void
|
|
{
|
|
$em = $this->createMock(EntityManagerInterface::class);
|
|
$security = $this->createMock(Security::class);
|
|
$requestStack = $this->createMock(RequestStack::class);
|
|
|
|
$user = $this->createMock(UserInterface::class);
|
|
$user->method('getUserIdentifier')->willReturn('admin@example.com');
|
|
$security->method('getUser')->willReturn($user);
|
|
|
|
$request = Request::create('/test', 'POST', [], [], [], ['REMOTE_ADDR' => '192.168.1.1']);
|
|
$requestStack->method('getCurrentRequest')->willReturn($request);
|
|
|
|
$persisted = null;
|
|
$em->expects($this->once())->method('persist')->with($this->callback(function (AuditLog $log) use (&$persisted) {
|
|
$persisted = $log;
|
|
|
|
return true;
|
|
}));
|
|
$em->expects($this->once())->method('flush');
|
|
|
|
$service = new AuditService($em, $security, $requestStack);
|
|
$service->log('order_created', 'BilletBuyer', 42, ['key' => 'value']);
|
|
|
|
self::assertSame('order_created', $persisted->getAction());
|
|
self::assertSame('BilletBuyer', $persisted->getEntityType());
|
|
self::assertSame(42, $persisted->getEntityId());
|
|
self::assertSame(['key' => 'value'], $persisted->getData());
|
|
self::assertSame('admin@example.com', $persisted->getPerformedBy());
|
|
self::assertSame('192.168.1.1', $persisted->getIpAddress());
|
|
}
|
|
|
|
public function testLogWithoutUser(): void
|
|
{
|
|
$em = $this->createMock(EntityManagerInterface::class);
|
|
$security = $this->createMock(Security::class);
|
|
$requestStack = $this->createMock(RequestStack::class);
|
|
|
|
$security->method('getUser')->willReturn(null);
|
|
$requestStack->method('getCurrentRequest')->willReturn(Request::create('/'));
|
|
|
|
$persisted = null;
|
|
$em->expects($this->once())->method('persist')->with($this->callback(function (AuditLog $log) use (&$persisted) {
|
|
$persisted = $log;
|
|
|
|
return true;
|
|
}));
|
|
$em->expects($this->once())->method('flush');
|
|
|
|
$service = new AuditService($em, $security, $requestStack);
|
|
$service->log('test_action', 'TestEntity');
|
|
|
|
self::assertNull($persisted->getPerformedBy());
|
|
self::assertNull($persisted->getEntityId());
|
|
}
|
|
|
|
public function testLogWithoutRequest(): void
|
|
{
|
|
$em = $this->createMock(EntityManagerInterface::class);
|
|
$security = $this->createMock(Security::class);
|
|
$requestStack = $this->createMock(RequestStack::class);
|
|
|
|
$security->method('getUser')->willReturn(null);
|
|
$requestStack->method('getCurrentRequest')->willReturn(null);
|
|
|
|
$persisted = null;
|
|
$em->expects($this->once())->method('persist')->with($this->callback(function (AuditLog $log) use (&$persisted) {
|
|
$persisted = $log;
|
|
|
|
return true;
|
|
}));
|
|
$em->expects($this->once())->method('flush');
|
|
|
|
$service = new AuditService($em, $security, $requestStack);
|
|
$service->log('cron_action', 'System');
|
|
|
|
self::assertNull($persisted->getIpAddress());
|
|
self::assertNull($persisted->getPerformedBy());
|
|
}
|
|
|
|
public function testLogWithEmptyData(): void
|
|
{
|
|
$em = $this->createMock(EntityManagerInterface::class);
|
|
$security = $this->createMock(Security::class);
|
|
$requestStack = $this->createMock(RequestStack::class);
|
|
|
|
$security->method('getUser')->willReturn(null);
|
|
$requestStack->method('getCurrentRequest')->willReturn(null);
|
|
|
|
$persisted = null;
|
|
$em->expects($this->once())->method('persist')->with($this->callback(function (AuditLog $log) use (&$persisted) {
|
|
$persisted = $log;
|
|
|
|
return true;
|
|
}));
|
|
|
|
$service = new AuditService($em, $security, $requestStack);
|
|
$service->log('simple', 'Entity', 1);
|
|
|
|
self::assertSame([], $persisted->getData());
|
|
}
|
|
}
|