core/modules/block/src/Tests/BlockSystemBrandingTest.php | 15 +++++---------- core/modules/book/src/Tests/BookTest.php | 3 +-- core/modules/comment/src/Tests/CommentAnonymousTest.php | 3 +-- core/modules/contact/src/Tests/ContactSitewideTest.php | 3 +-- core/modules/forum/src/Tests/ForumTest.php | 6 ++---- core/modules/simpletest/src/WebTestBase.php | 12 ++++++++++++ core/modules/user/src/Tests/UserLoginTest.php | 3 +-- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/core/modules/block/src/Tests/BlockSystemBrandingTest.php b/core/modules/block/src/Tests/BlockSystemBrandingTest.php index 7335350..57ebc85 100644 --- a/core/modules/block/src/Tests/BlockSystemBrandingTest.php +++ b/core/modules/block/src/Tests/BlockSystemBrandingTest.php @@ -38,11 +38,6 @@ protected function setUp() { * Tests system branding block configuration. */ public function testSystemBrandingSettings() { - $assert_cache_tags = function() { - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:system.site', $cache_tags)); - }; - $site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]'; $site_name_xpath = '//div[@id="block-site-branding"]//div[@class="site-name"]'; $site_slogan_xpath = '//div[@id="block-site-branding"]//div[@class="site-slogan"]'; @@ -56,7 +51,7 @@ public function testSystemBrandingSettings() { $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.'); $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.'); - $assert_cache_tags(); + $this->assertCacheTag('config:system.site'); // Turn just the logo off. $this->config('block.block.site-branding') @@ -70,7 +65,7 @@ public function testSystemBrandingSettings() { $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.'); $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.'); $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.'); - $assert_cache_tags(); + $this->assertCacheTag('config:system.site'); // Turn just the site name off. $this->config('block.block.site-branding') @@ -85,7 +80,7 @@ public function testSystemBrandingSettings() { $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.'); $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.'); - $assert_cache_tags(); + $this->assertCacheTag('config:system.site'); // Turn just the site slogan off. $this->config('block.block.site-branding') @@ -100,7 +95,7 @@ public function testSystemBrandingSettings() { $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.'); $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.'); - $assert_cache_tags(); + $this->assertCacheTag('config:system.site'); // Turn the site name and the site slogan off. $this->config('block.block.site-branding') @@ -115,7 +110,7 @@ public function testSystemBrandingSettings() { $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.'); $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.'); - $assert_cache_tags(); + $this->assertCacheTag('config:system.site'); } } diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index fff456b..af8c107 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -83,8 +83,7 @@ function testCacheTags() { $this->drupalLogin($this->bookAuthor); $this->drupalGet('node/add/book'); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:book.settings', $cache_tags)); + $this->assertCacheTag('config:book.settings'); } /** diff --git a/core/modules/comment/src/Tests/CommentAnonymousTest.php b/core/modules/comment/src/Tests/CommentAnonymousTest.php index 7c8bd9a..75afe02 100644 --- a/core/modules/comment/src/Tests/CommentAnonymousTest.php +++ b/core/modules/comment/src/Tests/CommentAnonymousTest.php @@ -35,8 +35,7 @@ protected function setUp() { */ function testCacheTags() { $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:user.settings', $cache_tags)); + $this->assertCacheTag('config:user.settings'); } /** diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index fcde3c6..f23258b 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -47,8 +47,7 @@ function testCacheTags() { $this->drupalLogin($this->drupalCreateUser(array('access site-wide contact form'))); $this->drupalGet('contact'); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:contact.settings', $cache_tags)); + $this->assertCacheTag('config:contact.settings'); } /** diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 2608de5..7ede0d1 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -115,12 +115,10 @@ protected function setUp() { */ function testCacheTags() { $this->drupalGet(Url::fromRoute('forum.index')); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:forum.settings', $cache_tags)); + $this->assertCacheTag('config:forum.settings'); $this->drupalGet(Url::fromRoute('forum.page', ['taxonomy_term' => 1])); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array('config:forum.settings', $cache_tags)); + $this->assertCacheTag('config:forum.settings'); } /** diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index e27b690..d66ed98 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -2728,4 +2728,16 @@ protected function buildUrl($path, array $options = array()) { return $this->getAbsoluteUrl($path); } } + + /** + * Asserts whether an expected cache tag was present in the last response. + * + * @param string $expected_cache_tag + * The expected cache tag. + */ + protected function assertCacheTag($expected_cache_tag) { + $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); + $this->assertTrue(in_array($expected_cache_tag, $cache_tags)); + } + } diff --git a/core/modules/user/src/Tests/UserLoginTest.php b/core/modules/user/src/Tests/UserLoginTest.php index 6f85658..3b17163 100644 --- a/core/modules/user/src/Tests/UserLoginTest.php +++ b/core/modules/user/src/Tests/UserLoginTest.php @@ -22,10 +22,9 @@ class UserLoginTest extends WebTestBase { */ function testCacheTags() { $this->drupalGet('user/login'); - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); // The user login form says "Enter your username.", hence it // depends on config:system.site, and its cache tags should be present. - $this->assertTrue(in_array('config:system.site', $cache_tags)); + $this->assertCacheTag('config:system.site'); } /**