core/includes/theme.inc | 8 ---- core/lib/Drupal/Core/Access/AccessResult.php | 2 +- core/lib/Drupal/Core/Config/Config.php | 1 + .../Drupal/Core/Config/Entity/ConfigEntityBase.php | 2 + .../Drupal/Core/Config/Entity/ConfigEntityType.php | 3 ++ core/lib/Drupal/Core/Render/Element/Page.php | 21 --------- core/modules/block/src/Entity/Block.php | 13 ------ .../src/Plugin/DisplayVariant/BlockPageVariant.php | 21 ++++++--- core/modules/block/src/Tests/BlockTest.php | 9 +--- .../block/src/Tests/BlockViewBuilderTest.php | 2 +- .../Plugin/DisplayVariant/BlockPageVariantTest.php | 24 ++++++++-- .../comment/src/Tests/CommentCacheTagsTest.php | 5 --- .../Tests/CommentDefaultFormatterCacheTagsTest.php | 5 +-- .../menu_ui/src/Tests/MenuCacheTagsTest.php | 5 +-- core/modules/node/src/Tests/NodeCacheTagsTest.php | 10 +---- core/modules/shortcut/src/Entity/Shortcut.php | 2 +- .../system/src/Tests/Bootstrap/PageCacheTest.php | 2 - .../Tests/Cache/PageCacheTagsIntegrationTest.php | 6 +-- .../src/Tests/Entity/EntityCacheTagsTestBase.php | 51 ++++++++++------------ core/modules/tour/src/Tests/TourCacheTagsTest.php | 4 -- .../Drupal/Tests/Core/Access/AccessResultTest.php | 4 +- core/tests/Drupal/Tests/Core/Config/ConfigTest.php | 10 +++++ 22 files changed, 89 insertions(+), 121 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 3dac164..2c8f3fd 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -319,14 +319,6 @@ function drupal_find_theme_templates($cache, $extension, $path) { return $implementations; } - -function theme_setting_get_cache_tags() { - $theme = \Drupal::theme()->getActiveTheme()->getName(); - return [ - 'config:' . $theme . '.settings', - 'config:system.theme.global', - ]; -} /** * Retrieves a setting for the current theme or for a given theme. * diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 9ea5783..76f0212 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -365,7 +365,7 @@ public function cacheUntilEntityChanges(EntityInterface $entity) { * Convenience method, adds the configuration object's cache tag. * * @param \Drupal\Core\Config\ConfigBase $configuration - * The entity whose cache tag to set on the access result. + * The configuration object whose cache tag to set on the access result. * * @return $this */ diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index a4004a8..bc6ba29 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -240,6 +240,7 @@ public function save() { public function delete() { $this->data = array(); $this->storage->delete($this->name); + Cache::invalidateTags($this->getCacheTags()); $this->isNew = TRUE; $this->resetOverriddenData(); $this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this)); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 6e8866b..5be6c85 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -375,6 +375,8 @@ public function link($text = NULL, $rel = 'edit-form', array $options = []) { * {@inheritdoc} */ public function getCacheTags() { + // Use cache tags that match the underlying config object's name. + // @see getConfigDependencyName() return ['config:' . $this->getConfigDependencyName()]; } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index ef46168..fc1eac0 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -70,6 +70,9 @@ public function __construct($definition) { $this->handlers += array( 'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage', ); + // Prefix the sole default list cache tag with 'config:', to make it + // consistent with the other Configuration System cache tags. + $this->list_cache_tags[0] = 'config:' . $this->list_cache_tags[0]; } /** diff --git a/core/lib/Drupal/Core/Render/Element/Page.php b/core/lib/Drupal/Core/Render/Element/Page.php index 9d7aca8..b65446a 100644 --- a/core/lib/Drupal/Core/Render/Element/Page.php +++ b/core/lib/Drupal/Core/Render/Element/Page.php @@ -20,32 +20,11 @@ class Page extends RenderElement { * {@inheritdoc} */ public function getInfo() { - $class = get_class($this); return array( '#show_messages' => TRUE, - '#pre_render' => array( - array($class, 'preRenderPage'), - ), '#theme' => 'page', '#title' => '', ); } - /** - * #pre_render callback for the page element type. - * - * @param array $element - * A structured array containing the page element type build properties. - * - * @return array - */ - public static function preRenderPage($element) { - // Assign the cache tag for the theme-specific settings. Instead of using - // yet another cache tag (such as 'theme:') to tag HTML page - // responses that are rendered using a certain theme, we reuse the theme - // settings simple config cache tag instead. - $element['#cache']['tags'][] = 'config:' . \Drupal::theme()->getActiveTheme()->getName() . '.settings'; - return $element; - } - } diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php index 4b1ffca..723bf68 100644 --- a/core/modules/block/src/Entity/Block.php +++ b/core/modules/block/src/Entity/Block.php @@ -204,19 +204,6 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { /** * {@inheritdoc} - * - * Block configuration entities are a special case: one block entity stores - * the placement of one block in one theme. Changing these entities may affect - * any page that is rendered in a certain theme, even if the block doesn't - * appear there currently. Hence a block configuration entity must also return - * the associated theme's cache tag. - */ - public function getCacheTags() { - return Cache::mergeTags(parent::getCacheTags(), ['config:' . $this->theme . '.settings']); - } - - /** - * {@inheritdoc} */ public function setContexts(array $contexts) { $this->contexts = $contexts; diff --git a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php index 895e2c6..bf91a04 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php @@ -12,6 +12,7 @@ use Drupal\block\Event\BlockEvents; use Drupal\Core\Block\MainContentBlockPluginInterface; use Drupal\Core\Display\PageVariantInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Display\VariantBase; @@ -43,11 +44,11 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont protected $blockViewBuilder; /** - * The current theme. + * The Block entity type list cache tags. * - * @var string + * @var string[] */ - protected $theme; + protected $blockListCacheTags; /** * The render array representing the main page content. @@ -71,12 +72,15 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont * The block view builder. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * The event dispatcher. + * @param string[] $block_list_cache_tags + * The Block entity type list cache tags. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, EventDispatcherInterface $dispatcher) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, EventDispatcherInterface $dispatcher, array $block_list_cache_tags) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->blockRepository = $block_repository; $this->blockViewBuilder = $block_view_builder; $this->dispatcher = $dispatcher; + $this->blockListCacheTags = $block_list_cache_tags; } /** @@ -89,7 +93,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('block.repository'), $container->get('entity.manager')->getViewBuilder('block'), - $container->get('event_dispatcher') + $container->get('event_dispatcher'), + $container->get('entity.manager')->getDefinition('block')->getListCacheTags() ); } @@ -108,7 +113,11 @@ public function build() { // Track whether a block that shows the main content is displayed or not. $main_content_block_displayed = FALSE; - $build = array(); + $build = [ + '#cache' => [ + 'tags' => $this->blockListCacheTags, + ], + ]; $contexts = $this->getActiveBlockContexts(); // Load all region content assigned via blocks. foreach ($this->blockRepository->getVisibleBlocksPerRegion($contexts) as $region => $blocks) { diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index d390b00..fcccc6b 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -327,8 +327,7 @@ public function testBlockCacheTags() { $cid = implode(':', $cid_parts); $cache_entry = \Drupal::cache('render')->get($cid); $expected_cache_tags = array( - 'config:classy.settings', - 'config:system.theme.global', + 'config:block_list', 'block_view', 'config:block.block.powered', 'block_plugin:system_powered_by_block', @@ -340,7 +339,6 @@ public function testBlockCacheTags() { $expected_cache_tags = array( 'block_view', 'config:block.block.powered', - 'config:classy.settings', 'block_plugin:system_powered_by_block', 'rendered', ); @@ -369,8 +367,7 @@ public function testBlockCacheTags() { $cid = implode(':', $cid_parts); $cache_entry = \Drupal::cache('render')->get($cid); $expected_cache_tags = array( - 'config:classy.settings', - 'config:system.theme.global', + 'config:block_list', 'block_view', 'config:block.block.powered', 'config:block.block.powered-2', @@ -382,7 +379,6 @@ public function testBlockCacheTags() { $expected_cache_tags = array( 'block_view', 'config:block.block.powered', - 'config:classy.settings', 'block_plugin:system_powered_by_block', 'rendered', ); @@ -392,7 +388,6 @@ public function testBlockCacheTags() { $expected_cache_tags = array( 'block_view', 'config:block.block.powered-2', - 'config:classy.settings', 'block_plugin:system_powered_by_block', 'rendered', ); diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php index 4c45933..bfd37d4 100644 --- a/core/modules/block/src/Tests/BlockViewBuilderTest.php +++ b/core/modules/block/src/Tests/BlockViewBuilderTest.php @@ -215,7 +215,7 @@ public function testBlockViewBuilderAlter() { $request->setMethod('GET'); $default_keys = array('entity_view', 'block', 'test_block', 'en', 'cache_context.theme'); - $default_tags = array('block_view', 'config:block.block.test_block', 'config:stark.settings', 'block_plugin:test_cache'); + $default_tags = array('block_view', 'config:block.block.test_block', 'block_plugin:test_cache'); // Advanced: cached block, but an alter hook adds an additional cache key. $this->setBlockCacheConfig(array( diff --git a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php index 0ae38d4..c39d744 100644 --- a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php +++ b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php @@ -61,9 +61,8 @@ public function setUpDisplayVariant($configuration = array(), $definition = arra $this->dispatcher->expects($this->any()) ->method('dispatch') ->willReturnArgument(1); - $this->contextHandler = $this->getMock('Drupal\Core\Plugin\Context\ContextHandlerInterface'); return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\BlockPageVariant') - ->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, $this->dispatcher, $this->contextHandler)) + ->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, $this->dispatcher, ['config:block_list'])) ->setMethods(array('getRegionNames')) ->getMock(); } @@ -89,6 +88,11 @@ public function providerBuild() { $test_cases = []; $test_cases[] = [$blocks_config, 4, [ + '#cache' => [ + 'tags' => [ + 'config:block_list', + ], + ], 'top' => [ 'block1' => [], '#sorted' => TRUE, @@ -108,6 +112,11 @@ public function providerBuild() { unset($blocks_config['block4']); $test_cases[] = [$blocks_config, 3, [ + '#cache' => [ + 'tags' => [ + 'config:block_list', + ], + ], 'top' => [ 'block1' => [], '#sorted' => TRUE, @@ -170,7 +179,16 @@ public function testBuildWithoutMainContent() { ->method('getVisibleBlocksPerRegion') ->willReturn([]); - $expected = ['content' => ['system_main' => []]]; + $expected = [ + '#cache' => [ + 'tags' => [ + 'config:block_list', + ], + ], + 'content' => [ + 'system_main' => [], + ], + ]; $this->assertSame($expected, $display_variant->build()); } diff --git a/core/modules/comment/src/Tests/CommentCacheTagsTest.php b/core/modules/comment/src/Tests/CommentCacheTagsTest.php index 0b8a26e..6f83dbf 100644 --- a/core/modules/comment/src/Tests/CommentCacheTagsTest.php +++ b/core/modules/comment/src/Tests/CommentCacheTagsTest.php @@ -82,8 +82,6 @@ protected function createEntity() { * {@inheritdoc} * * Each comment must have a comment body, which always has a text format. - * - * Plus, template_preprocess_comment() depends on theme settings. */ protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) { /** @var \Drupal\comment\CommentInterface $entity */ @@ -91,9 +89,6 @@ protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) { 'config:filter.format.plain_text', 'user:' . $entity->getOwnerId(), 'user_view', - // Cache tags added by template_preprocess_comment(). - 'config:classy.settings', - 'config:system.theme.global', ); } diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php index e8ed806..1a97e1b 100644 --- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php +++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php @@ -110,12 +110,9 @@ public function testCacheTags() { 'config:filter.format.plain_text', 'user_view', 'user:2', - // Cache tags added by template_preprocess_comment(). - 'config:core.settings', - 'config:system.theme.global', ); sort($expected_cache_tags); - $this->assertEqual($build['#cache']['tags'], $expected_cache_tags); + $this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.'); } } diff --git a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php index feac980..96432d4 100644 --- a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php +++ b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php @@ -48,10 +48,9 @@ public function testMenuBlock() { // Verify a cache hit, but also the presence of the correct cache tags. $expected_tags = array( - 'config:classy.settings', - 'config:system.theme.global', 'rendered', 'block_view', + 'config:block_list', 'config:block.block.' . $block->id(), 'block_plugin:system_menu_block__llama', 'config:system.menu.llama', @@ -106,7 +105,7 @@ public function testMenuBlock() { $this->verifyPageCache($path, 'MISS'); // Verify a cache hit. - $this->verifyPageCache($path, 'HIT', array('rendered', 'config:classy.settings', 'config:system.theme.global')); + $this->verifyPageCache($path, 'HIT', ['config:block_list', 'rendered']); } } diff --git a/core/modules/node/src/Tests/NodeCacheTagsTest.php b/core/modules/node/src/Tests/NodeCacheTagsTest.php index 67753eb..cd46f79 100644 --- a/core/modules/node/src/Tests/NodeCacheTagsTest.php +++ b/core/modules/node/src/Tests/NodeCacheTagsTest.php @@ -46,17 +46,9 @@ protected function createEntity() { * {@inheritdoc} * * Each node must have an author. - * - * Plus, template_preprocess_node() depends on theme settings. */ protected function getAdditionalCacheTagsForEntity(EntityInterface $node) { - return [ - 'user:' . $node->getOwnerId(), - 'user_view', - // Cache tags added by template_preprocess_comment(). - 'config:classy.settings', - 'config:system.theme.global', - ]; + return array('user:' . $node->getOwnerId(), 'user_view'); } } diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 770406a..1ebf208 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -46,7 +46,7 @@ * "delete-form" = "entity.shortcut.delete_form", * "edit-form" = "entity.shortcut.canonical", * }, - * list_cache_tags = { "shortcut_set_list" }, + * list_cache_tags = { "config:shortcut_set_list" }, * bundle_entity_type = "shortcut_set" * ) */ diff --git a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php index a4b3611..11e0bee 100644 --- a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php @@ -62,8 +62,6 @@ function testPageCacheTags() { $cache_entry = \Drupal::cache('render')->get($cid); sort($cache_entry->tags); $expected_tags = array( - 'config:classy.settings', - 'config:system.theme.global', 'pre_render', 'rendered', 'system_test_cache_tags_page', diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php index 97639bc..f25ed00 100644 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php @@ -69,9 +69,8 @@ function testPageCacheTags() { // Full node page 1. $this->verifyPageCacheTags('node/' . $node_1->id(), array( 'rendered', - 'config:bartik.settings', - 'config:system.theme.global', 'block_view', + 'config:block_list', 'config:block.block.bartik_content', 'config:block.block.bartik_tools', 'config:block.block.bartik_login', @@ -99,9 +98,8 @@ function testPageCacheTags() { // Full node page 2. $this->verifyPageCacheTags('node/' . $node_2->id(), array( 'rendered', - 'config:bartik.settings', - 'config:system.theme.global', 'block_view', + 'config:block_list', 'config:block.block.bartik_content', 'config:block.block.bartik_tools', 'config:block.block.bartik_login', diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index 145daba..2ddfdb8 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -282,8 +282,13 @@ public function testReferencedEntity() { $empty_entity_listing_path = 'entity_test/list_empty/' . $entity_type; $nonempty_entity_listing_path = 'entity_test/list_labels_alphabetically/' . $entity_type; - $render_cache_tags = array('rendered'); - $theme_cache_tags = array('config:classy.settings', 'config:system.theme.global'); + // Cache tags present on every rendered page. + $page_cache_tags = Cache::mergeTags( + ['rendered'], + // If the block module is used, the Block page display variant is used, + // which adds the block config entity type's list cache tags. + \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list']: [] + ); $view_cache_tag = array(); if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) { @@ -298,11 +303,13 @@ public function testReferencedEntity() { // Includes the main entity's cache tags, since this entity references it. $this->entity->getCacheTags(), $this->getAdditionalCacheTagsForEntity($this->entity), - $view_cache_tag + $view_cache_tag, + ['rendered'] ); $non_referencing_entity_cache_tags = Cache::mergeTags( $this->non_referencing_entity->getCacheTags(), - \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags() + \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(), + ['rendered'] ); // Generate the cache tags for all two possible entity listing paths. @@ -310,44 +317,37 @@ public function testReferencedEntity() { // 2. list cache tag plus entity cache tag (listing query has a match) $empty_entity_listing_cache_tags = Cache::mergeTags( $this->entity->getEntityType()->getListCacheTags(), - $theme_cache_tags, - $render_cache_tags + $page_cache_tags ); $nonempty_entity_listing_cache_tags = Cache::mergeTags( $this->entity->getEntityType()->getListCacheTags(), $this->entity->getCacheTags(), $this->getAdditionalCacheTagsForEntityListing($this->entity), - $theme_cache_tags, - $render_cache_tags + $page_cache_tags ); $this->pass("Test referencing entity.", 'Debug'); $this->verifyPageCache($referencing_entity_path, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $referencing_entity_cache_tags); - $this->verifyPageCache($referencing_entity_path, 'HIT', $tags); + $this->verifyPageCache($referencing_entity_path, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags)); // Also verify the existence of an entity render cache entry. $cid = 'entity_view:entity_test:' . $this->referencing_entity->id() . ':full:classy:r.anonymous:' . date_default_timezone_get(); - $tags = Cache::mergeTags($render_cache_tags, $referencing_entity_cache_tags); - $this->verifyRenderCache($cid, $tags); + $this->verifyRenderCache($cid, $referencing_entity_cache_tags); $this->pass("Test non-referencing entity.", 'Debug'); $this->verifyPageCache($non_referencing_entity_path, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $non_referencing_entity_cache_tags); - $this->verifyPageCache($non_referencing_entity_path, 'HIT', $tags); + $this->verifyPageCache($non_referencing_entity_path, 'HIT', Cache::mergeTags($non_referencing_entity_cache_tags, $page_cache_tags)); // Also verify the existence of an entity render cache entry. $cid = 'entity_view:entity_test:' . $this->non_referencing_entity->id() . ':full:classy:r.anonymous:' . date_default_timezone_get(); - $tags = Cache::mergeTags($render_cache_tags, $non_referencing_entity_cache_tags); - $this->verifyRenderCache($cid, $tags); + $this->verifyRenderCache($cid, $non_referencing_entity_cache_tags); $this->pass("Test listing of referencing entities.", 'Debug'); // Prime the page cache for the listing of referencing entities. $this->verifyPageCache($listing_path, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $referencing_entity_cache_tags); - $this->verifyPageCache($listing_path, 'HIT', $tags); + $this->verifyPageCache($listing_path, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags)); $this->pass("Test empty listing.", 'Debug'); @@ -563,16 +563,13 @@ public function testReferencedEntity() { // Verify cache hits. $referencing_entity_cache_tags = Cache::mergeTags( $this->referencing_entity->getCacheTags(), - \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags() + \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(), + ['rendered'] ); - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $referencing_entity_cache_tags); - $this->verifyPageCache($referencing_entity_path, 'HIT', $tags); - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags); - $this->verifyPageCache($listing_path, 'HIT', $tags); - $tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $this->entity->getEntityType()->getListCacheTags()); - $this->verifyPageCache($empty_entity_listing_path, 'HIT', $tags); - $tags = Cache::mergeTags($tags, $this->getAdditionalCacheTagsForEntityListing()); - $this->verifyPageCache($nonempty_entity_listing_path, 'HIT', $tags); + $this->verifyPageCache($referencing_entity_path, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags)); + $this->verifyPageCache($listing_path, 'HIT', $page_cache_tags); + $this->verifyPageCache($empty_entity_listing_path, 'HIT', $empty_entity_listing_cache_tags); + $this->verifyPageCache($nonempty_entity_listing_path, 'HIT', Cache::mergeTags($this->entity->getEntityType()->getListCacheTags(), $this->getAdditionalCacheTagsForEntityListing(), $page_cache_tags)); } /** diff --git a/core/modules/tour/src/Tests/TourCacheTagsTest.php b/core/modules/tour/src/Tests/TourCacheTagsTest.php index df15a4b..d6a537f 100644 --- a/core/modules/tour/src/Tests/TourCacheTagsTest.php +++ b/core/modules/tour/src/Tests/TourCacheTagsTest.php @@ -49,8 +49,6 @@ public function testRenderedTour() { // Verify a cache hit, but also the presence of the correct cache tags. $expected_tags = [ - 'config:classy.settings', - 'config:system.theme.global', 'config:tour.tour.tour-test', 'rendered', ]; @@ -71,8 +69,6 @@ public function testRenderedTour() { // Verify a cache hit. $expected_tags = [ - 'config:classy.settings', - 'config:system.theme.global', 'rendered', ]; $this->verifyPageCache($path, 'HIT', $expected_tags); diff --git a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php index 4c3bc64..add45c2 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php @@ -453,8 +453,8 @@ public function testCacheTags() { $configuration = $this->getMock('\Drupal\Core\Config\ConfigBase'); $configuration->expects($this->any()) ->method('getCacheTags') - ->will($this->returnValue(array('config:system.theme.global'))); - $tags = array('config:system.theme.global'); + ->will($this->returnValue(array('config:foo.bar.baz'))); + $tags = array('config:foo.bar.baz'); $a = AccessResult::neutral()->addCacheTags($tags); $verify($a, $tags); $b = AccessResult::neutral()->cacheUntilConfigurationChanges($configuration); diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 215b915..15d300b 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -290,6 +290,16 @@ public function testNestedClear($data) { * @dataProvider overrideDataProvider */ public function testDelete($data, $module_data) { + // Mock the cache backend, verifying that invalidateTags() is invoked on it, + // *twice*: once for saving, once for deleting. + $cache_backend = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface'); + $cache_backend->expects($this->exactly(2)) + ->method('invalidateTags') + ->with(['config:config.test']); + $container = \Drupal::getContainer(); + $container->set('cache.mocked', $cache_backend); + $container->setParameter('cache_bins', ['cache.mocked' => 'mocked']); + // Set initial data. foreach ($data as $key => $value) { $this->config->set($key, $value);