You are here

protected function PageCacheTagsTestBase::verifyPageCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php \Drupal\system\Tests\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.

5 calls to PageCacheTagsTestBase::verifyPageCache()
CommentCacheTagsTest::testCommentEntity in core/modules/comment/src/Tests/CommentCacheTagsTest.php
Test that comments correctly invalidate the cache tag of their host entity.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
EntityWithUriCacheTagsTestBase::testEntityUri in core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity at its URI.
MenuCacheTagsTest::testMenuBlock in core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php
Tests cache tags presence and invalidation of the Menu entity.
TourCacheTagsTest::testRenderedTour in core/modules/tour/src/Tests/TourCacheTagsTest.php
Tests cache tags presence and invalidation of the Tour entity.

File

core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php, line 50
Contains \Drupal\system\Tests\Cache\PageCacheTagsTestBase.

Class

PageCacheTagsTestBase
Provides helper methods for page cache tags tests.

Namespace

Drupal\system\Tests\Cache

Code

protected function verifyPageCache(Url $url, $hit_or_miss, $tags = FALSE) {
  $this
    ->drupalGet($url);
  $message = SafeMarkup::format('Page cache @hit_or_miss for %path.', array(
    '@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)) {
    $absolute_url = $url
      ->setAbsolute()
      ->toString();
    $cid_parts = array(
      $absolute_url,
      'html',
    );
    $cid = implode(':', $cid_parts);
    $cache_entry = \Drupal::cache('render')
      ->get($cid);
    sort($cache_entry->tags);
    $tags = array_unique($tags);
    sort($tags);
    $this
      ->assertIdentical($cache_entry->tags, $tags);
  }
}