You are here

public function EntityAccessEventTest::testEntityAccessEventNeutralResult in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Entity/EntityAccessEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityAccessEventTest::testEntityAccessEventNeutralResult()

EntityAccessEvent with neutral result test.

File

modules/core_event_dispatcher/tests/src/Unit/Entity/EntityAccessEventTest.php, line 67

Class

EntityAccessEventTest
Class EntityAccessEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity

Code

public function testEntityAccessEventNeutralResult() : void {
  $accessResult = new AccessResultNeutral();
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_ACCESS => static function (EntityAccessEvent $event) use ($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::assertTrue($hookAccessResult
    ->isNeutral());
  self::assertFalse($hookAccessResult
    ->isAllowed());
  self::assertFalse($hookAccessResult
    ->isForbidden());
}