X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fpage_cache%2Ftests%2Fsrc%2FFunctional%2FPageCacheTagsIntegrationTest.php;fp=web%2Fcore%2Fmodules%2Fpage_cache%2Ftests%2Fsrc%2FFunctional%2FPageCacheTagsIntegrationTest.php;h=5f84a3478dedc50a2906cf9e67f9cb7b3bd6e39e;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/page_cache/tests/src/Functional/PageCacheTagsIntegrationTest.php b/web/core/modules/page_cache/tests/src/Functional/PageCacheTagsIntegrationTest.php new file mode 100644 index 000000000..5f84a3478 --- /dev/null +++ b/web/core/modules/page_cache/tests/src/Functional/PageCacheTagsIntegrationTest.php @@ -0,0 +1,164 @@ +enablePageCaching(); + } + + /** + * Test that cache tags are properly bubbled up to the page level. + */ + public function testPageCacheTags() { + // Create two nodes. + $author_1 = $this->drupalCreateUser(); + $node_1 = $this->drupalCreateNode([ + 'uid' => $author_1->id(), + 'title' => 'Node 1', + 'body' => [ + 0 => ['value' => 'Body 1', 'format' => 'basic_html'], + ], + 'promote' => NodeInterface::PROMOTED, + ]); + $author_2 = $this->drupalCreateUser(); + $node_2 = $this->drupalCreateNode([ + 'uid' => $author_2->id(), + 'title' => 'Node 2', + 'body' => [ + 0 => ['value' => 'Body 2', 'format' => 'full_html'], + ], + 'promote' => NodeInterface::PROMOTED, + ]); + + // Place a block, but only make it visible on full node page 2. + $block = $this->drupalPlaceBlock('views_block:comments_recent-block_1', [ + 'visibility' => [ + 'request_path' => [ + 'pages' => '/node/' . $node_2->id(), + ], + ], + ]); + + $cache_contexts = [ + 'languages:' . LanguageInterface::TYPE_INTERFACE, + 'route', + 'theme', + 'timezone', + 'user', + // The placed block is only visible on certain URLs through a visibility + // condition. + 'url.path', + 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, + ]; + + // Full node page 1. + $this->assertPageCacheContextsAndTags($node_1->urlInfo(), $cache_contexts, [ + 'http_response', + 'rendered', + 'block_view', + 'config:block_list', + 'config:block.block.bartik_branding', + 'config:block.block.bartik_breadcrumbs', + 'config:block.block.bartik_content', + 'config:block.block.bartik_tools', + 'config:block.block.bartik_footer', + 'config:block.block.bartik_help', + 'config:block.block.bartik_search', + 'config:block.block.' . $block->id(), + 'config:block.block.bartik_powered', + 'config:block.block.bartik_main_menu', + 'config:block.block.bartik_account_menu', + 'config:block.block.bartik_messages', + 'config:block.block.bartik_local_actions', + 'config:block.block.bartik_local_tasks', + 'config:block.block.bartik_page_title', + 'node_view', + 'node:' . $node_1->id(), + 'user:0', + 'user:' . $author_1->id(), + 'config:filter.format.basic_html', + 'config:color.theme.bartik', + 'config:search.settings', + 'config:system.menu.account', + 'config:system.menu.tools', + 'config:system.menu.footer', + 'config:system.menu.main', + 'config:system.site', + // FinishResponseSubscriber adds this cache tag to responses that have the + // 'user.permissions' cache context for anonymous users. + 'config:user.role.anonymous', + ]); + + // Render the view block adds the languages cache context. + $cache_contexts[] = 'languages:' . LanguageInterface::TYPE_CONTENT; + + // Full node page 2. + $this->assertPageCacheContextsAndTags($node_2->urlInfo(), $cache_contexts, [ + 'http_response', + 'rendered', + 'block_view', + 'config:block_list', + 'config:block.block.bartik_branding', + 'config:block.block.bartik_breadcrumbs', + 'config:block.block.bartik_content', + 'config:block.block.bartik_tools', + 'config:block.block.bartik_help', + 'config:block.block.bartik_search', + 'config:block.block.' . $block->id(), + 'config:block.block.bartik_footer', + 'config:block.block.bartik_powered', + 'config:block.block.bartik_main_menu', + 'config:block.block.bartik_account_menu', + 'config:block.block.bartik_messages', + 'config:block.block.bartik_local_actions', + 'config:block.block.bartik_local_tasks', + 'config:block.block.bartik_page_title', + 'node_view', + 'node:' . $node_2->id(), + 'user:' . $author_2->id(), + 'config:color.theme.bartik', + 'config:filter.format.full_html', + 'config:search.settings', + 'config:system.menu.account', + 'config:system.menu.tools', + 'config:system.menu.footer', + 'config:system.menu.main', + 'config:system.site', + 'comment_list', + 'node_list', + 'config:views.view.comments_recent', + // FinishResponseSubscriber adds this cache tag to responses that have the + // 'user.permissions' cache context for anonymous users. + 'config:user.role.anonymous', + 'user:0', + ]); + } + +}