You are here

public function EntityAccessControlHandlerTest::testHooks in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testHooks()

Tests hook invocations.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php, line 279

Class

EntityAccessControlHandlerTest
Tests the entity access control handler.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testHooks() {
  $state = $this->container
    ->get('state');
  $entity = EntityTest::create([
    'name' => 'test',
  ]);

  // Test hook_entity_create_access() and hook_ENTITY_TYPE_create_access().
  $entity
    ->access('create');
  $this
    ->assertTrue($state
    ->get('entity_test_entity_create_access'));
  $this
    ->assertSame([
    'entity_type_id' => 'entity_test',
    'langcode' => LanguageInterface::LANGCODE_DEFAULT,
  ], $state
    ->get('entity_test_entity_create_access_context'));
  $this
    ->assertEquals(TRUE, $state
    ->get('entity_test_entity_test_create_access'));

  // Test hook_entity_access() and hook_ENTITY_TYPE_access().
  $entity
    ->access('view');
  $this
    ->assertTrue($state
    ->get('entity_test_entity_access'));
  $this
    ->assertTrue($state
    ->get('entity_test_entity_test_access'));
}