From 1c9b47564042aa822fd31a9f428fb780939bda9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 Feb 2026 18:49:31 +0100 Subject: [PATCH] Add `AuditEventDumperTest` to validate audit event dumping functionality - Introduced a test case for `AuditEventDumper` to ensure proper CSV generation and storage. - Verified metadata, user, and entity subject data accuracy in the dumped output. --- .../Tests/Audit/AuditEventDumperTest.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Audit/AuditEventDumperTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Audit/AuditEventDumperTest.php b/src/Bundle/ChillMainBundle/Tests/Audit/AuditEventDumperTest.php new file mode 100644 index 000000000..d2d45b632 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Audit/AuditEventDumperTest.php @@ -0,0 +1,104 @@ +storedObjectManager = self::getContainer()->get(StoredObjectManagerInterface::class); + $this->auditTrailRepository = self::getContainer()->get(AuditTrailRepository::class); + $this->translator = self::getContainer()->get('translator'); + $this->subjectConverterManager = self::getContainer()->get(SubjectConverterManagerInterface::class); + $this->entityManager = self::getContainer()->get('doctrine.orm.entity_manager'); + $this->userRender = self::getContainer()->get(UserRender::class); + } + + public function testDump(): void + { + // store an audit + + $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u') + ->setMaxResults(1) + ->getOneOrNullResult(); + $person = $this->getRandomPerson($this->entityManager); + $subjetBag = $this->subjectConverterManager->getSubjectsForEntity($person); + + $audit = new AuditTrail( + UuidV7::uuid7(), + AuditTrail::AUDIT_VIEW, + $at = new \DateTimeImmutable('2026-02-14T14:00:00', new \DateTimeZone('Europe/Brussels')), + $user, + 'Some description', + $subjetBag->subject->asArray(), + [], + ['some-metadata' => 1], + ); + + $this->entityManager->persist($audit); + $this->entityManager->flush(); + + $criteria = ['from' => $at->sub(new \DateInterval('PT30S')), 'to' => $at->add(new \DateInterval('PT30S'))]; + + $dumper = new AuditEventDumper( + $this->storedObjectManager, + $this->auditTrailRepository, + $this->translator, + $this->subjectConverterManager, + $this->entityManager, + $this->userRender, + ); + + $storedObject = $dumper->dump($criteria, 'fr'); + + $read = $this->storedObjectManager->read($storedObject); + + self::assertStringContainsString('14/02/2026 14:00:00', $read); + self::assertStringContainsString((string) $user->getId(), $read); + self::assertStringContainsString('Some description', $read); + self::assertStringContainsString($person->getFirstName(), $read); + } +}