public function EntityFieldAccessEventTest::testEntityFieldAccessEventWithResultSet in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityFieldAccessEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityFieldAccessEventTest::testEntityFieldAccessEventWithResultSet()
Field access event with result set.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityFieldAccessEventTest.php, line 66
Class
- EntityFieldAccessEventTest
- Class EntityFieldAccessEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\EntityCode
public function testEntityFieldAccessEventWithResultSet() : void {
$accessResult = $this
->createMock(AccessResultInterface::class);
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::ENTITY_FIELD_ACCESS => static function (EntityFieldAccessEvent $event) use ($accessResult) {
$event
->setAccessResult($accessResult);
},
]);
$operation = 'test';
$fieldDefinition = $this
->createMock(FieldDefinitionInterface::class);
$account = $this
->createMock(AccountInterface::class);
$items = $this
->createMock(FieldItemListInterface::class);
$hookAccessResult = core_event_dispatcher_entity_field_access($operation, $fieldDefinition, $account, $items);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityFieldAccessEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_FIELD_ACCESS);
self::assertSame($operation, $event
->getOperation());
self::assertSame($fieldDefinition, $event
->getFieldDefinition());
self::assertSame($account, $event
->getAccount());
self::assertSame($items, $event
->getItems());
self::assertSame($accessResult, $event
->getAccessResult());
self::assertSame($accessResult, $hookAccessResult);
}