You are here

protected static function ResourceTestBase::entityAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityAccess()

Checks access for the given operation on the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check field access.

string $operation: The operation for which to check access.

\Drupal\Core\Session\AccountInterface $account: The account for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The AccessResult.

4 calls to ResourceTestBase::entityAccess()
CommentTest::entityAccess in core/modules/jsonapi/tests/src/Functional/CommentTest.php
Checks access for the given operation on the given entity.
ResourceTestBase::doTestSparseFieldSets in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests sparse field sets.
ResourceTestBase::entityFieldAccess in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Checks access for the given field operation on the given entity.
ResourceTestBase::getExpectedCollectionCacheability in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Computes the cacheability for a given entity collection.
3 methods override ResourceTestBase::entityAccess()
CommentTest::entityAccess in core/modules/jsonapi/tests/src/Functional/CommentTest.php
Checks access for the given operation on the given entity.
EditorTest::entityAccess in core/modules/jsonapi/tests/src/Functional/EditorTest.php
Checks access for the given operation on the given entity.
FieldConfigTest::entityAccess in core/modules/jsonapi/tests/src/Functional/FieldConfigTest.php
Checks access for the given operation on the given entity.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 3387

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function entityAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  // The default entity access control handler assumes that permissions do not
  // change during the lifetime of a request and caches access results.
  // However, we're changing permissions during a test run and need fresh
  // results, so reset the cache.
  \Drupal::entityTypeManager()
    ->getAccessControlHandler($entity
    ->getEntityTypeId())
    ->resetCache();
  return $entity
    ->access($operation, $account, TRUE);
}