function DisplayFeedTest::testFeedCacheability

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedCacheability()

Tests the cacheability of the feed display.

File

core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php, line 210

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFeedCacheability() : void {
  // Test as an anonymous user.
  $this->drupalLogout();
  // Set the page cache max age to a value greater than zero.
  $config = $this->config('system.performance');
  $config->set('cache.page.max_age', 300);
  $config->save();
  // Uninstall all page cache modules that could cache the HTTP response
  // headers.
  \Drupal::service('module_installer')->uninstall([
    'page_cache',
    'dynamic_page_cache',
  ]);
  // Reset all so that the config and module changes are active.
  $this->resetAll();
  $url = 'test-feed-display.xml';
  $this->drupalGet($url);
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->responseHeaderEquals('Cache-Control', 'max-age=300, public');
  $this->assertSession()
    ->responseHeaderEquals('Content-Type', 'application/rss+xml; charset=utf-8');
  // Visit the page again to get the cached response.
  $this->drupalGet($url);
  $this->assertSession()
    ->responseHeaderEquals('Cache-Control', 'max-age=300, public');
  $this->assertSession()
    ->responseHeaderEquals('Content-Type', 'application/rss+xml; charset=utf-8');
}

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