function EntityAccessControlHandlerTest::testDefaultEntityAccess
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testDefaultEntityAccess()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testDefaultEntityAccess()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testDefaultEntityAccess()
Ensures default entity access is checked when necessary.
This ensures that the default checkAccess() implementation of the entity access control handler is considered if hook_entity_access() has not explicitly forbidden access. Therefore the default checkAccess() implementation can forbid access, even after access was already explicitly allowed by hook_entity_access().
See also
\Drupal\entity_test\EntityTestAccessControlHandler::checkAccess()
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityAccessControlHandlerTest.php, line 157
Class
- EntityAccessControlHandlerTest
- Tests the entity access control handler.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testDefaultEntityAccess() : void {
// Set up a non-admin user that is allowed to view test entities.
\Drupal::currentUser()->setAccount($this->createUser([
'view test entity',
], NULL, FALSE, [
'uid' => 2,
]));
$entity = EntityTest::create([
'name' => 'forbid_access',
]);
// The user is denied access to the entity.
$this->assertEntityAccess([
'create' => FALSE,
'update' => FALSE,
'delete' => FALSE,
'view' => FALSE,
], $entity);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.