You are here

public function EntityAccessControlHandlerTest::testEntityAccessDefaultController 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::testEntityAccessDefaultController()

Ensures that the default handler is used as a fallback.

File

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

Class

EntityAccessControlHandlerTest
Tests the entity access control handler.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityAccessDefaultController() {

  // The implementation requires that the global user id can be loaded.
  \Drupal::currentUser()
    ->setAccount($this
    ->createUser([
    'uid' => 2,
  ]));

  // Check that the default access control handler is used for entities that don't
  // have a specific access control handler defined.
  $handler = $this->container
    ->get('entity_type.manager')
    ->getAccessControlHandler('entity_test_default_access');
  $this
    ->assertInstanceOf(EntityAccessControlHandler::class, $handler);
  $entity = EntityTestDefaultAccess::create();
  $this
    ->assertEntityAccess([
    'create' => FALSE,
    'update' => FALSE,
    'delete' => FALSE,
    'view' => FALSE,
  ], $entity);
}