diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index ba99651..23f4704 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -80,10 +80,10 @@ public static function mergeTags($a = array(), $b = array()) { */ public static function mergeMaxAges($a = Cache::PERMANENT, $b = Cache::PERMANENT) { // If one of the values is Cache::PERMANENT, return the other value. - if ($a == Cache::PERMANENT){ + if ($a === Cache::PERMANENT){ return $b; } - if ($b == Cache::PERMANENT){ + if ($b === Cache::PERMANENT){ return $a; } diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index c20d9a6..086a826 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -371,7 +371,6 @@ public function resetCache(array $entities = NULL) { $tags = Cache::mergeTags($tags, $entity->getCacheTags()); $tags = Cache::mergeTags($tags, $entity->getEntityType()->getListCacheTags()); } - $tags = Cache::mergeTags($tags); Cache::invalidateTags($tags); } else { diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 9fd3ba0..4266fd4 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -49,14 +49,13 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $configuration = $plugin->getConfiguration(); $cache_tags = Cache::mergeTags( - $this->getCacheTags(), // Block view builder cache tag. - $entity->getCacheTags() // Block entity cache tag. + $this->getCacheTags(), + $entity->getCacheTags() ); $cache_tags = Cache::mergeTags( $cache_tags, - $plugin->getCacheTags() // Block plugin cache tags. + $plugin->getCacheTags() ); - $cache_tags = Cache::mergeTags($cache_tags); // Create the render array for the block as a whole. // @see template_preprocess_block(). diff --git a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php index 1590640..c3a07c4 100644 --- a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php +++ b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php @@ -93,14 +93,12 @@ public function testBlock() { $expected_block_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']; $expected_block_cache_tags = Cache::mergeTags(['block_view', 'rendered'], $block->getCacheTags()); $expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags, $block->getPlugin()->getCacheTags()); - $expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags); // Expected contexts and tags for the BlockContent entity. // @see \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults(). $expected_entity_cache_contexts = ['theme']; $expected_entity_cache_tags = Cache::mergeTags(['block_content_view'], $this->entity->getCacheTags()); $expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags); // Verify that what was render cached matches the above expectations. $cid = $this->createCacheId($expected_block_cache_keys, $expected_block_cache_contexts); diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index edc4889..351447d 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -371,7 +371,6 @@ public function testReferencedEntity() { $referencing_entity_cache_tags, ['rendered'] ); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags); $non_referencing_entity_cache_tags = Cache::mergeTags( $this->nonReferencingEntity->getCacheTags(), @@ -381,7 +380,6 @@ public function testReferencedEntity() { $non_referencing_entity_cache_tags, ['rendered'] ); - $non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags); // Generate the cache tags for all two possible entity listing paths. // 1. list cache tag only (listing query has no match) @@ -408,7 +406,6 @@ public function testReferencedEntity() { $this->verifyPageCache($referencing_entity_url, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. - $expectedTags = []; $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); $expectedTags = Cache::mergeTags($expectedTags, $page_cache_tags_referencing_entity); $this->verifyPageCache($referencing_entity_url, 'HIT', $expectedTags); @@ -440,7 +437,6 @@ public function testReferencedEntity() { $this->verifyPageCache($listing_url, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. - $expectedTags = []; $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); $expectedTags = Cache::mergeTags($expectedTags, $page_cache_tags_referencing_entity); $this->verifyPageCache($listing_url, 'HIT', $expectedTags); diff --git a/core/modules/tracker/src/Tests/TrackerTest.php b/core/modules/tracker/src/Tests/TrackerTest.php index c20c054..5ff88e6 100644 --- a/core/modules/tracker/src/Tests/TrackerTest.php +++ b/core/modules/tracker/src/Tests/TrackerTest.php @@ -78,8 +78,11 @@ function testTrackerAll() { // Assert cache contexts, specifically the pager and node access contexts. $this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions']); + // Assert cache tags for the visible node and node list cache tag. - $this->assertCacheTags(Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags(), ['node_list', 'rendered'])); + $expected_tags = Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags()); + $expected_tags = Cache::mergeTags($expected_tags, ['node_list', 'rendered']); + $this->assertCacheTags($expected_tags); // Delete a node and ensure it no longer appears on the tracker. $published->delete(); @@ -143,16 +146,15 @@ function testTrackerUser() { // Assert cache contexts; the node grant context is not directly visible due // to it being implied by the user context. $this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args.pagers:0', 'user']); + // Assert cache tags for the visible nodes (including owners) and node list // cache tag. - $tags = Cache::mergeTags( - $my_published->getCacheTags(), - $my_published->getOwner()->getCacheTags(), - $other_published_my_comment->getCacheTags(), - $other_published_my_comment->getOwner()->getCacheTags(), - ['node_list', 'rendered'] - ); - $this->assertCacheTags($tags); + $expected_tags = Cache::mergeTags($my_published->getCacheTags(), $my_published->getOwner()->getCacheTags()); + $expected_tags = Cache::mergeTags($expected_tags, $other_published_my_comment->getCacheTags()); + $expected_tags = Cache::mergeTags($expected_tags, $other_published_my_comment->getOwner()->getCacheTags()); + $expected_tags = Cache::mergeTags($expected_tags, ['node_list', 'rendered']); + + $this->assertCacheTags($expected_tags); $this->assertLink($my_published->label()); $this->assertNoLink($unpublished->label());