You are here

protected function ResourceTestBase::getExpectedCacheContexts 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::getExpectedCacheContexts()
  2. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getExpectedCacheContexts()

The expected cache contexts for the GET/HEAD response of the test entity.

Parameters

array|null $sparse_fieldset: If a sparse fieldset is being requested, limit the expected cache contexts for this entity's fields to just these fields.

Return value

string[] A set of cache contexts.

See also

::testGetIndividual()

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
  $cache_contexts = [
    // Cache contexts for JSON:API URL query parameters.
    'url.query_args:fields',
    'url.query_args:include',
    // Drupal defaults.
    'url.site',
    'user.permissions',
  ];
  $entity_type = $this->entity
    ->getEntityType();
  return Cache::mergeContexts($cache_contexts, $entity_type
    ->isRevisionable() ? [
    'url.query_args:resourceVersion',
  ] : []);
}