diff --git a/tests/Module/Commercial/Unit/SupplierProcessorTest.php b/tests/Module/Commercial/Unit/SupplierProcessorTest.php index 19b26f4..250ae0a 100644 --- a/tests/Module/Commercial/Unit/SupplierProcessorTest.php +++ b/tests/Module/Commercial/Unit/SupplierProcessorTest.php @@ -101,6 +101,24 @@ final class SupplierProcessorTest extends TestCase self::assertInstanceOf(Supplier::class, $processor->process($supplier, $this->operation())); } + public function testAdminIncompleteInformationPasses(): void + { + // Distinct du cas user=null : un utilisateur AUTHENTIFIE mais non-Commerciale + // (ici un admin, BusinessRoleAwareInterface renvoyant false pour tout role + // metier) n'est pas soumis a la completude Information -> 200 malgre un + // onglet Information incomplet. Prouve que le gate porte bien sur le ROLE + // metier Commerciale, et pas sur « il y a un utilisateur connecte ». + $supplier = $this->minimalSupplier(); + $supplier->setDescription('Une description'); + + $processor = $this->makeProcessor( + payload: ['description' => 'Une description'], + user: $this->adminUser(), + ); + + self::assertInstanceOf(Supplier::class, $processor->process($supplier, $this->operation())); + } + /** * @param list $granted Permissions accordees a l'utilisateur courant * @param array $payload Corps JSON simule de la requete @@ -175,6 +193,33 @@ final class SupplierProcessorTest extends TestCase return $this->createStub(Operation::class); } + /** + * Utilisateur authentifie non-Commerciale (profil admin) : porte + * BusinessRoleAwareInterface mais ne reconnait aucun role metier. Sert a + * distinguer « pas de role Commerciale » de « pas d'utilisateur » (null). + */ + private function adminUser(): UserInterface + { + return new class implements UserInterface, BusinessRoleAwareInterface { + public function hasBusinessRole(string $roleCode): bool + { + return false; + } + + public function getRoles(): array + { + return ['ROLE_ADMIN']; + } + + public function eraseCredentials(): void {} + + public function getUserIdentifier(): string + { + return 'admin-test'; + } + }; + } + private function commercialeUser(): UserInterface { return new class implements UserInterface, BusinessRoleAwareInterface {