You are here

protected function LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::verifyPageCacheContainsTags in Drupal 8

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

1 call to LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::verifyPageCacheContainsTags()
LayoutBuilderFieldBlockEntityReferenceCacheTagsTest::testEntityReferenceFieldBlockCaching in core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockEntityReferenceCacheTagsTest.php
Tests cache tags on field block for entity reference field.

File

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

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);
  $message = new FormattableMarkup('Page cache @hit_or_miss for %path.', [
    '@hit_or_miss' => $hit_or_miss,
    '%path' => $url
      ->toString(),
  ]);
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message);
  if ($hit_or_miss === 'HIT' && is_array($tags)) {
    $cache_tags = explode(' ', $this
      ->drupalGetHeader('X-Drupal-Cache-Tags'));
    $tags = array_unique($tags);
    $this
      ->assertEmpty(array_diff($tags, $cache_tags), 'Page cache tags contains all expected tags.');
  }
}