public function EntityAccessEventTest::testEntityAccessEventCombinedResults in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/core_event_dispatcher/tests/src/Unit/Entity/EntityAccessEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityAccessEventTest::testEntityAccessEventCombinedResults()
EntityAccessEvent with combined results test.
This simulates multiple event listeners adding their own access results to this event.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityAccessEventTest.php, line 136
Class
- EntityAccessEventTest
- Class EntityAccessEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\EntityCode
public function testEntityAccessEventCombinedResults() : void {
$accessResults = [
new AccessResultNeutral(),
new AccessResultAllowed(),
new AccessResultForbidden(),
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::ENTITY_ACCESS => static function (EntityAccessEvent $event) use ($accessResults) {
foreach ($accessResults as $accessResult) {
$event
->addAccessResult($accessResult);
}
},
]);
$entity = $this
->createMock(EntityInterface::class);
$operation = 'test';
$account = $this
->createMock(AccountInterface::class);
$hookAccessResult = core_event_dispatcher_entity_access($entity, $operation, $account);
self::assertFalse($hookAccessResult
->isNeutral());
self::assertFalse($hookAccessResult
->isAllowed());
self::assertTrue($hookAccessResult
->isForbidden());
}