Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()
  2. 9 core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()

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.

7 calls to PageCacheTagsTestBase::verifyPageCache()
CommentCacheTagsTest::testCommentEntity in core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
Tests that comments invalidate the cache tag of their host entity.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
EntityWithUriCacheTagsTestBase::testEntityUri in core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity at its URI.
MenuCacheTagsTest::testMenuBlock in core/modules/menu_ui/tests/src/Functional/MenuCacheTagsTest.php
Tests cache tags presence and invalidation of the Menu entity.
ShortcutsNavigationBlockTest::testNavigationBlock in core/modules/navigation/tests/src/Functional/ShortcutsNavigationBlockTest.php
Tests visibility and cacheability of shortcuts in the navigation bar.

... See full list

File

core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php, line 38

Class

PageCacheTagsTestBase
Provides helper methods for page cache tags tests.

Namespace

Drupal\Tests\system\Functional\Cache

Code

protected function verifyPageCache(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)) {
    $absolute_url = $url
      ->setAbsolute()
      ->toString();
    $cid_parts = [
      $absolute_url,
      '',
    ];
    $cid = implode(':', $cid_parts);
    $cache_entry = \Drupal::cache('page')
      ->get($cid);
    sort($cache_entry->tags);
    $tags = array_unique($tags);
    sort($tags);
    $this
      ->assertSame($cache_entry->tags, $tags);
  }
}