You are here

public function PageCacheTest::testPageCacheTagsIndependentFromCacheabilityHeaders in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testPageCacheTagsIndependentFromCacheabilityHeaders()

Test that the page cache doesn't depend on cacheability headers.

File

core/modules/page_cache/tests/src/Functional/PageCacheTest.php, line 89

Class

PageCacheTest
Enables the page cache and tests it with various HTTP requests.

Namespace

Drupal\Tests\page_cache\Functional

Code

public function testPageCacheTagsIndependentFromCacheabilityHeaders() {

  // Disable the cacheability headers.
  $this
    ->setContainerParameter('http.response.debug_cacheability_headers', FALSE);
  $this
    ->rebuildContainer();
  $this
    ->resetAll();
  $path = 'system-test/cache_tags_page';
  $tags = [
    'system_test_cache_tags_page',
  ];
  $this
    ->drupalGet($path);
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'MISS');

  // Verify a cache hit, but also the presence of the correct cache tags.
  $this
    ->drupalGet($path);
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'HIT');
  $cid_parts = [
    Url::fromRoute('system_test.cache_tags_page', [], [
      'absolute' => TRUE,
    ])
      ->toString(),
    '',
  ];
  $cid = implode(':', $cid_parts);
  $cache_entry = \Drupal::cache('page')
    ->get($cid);
  sort($cache_entry->tags);
  $expected_tags = [
    'config:user.role.anonymous',
    'http_response',
    'pre_render',
    'rendered',
    'system_test_cache_tags_page',
  ];
  $this
    ->assertIdentical($cache_entry->tags, $expected_tags);
  Cache::invalidateTags($tags);
  $this
    ->drupalGet($path);
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'MISS');
}