You are here

public function EntityAccessControlHandlerTest::testDefaultEntityAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testDefaultEntityAccess()
  2. 9 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()

entity_test_entity_access()

File

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

Class

EntityAccessControlHandlerTest
Tests the entity access control handler.

Namespace

Drupal\KernelTests\Core\Entity

Code

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);
}