function EntityAccessControlHandlerTest::testHooks
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testHooks()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testHooks()
- 11.x 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 281
Class
- EntityAccessControlHandlerTest
- Tests the entity access control handler.
Namespace
Drupal\KernelTests\Core\EntityCode
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'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.