public function EntityAccessControlHandlerTest::testDefaultEntityAccess in Drupal 9
Same name and namespace in other branches
- 8 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 153
Class
- EntityAccessControlHandlerTest
- Tests the entity access control handler.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testDefaultEntityAccess() {
// Set up a non-admin user that is allowed to view test entities.
\Drupal::currentUser()
->setAccount($this
->createUser([
'uid' => 2,
], [
'view test entity',
]));
$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);
}