You are here

protected function LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::verifyPageCacheContainsTags in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::verifyPageCacheContainsTags()
  2. 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::verifyPageCacheContainsTags()

Verify that when loading a given page, it's a page cache hit or miss.

Parameters

\Drupal\Core\Url $url: The page for this URL will be loaded.

string $hit_or_miss: 'HIT' if a page cache hit is expected, 'MISS' otherwise.

array|false $tags: When expecting a page cache hit, you may optionally specify an array of expected cache tags. While FALSE, the cache tags will not be verified. This tests whether all expected tags are in the page cache tags, not that expected tags and page cache tags are identical.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php, line 128

Class

LayoutBuilderFieldBlockEntityReferenceCacheTagsTest
Tests cache tags on entity reference field blocks in Layout Builder.

Namespace

Drupal\Tests\layout_builder\Functional

Code

protected function verifyPageCacheContainsTags(Url $url, $hit_or_miss, $tags = FALSE) {
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', $hit_or_miss);
  if ($hit_or_miss === 'HIT' && is_array($tags)) {
    $cache_tags = explode(' ', $this
      ->getSession()
      ->getResponseHeader('X-Drupal-Cache-Tags'));
    $tags = array_unique($tags);
    $this
      ->assertEmpty(array_diff($tags, $cache_tags), 'Page cache tags contains all expected tags.');
  }
}