function PageCacheTest::testPageCacheWithoutVaryCookie

Same name in other branches
  1. 9 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testPageCacheWithoutVaryCookie()
  2. 10 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testPageCacheWithoutVaryCookie()
  3. 11.x core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testPageCacheWithoutVaryCookie()

Tests the omit_vary_cookie setting.

File

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

Class

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

Namespace

Drupal\Tests\page_cache\Functional

Code

public function testPageCacheWithoutVaryCookie() {
    $config = $this->config('system.performance');
    $config->set('cache.page.max_age', 300);
    $config->save();
    $settings['settings']['omit_vary_cookie'] = (object) [
        '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->assertStringNotContainsString('cookie', $this->drupalGetHeader('Vary'), 'Vary: Cookie header was not sent.', TRUE);
    $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->assertStringNotContainsString('cookie', $this->drupalGetHeader('Vary'), 'Vary: Cookie header was not sent.', TRUE);
    $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.