public function EntityFieldAccessEventTest::testEntityFieldAccessEvent in Hook Event Dispatcher 8
Test the BlockBuildAlterEvent.
File
- tests/
src/ Unit/ EntityField/ EntityFieldAccessEventTest.php, line 45
Class
- EntityFieldAccessEventTest
- Class EntityFieldAccessEventTest.
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\EntityFieldCode
public function testEntityFieldAccessEvent() {
$accessResult = $this
->createMock(AccessResultInterface::class);
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::ENTITY_FIELD_ACCESS => 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 = hook_event_dispatcher_entity_field_access($operation, $fieldDefinition, $account, $items);
/** @var \Drupal\hook_event_dispatcher\Event\EntityField\EntityFieldAccessEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_FIELD_ACCESS);
self::assertEquals($operation, $event
->getOperation());
self::assertEquals($fieldDefinition, $event
->getFieldDefinition());
self::assertEquals($account, $event
->getAccount());
self::assertEquals($items, $event
->getItems());
self::assertEquals($accessResult, $hookAccessResult);
}