function PageCacheTest::testPageCacheWithoutVaryCookie
Tests the omit_vary_cookie setting.
File
- 
              core/
modules/ page_cache/ tests/ src/ Functional/ PageCacheTest.php, line 405  
Class
- PageCacheTest
 - Enables the page cache and tests it with various HTTP requests.
 
Namespace
Drupal\Tests\page_cache\FunctionalCode
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->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', 'MISS');
  $this->assertSession()
    ->responseHeaderNotContains('Vary', 'cookie');
  $this->assertSession()
    ->responseHeaderEquals('Cache-Control', 'max-age=300, public');
  // Check cache.
  $this->drupalGet('');
  $this->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', 'HIT');
  $this->assertSession()
    ->responseHeaderNotContains('Vary', 'cookie');
  $this->assertSession()
    ->responseHeaderEquals('Cache-Control', 'max-age=300, public');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.