You are here

public function EntityAccessControlHandlerTest::testHooks in Drupal 8

Same name and namespace in other branches
  1. 9 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
    ->assertEqual($state
    ->get('entity_test_entity_create_access'), TRUE);
  $this
    ->assertIdentical($state
    ->get('entity_test_entity_create_access_context'), [
    'entity_type_id' => 'entity_test',
    'langcode' => LanguageInterface::LANGCODE_DEFAULT,
  ]);
  $this
    ->assertEqual($state
    ->get('entity_test_entity_test_create_access'), TRUE);

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