You are here

public function EntityFieldAccessEventTest::testEntityFieldAccessEventWithoutResult in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityFieldAccessEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityFieldAccessEventTest::testEntityFieldAccessEventWithoutResult()

Field access event with result set.

File

modules/core_event_dispatcher/tests/src/Unit/Entity/EntityFieldAccessEventTest.php, line 45

Class

EntityFieldAccessEventTest
Class EntityFieldAccessEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity

Code

public function testEntityFieldAccessEventWithoutResult() : void {
  $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($hookAccessResult, $event
    ->getAccessResult());
  self::assertTrue($event
    ->getAccessResult()
    ->isNeutral());
}