diff --git a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php index 63a7e97..16c6c6a 100644 --- a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php @@ -26,6 +26,8 @@ class AggregatorRenderingTest extends AggregatorTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); + $this->drupalPlaceBlock('page_title_block'); } diff --git a/core/modules/block/src/Tests/BlockInstallTest.php b/core/modules/block/src/Tests/BlockInstallTest.php index 84819e6..2e49440 100644 --- a/core/modules/block/src/Tests/BlockInstallTest.php +++ b/core/modules/block/src/Tests/BlockInstallTest.php @@ -16,6 +16,16 @@ */ class BlockInstallTest extends WebTestBase { + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->enableCacheHeaders(); + } + + public function testCacheTagInvalidationUponInstallation() { // Warm the page cache. $this->drupalGet(''); diff --git a/core/modules/block/src/Tests/BlockSystemBrandingTest.php b/core/modules/block/src/Tests/BlockSystemBrandingTest.php index a78f675..5cda4f6 100644 --- a/core/modules/block/src/Tests/BlockSystemBrandingTest.php +++ b/core/modules/block/src/Tests/BlockSystemBrandingTest.php @@ -26,6 +26,9 @@ class BlockSystemBrandingTest extends BlockTestBase { */ protected function setUp() { parent::setUp(); + + $this->enableCacheHeaders(); + // Set a site slogan. $this->config('system.site') ->set('slogan', 'Community plumbing') diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/src/Tests/Views/DisplayBlockTest.php index f7b3ffe..29f55b3 100644 --- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php +++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php @@ -43,6 +43,7 @@ class DisplayBlockTest extends ViewTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); ViewTestData::createTestViews(get_class($this), array('block_test_views')); $this->enableViewsTestModule(); } diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index b1c9fa3..a5fcf14 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -69,6 +69,7 @@ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('system_breadcrumb_block'); $this->drupalPlaceBlock('page_title_block'); + $this->enableCacheHeaders(); // node_access_test requires a node_access_rebuild(). node_access_rebuild(); diff --git a/core/modules/comment/src/Tests/CommentAnonymousTest.php b/core/modules/comment/src/Tests/CommentAnonymousTest.php index b7e5bd8..57b4846 100644 --- a/core/modules/comment/src/Tests/CommentAnonymousTest.php +++ b/core/modules/comment/src/Tests/CommentAnonymousTest.php @@ -19,6 +19,7 @@ class CommentAnonymousTest extends CommentTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // Enable anonymous and authenticated user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array( 'access comments', diff --git a/core/modules/comment/src/Tests/CommentCacheTagsTest.php b/core/modules/comment/src/Tests/CommentCacheTagsTest.php index 15142d8..946bdf9 100644 --- a/core/modules/comment/src/Tests/CommentCacheTagsTest.php +++ b/core/modules/comment/src/Tests/CommentCacheTagsTest.php @@ -46,6 +46,7 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // Give anonymous users permission to view comments, so that we can verify // the cache tags of cached versions of comment pages. $user_role = Role::load(RoleInterface::ANONYMOUS_ID); diff --git a/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php b/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php index 22d0b11..aa4b73d 100644 --- a/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php +++ b/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php @@ -30,6 +30,7 @@ class CacheabilityMetadataConfigOverrideIntegrationTest extends WebTestBase { public function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // @todo If our block does not contain any content then the cache context // is not bubbling up and the test fails. Remove this line once the cache // contexts are properly set. See https://www.drupal.org/node/2529980. diff --git a/core/modules/contact/src/Tests/ContactPersonalTest.php b/core/modules/contact/src/Tests/ContactPersonalTest.php index d133240..3c5e3d2 100644 --- a/core/modules/contact/src/Tests/ContactPersonalTest.php +++ b/core/modules/contact/src/Tests/ContactPersonalTest.php @@ -51,6 +51,8 @@ class ContactPersonalTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); + // Create an admin user. $this->adminUser = $this->drupalCreateUser(array('administer contact forms', 'administer users', 'administer account settings', 'access site reports')); diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index 39cd34a..b3480db 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -38,6 +38,8 @@ class ContactSitewideTest extends WebTestBase { */ protected function setUp() { parent::setUp(); + + $this->enableCacheHeaders(); $this->drupalPlaceBlock('system_breadcrumb_block'); $this->drupalPlaceBlock('local_actions_block'); $this->drupalPlaceBlock('page_title_block'); diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php index baa9aaa..52bc0a6 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php @@ -63,7 +63,6 @@ protected function setUp() { $this->enableCacheHeaders(); } - /** * Tests the basic translation UI. */ diff --git a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php index b602be0..0507aac 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php @@ -35,6 +35,8 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase { protected function setUp() { parent::setUp(); + + $this->enableCacheHeaders(); $this->setupEntity(); } diff --git a/core/modules/forum/src/Tests/ForumIndexTest.php b/core/modules/forum/src/Tests/ForumIndexTest.php index e84a3eb..c24315a 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -26,6 +26,7 @@ class ForumIndexTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // Create a test user. $web_user = $this->drupalCreateUser(['create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes', 'administer forums']); $this->drupalLogin($web_user); diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 974e400..475eb0b 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -82,6 +82,7 @@ class ForumTest extends WebTestBase { */ protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->drupalPlaceBlock('system_breadcrumb_block'); $this->drupalPlaceBlock('page_title_block'); diff --git a/core/modules/history/src/Tests/HistoryTest.php b/core/modules/history/src/Tests/HistoryTest.php index 3340f1a..892a60f 100644 --- a/core/modules/history/src/Tests/HistoryTest.php +++ b/core/modules/history/src/Tests/HistoryTest.php @@ -41,6 +41,7 @@ class HistoryTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $this->user = $this->drupalCreateUser(array('create page content', 'access content')); diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index c4cf485..444a4f2 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -29,6 +29,15 @@ class ImageFieldDisplayTest extends ImageFieldTestBase { public static $modules = array('field_ui'); /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->enableCacheHeaders(); + } + + /** * Test image formatters on node display for public files. */ function testImageFieldFormattersPublic() { diff --git a/core/modules/menu_ui/src/Tests/MenuNodeTest.php b/core/modules/menu_ui/src/Tests/MenuNodeTest.php index b3397cc..694c2c3 100644 --- a/core/modules/menu_ui/src/Tests/MenuNodeTest.php +++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php @@ -34,6 +34,7 @@ class MenuNodeTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->drupalPlaceBlock('system_menu_block:main'); $this->drupalPlaceBlock('page_title_block'); diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 326db81..b7f17b5 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -70,6 +70,7 @@ class MenuTest extends MenuWebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->drupalPlaceBlock('page_title_block'); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); diff --git a/core/modules/node/src/Tests/NodeTypeTest.php b/core/modules/node/src/Tests/NodeTypeTest.php index a8fa54d..92ad3c0 100644 --- a/core/modules/node/src/Tests/NodeTypeTest.php +++ b/core/modules/node/src/Tests/NodeTypeTest.php @@ -26,6 +26,15 @@ class NodeTypeTest extends NodeTestBase { public static $modules = ['field_ui']; /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->enableCacheHeaders(); + } + + /** * Ensures that node type functions (node_type_get_*) work correctly. * * Load available node types and validate the returned data. diff --git a/core/modules/node/src/Tests/Views/FrontPageTest.php b/core/modules/node/src/Tests/Views/FrontPageTest.php index 5cd78a8..9ecc91f 100644 --- a/core/modules/node/src/Tests/Views/FrontPageTest.php +++ b/core/modules/node/src/Tests/Views/FrontPageTest.php @@ -47,6 +47,7 @@ class FrontPageTest extends ViewTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->nodeStorage = $this->container->get('entity.manager') ->getStorage('node'); } diff --git a/core/modules/page_cache/src/Tests/PageCacheTest.php b/core/modules/page_cache/src/Tests/PageCacheTest.php index a2278e7..0b833b9 100644 --- a/core/modules/page_cache/src/Tests/PageCacheTest.php +++ b/core/modules/page_cache/src/Tests/PageCacheTest.php @@ -37,6 +37,7 @@ class PageCacheTest extends WebTestBase { protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); $this->config('system.site') ->set('name', 'Drupal') ->set('page.front', '/test-page') diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index b42831b..d5932a7 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -43,6 +43,7 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase { */ protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // Create user. $this->adminUser = $this->drupalCreateUser(array( diff --git a/core/modules/rest/src/Tests/PageCacheTest.php b/core/modules/rest/src/Tests/PageCacheTest.php index 3ae0084..ea943e9 100644 --- a/core/modules/rest/src/Tests/PageCacheTest.php +++ b/core/modules/rest/src/Tests/PageCacheTest.php @@ -22,6 +22,15 @@ class PageCacheTest extends RESTTestBase { public static $modules = array('hal', 'rest', 'entity_test'); /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->enableCacheHeaders(); + } + + /** * Tests that configuration changes also clear the page cache. */ public function testConfigChangePageCache() { diff --git a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php b/core/modules/search/src/Tests/SearchPageCacheTagsTest.php index 6a74718..026db6c 100644 --- a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php +++ b/core/modules/search/src/Tests/SearchPageCacheTagsTest.php @@ -40,6 +40,7 @@ class SearchPageCacheTagsTest extends SearchTestBase { */ protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); // Create user. $this->searchingUser = $this->drupalCreateUser(array('search content', 'access user profiles')); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 8c88f40..21ad1f9 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -3003,4 +3003,17 @@ protected function assertNoCacheTag($cache_tag) { $this->assertFalse(in_array($cache_tag, $cache_tags), "'" . $cache_tag . "' is absent in the X-Drupal-Cache-Tags header."); } + /** + * Writes the needed cache headers. + */ + protected function enableCacheHeaders() { + // Send cacheability headers so tests can check their values. + $settings['settings']['send_cacheability_headers'] = (object) [ + 'value' => TRUE, + 'required' => TRUE, + ]; + + $this->writeSettings($settings); + } + } diff --git a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php index cb9c398..ff914f3 100644 --- a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php +++ b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php @@ -18,19 +18,6 @@ trait AssertPageCacheContextsAndTagsTrait { /** - * Writes the needed cache headers. - */ - protected function enableCacheHeaders() { - // Send cacheability headers so tests can check their values. - $settings['settings']['send_cacheability_headers'] = (object) [ - 'value' => TRUE, - 'required' => TRUE, - ]; - - $this->writeSettings($settings); - } - - /** * Enables page caching. */ protected function enablePageCaching() { diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php b/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php index b4f40bd..5c5f762 100644 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php @@ -29,6 +29,8 @@ protected function setUp() { parent::setUp(); + $this->enableCacheHeaders(); + // Enable page caching. $config = $this->config('system.performance'); $config->set('cache.page.max_age', 3600);