diff --git a/core/modules/system/src/Tests/Render/HtmlResponseAttachmentsTest.php b/core/modules/system/src/Tests/Render/HtmlResponseAttachmentsTest.php index 02497fb..d8bcddb 100644 --- a/core/modules/system/src/Tests/Render/HtmlResponseAttachmentsTest.php +++ b/core/modules/system/src/Tests/Render/HtmlResponseAttachmentsTest.php @@ -101,4 +101,26 @@ public function testAttachments() { $this->assertHeader('X-Drupal-Cache', 'HIT'); } + /** + * Test caching of ['#attached']. + */ + public function testSmartCache() { + // Make sure our test block is visible. + $this->drupalPlaceBlock('drupal_process_attached_block', ['region' => 'content']); + + // Get the front page, which should now have our visible block. + $this->drupalGet(''); + // Make sure our block is visible. + $this->assertText('Headers handled by drupal_process_attached().'); + // The header added in the block build should be present. + $this->assertHeader('X-DPA-Cache-Test', 'HIT'); + + // Reload the page, to test caching. + $this->drupalGet(''); + // Make sure our block is visible. + $this->assertText('Headers handled by drupal_process_attached().'); + // The header should be present again. + $this->assertHeader('X-DPA-Cache-Test', 'HIT'); + } + } diff --git a/core/modules/system/tests/modules/render_attached_test/render_attached_test.info.yml b/core/modules/system/tests/modules/render_attached_test/render_attached_test.info.yml index db4ff45..111fb96 100644 --- a/core/modules/system/tests/modules/render_attached_test/render_attached_test.info.yml +++ b/core/modules/system/tests/modules/render_attached_test/render_attached_test.info.yml @@ -4,3 +4,5 @@ description: 'Support module for HtmlResponseAttachmentsTest.' package: Testing version: VERSION core: 8.x +dependencies: + - block diff --git a/core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/DrupalProcessAttachedBlock.php b/core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/DrupalProcessAttachedBlock.php new file mode 100644 index 0000000..9ab5400 --- /dev/null +++ b/core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/DrupalProcessAttachedBlock.php @@ -0,0 +1,42 @@ + ['http_header' => [['X-DPA-Cache-Test', 'HIT']]]]); + // Return some arbitrary markup so the block doesn't disappear. + return ['#markup' => 'Headers handled by drupal_process_attached().']; + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return Cache::PERMANENT; + } + +}