summaryrefslogtreecommitdiffstats
path: root/core/modules/page_cache/src/Tests/PageCacheTest.php
diff options
context:
space:
mode:
authoreffulgentsia2015-10-05 22:09:09 (GMT)
committereffulgentsia2015-10-05 22:09:09 (GMT)
commit866be5fb95ab375c10d2e9884d628b44ac228296 (patch)
tree8fba56e0c33d46a5da232ce3bf3d249f506fcc2a /core/modules/page_cache/src/Tests/PageCacheTest.php
parentd5c827e43c567c771c4d91aa0afda87bdbebf670 (diff)
Issue #2476407 by borisson_, hussainweb, znerol, Fabianx, Wim Leers, dawehner, Crell, Berdir: Use CacheableResponseInterface to determine which responses should be cached
Diffstat (limited to 'core/modules/page_cache/src/Tests/PageCacheTest.php')
-rw-r--r--core/modules/page_cache/src/Tests/PageCacheTest.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/modules/page_cache/src/Tests/PageCacheTest.php b/core/modules/page_cache/src/Tests/PageCacheTest.php
index 18a6dfd..a2278e7 100644
--- a/core/modules/page_cache/src/Tests/PageCacheTest.php
+++ b/core/modules/page_cache/src/Tests/PageCacheTest.php
@@ -406,4 +406,50 @@ class PageCacheTest extends WebTestBase {
$this->assertText("Immutable: FALSE", "Form is not immutable,");
}
+ /**
+ * Tests cacheability of a CacheableResponse.
+ *
+ * Tests the difference between having a controller return a plain Symfony
+ * Response object versus returning a Response object that implements the
+ * CacheableResponseInterface.
+ */
+ public function testCacheableResponseResponses() {
+ $config = $this->config('system.performance');
+ $config->set('cache.page.max_age', 300);
+ $config->save();
+
+ // Try to fill the cache.
+ $this->drupalGet('/system-test/respond-reponse');
+ $this->assertFalse(in_array('X-Drupal-Cache', $this->drupalGetHeaders()), 'Drupal page cache header not found');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
+
+ // Still not cached, uncacheable response.
+ $this->drupalGet('/system-test/respond-reponse');
+ $this->assertFalse(in_array('X-Drupal-Cache', $this->drupalGetHeaders()), 'Drupal page cache header not found');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
+
+ // Try to fill the cache.
+ $this->drupalGet('/system-test/respond-cacheable-reponse');
+ $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
+
+ // Should be cached now.
+ $this->drupalGet('/system-test/respond-cacheable-reponse');
+ $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
+
+ // Uninstall page cache. This should flush all caches so the next call to a
+ // previously cached page should be a miss now.
+ $this->container->get('module_installer')
+ ->uninstall(['page_cache']);
+
+ // Try to fill the cache.
+ $this->drupalGet('/system-test/respond-reponse');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
+
+ // Still not cached, uncacheable response.
+ $this->drupalGet('/system-test/respond-reponse');
+ $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
+ }
+
}