.../modules/page_cache/src/Tests/PageCacheTest.php | 22 ++++++++++++++-------- .../src/Controller/SystemTestController.php | 7 +++++++ .../modules/system_test/system_test.routing.yml | 7 +++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/core/modules/page_cache/src/Tests/PageCacheTest.php b/core/modules/page_cache/src/Tests/PageCacheTest.php index 262ab4c..72c89ff 100644 --- a/core/modules/page_cache/src/Tests/PageCacheTest.php +++ b/core/modules/page_cache/src/Tests/PageCacheTest.php @@ -451,15 +451,25 @@ public function testCacheableResponseResponses() { // 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->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), '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->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), '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-public-response'); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.'); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=60, public', 'Cache-Control header was sent'); + + // Still not cached, uncacheable response. + $this->drupalGet('/system-test/respond-public-response'); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.'); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=60, public', '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.'); @@ -475,12 +485,8 @@ public function testCacheableResponseResponses() { ->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'); + $this->drupalGet('/respond-cacheable-reponse'); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.'); } } diff --git a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php index abd9022..9d35102 100644 --- a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php +++ b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php @@ -276,6 +276,13 @@ public function respondWithReponse(Request $request) { } /** + * A plain Symfony reponse with Cache-Control: public, max-age=60. + */ + public function respondWithPublicResponse() { + return (new Response('test'))->setPublic()->setMaxAge(60); + } + + /** * A simple page callback that uses a CacheableResponse object. */ public function respondWithCacheableReponse(Request $request) { diff --git a/core/modules/system/tests/modules/system_test/system_test.routing.yml b/core/modules/system/tests/modules/system_test/system_test.routing.yml index 94a1bef..1fb4069 100644 --- a/core/modules/system/tests/modules/system_test/system_test.routing.yml +++ b/core/modules/system/tests/modules/system_test/system_test.routing.yml @@ -137,6 +137,13 @@ system_test.respond_response: requirements: _access: 'TRUE' +system_test.respond_public_response: + path: '/system-test/respond-public-response' + defaults: + _controller: '\Drupal\system_test\Controller\SystemTestController::respondWithPublicResponse' + requirements: + _access: 'TRUE' + system_test.respond_cacheable_response: path: '/system-test/respond-cacheable-reponse' defaults: