diff --git a/src/Attribute/AdminDashboard.php b/src/Attribute/AdminDashboard.php index eef97709d7..dfdda6a268 100644 --- a/src/Attribute/AdminDashboard.php +++ b/src/Attribute/AdminDashboard.php @@ -12,11 +12,11 @@ public function __construct( /** * @var string|null $routePath The path of the Symfony route that will be created for the dashboard (e.g. '/admin) */ - public /* ?string */ $routePath = null, + /* ?string */ public $routePath = null, /** * @var string|null $routeName The name of the Symfony route that will be created for the dashboard (e.g. 'admin') */ - public /* ?string */ $routeName = null, + /* ?string */ public $routeName = null, /** * @var array{ * requirements?: array, diff --git a/tests/TestApplication/src/Security/CustomVoter.php b/tests/TestApplication/src/Security/CustomVoter.php new file mode 100644 index 0000000000..03d52dbb5b --- /dev/null +++ b/tests/TestApplication/src/Security/CustomVoter.php @@ -0,0 +1,61 @@ +getInstance()) { + $entities[] = $subject; + } + + foreach ($entities as $entityDto) { + if ($this->banEntity && $entityDto->getInstance() === $this->banEntity) { + // imitate the behavior of FieldFactory::processFields() + // which removes the field from the entity if it is not granted + if ($subject instanceof FieldDto) { + if ($fieldDto = $entityDto->getFields()?->getByProperty($this->banEntityProperty)) { + $entityDto->getFields()->unset($fieldDto); + } + } + } + } + + return true; + } + + public function ban(object $entity, ?string $propertyName = null): void + { + $this->banEntity = $entity; + $this->banEntityProperty = $propertyName; + } + + public function removeBan(): void + { + $this->banEntity = null; + $this->banEntityProperty = null; + } +} diff --git a/tests/VoterTest.php b/tests/VoterTest.php new file mode 100644 index 0000000000..daedd79284 --- /dev/null +++ b/tests/VoterTest.php @@ -0,0 +1,60 @@ +client->followRedirects(); + $this->repository = $this->entityManager->getRepository(Website::class); + } + + public function testingVoter() + { + // Arrange + $entities = $this->repository->findAll(); + + /** @var CustomVoter $voter */ + $voter = $this->getContainer()->get(CustomVoter::class); + $voter->ban($entities[0], 'name'); + + // UnanimousStrategy + $accessDecisionManager = $this->getContainer()->get('security.access.decision_manager'); + \Closure::bind(function () { + $this->strategy = new UnanimousStrategy(); + }, $accessDecisionManager, $accessDecisionManager)(); + + // Act + $crawler = $this->client->request('GET', $this->generateIndexUrl()); + + // Assert + $this->assertResponseIsSuccessful(); + $this->assertSelectorExists('th[data-column="pages"]'); + $this->assertSelectorExists('th[data-column="name"]'); + } +}