You are here

public function PageCacheTest::testPageCacheWithoutVaryCookie in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/page_cache/src/Tests/PageCacheTest.php \Drupal\page_cache\Tests\PageCacheTest::testPageCacheWithoutVaryCookie()

Tests the omit_vary_cookie setting.

File

core/modules/page_cache/src/Tests/PageCacheTest.php, line 388
Contains \Drupal\page_cache\Tests\PageCacheTest.

Class

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

Namespace

Drupal\page_cache\Tests

Code

public function testPageCacheWithoutVaryCookie() {
  $config = $this
    ->config('system.performance');
  $config
    ->set('cache.page.max_age', 300);
  $config
    ->save();
  $settings['settings']['omit_vary_cookie'] = (object) array(
    'value' => TRUE,
    'required' => TRUE,
  );
  $this
    ->writeSettings($settings);

  // Fill the cache.
  $this
    ->drupalGet('');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
  $this
    ->assertTrue(strpos($this
    ->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');

  // Check cache.
  $this
    ->drupalGet('');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
  $this
    ->assertTrue(strpos($this
    ->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
}