You are here

protected static function ResourceTestBase::entityAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityAccess()
  2. 9 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.

File

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

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