1 views_cache.test ViewsCacheTest::testHttpHeadersCaching()

Check that HTTP headers are cached for views.

File

core/modules/views/tests/views_cache.test, line 207
Definition of ViewsCacheTest.

Class

ViewsCacheTest
Basic test for pluggable caching.

Code

function testHttpHeadersCaching() {
  // Create a few nodes to appear in RSS feed.
  for ($i = 0; $i < 5; $i++) {
    $this->backdropCreateNode();
  }

  // Make the first request and check returned content type.
  $this->backdropGet('test_feed_http_headers_caching');
  $first_content = $this->backdropGetContent();
  $first_content_type = $this->backdropGetHeader('content-type');
  $expected_type = 'application/rss+xml';
  $this->assertIdentical(0, strpos(trim($first_content_type), $expected_type), t('Expected content type returned.'));

  // Check that we have 7 items in RSS feed returned by the first request.
  $xml = simplexml_load_string($first_content);
  $items = $xml->xpath('/rss/channel/item');
  $this->assertEqual(5, count($items), t('The number of RSS feed items matched.'));

  // Create another node to be sure we get cached results on the second
  // request.
  $this->backdropCreateNode();

  // Make the second request, check content type and content matching.
  $this->backdropGet('test_feed_http_headers_caching');
  $second_content = $this->backdropGetContent();
  $this->assertEqual($first_content, $second_content, t('The second result fetched from cache.'));
  $second_content_type = $this->backdropGetHeader('content-type');
  $this->assertEqual($first_content_type, $second_content_type, t('Content types of responses are equal.'));
}