.../lib/Drupal/menu/Tests/MenuCacheTagsTest.php | 114 ++++++++++++++++++++ .../menu/lib/Drupal/menu/Tests/MenuTest.php | 60 ----------- 2 files changed, 114 insertions(+), 60 deletions(-) diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuCacheTagsTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuCacheTagsTest.php new file mode 100644 index 0000000..14c6168 --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuCacheTagsTest.php @@ -0,0 +1,114 @@ + "Menu & Menu link entities cache tags", + 'description' => "Test the Menu & Menu link entities' cache tags.", + 'group' => 'Menu', + ); + } + + /** + * Tests cache tags presence and invalidation of the Menu entity. + * + * Tests the following cache tags: + * - "menu:" + */ + public function testMenuBlock() { + // Create a Llama menu, add a link to it and place the corresponding block. + $menu = entity_create('menu', array( + 'id' => 'llama', + 'label' => 'Llama', + 'description' => 'Description text', + )); + $menu->save(); + $menu_link = entity_create('menu_link', array( + 'link_path' => '', + 'link_title' => 'Vicuña', + 'menu_name' => 'llama', + )); + $menu_link->save(); + $block = $this->drupalPlaceBlock('system_menu_block:llama', array('label' => 'Llama', 'module' => 'system', 'region' => 'footer')); + + // Prime the page cache. + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit, but also the presence of the correct cache tags. + $this->verifyPageCache('test-page', 'HIT', array('content:1', 'menu:llama')); + + + // Verify that after modifying the menu, there is a cache miss. + $this->pass('Test modification of menu.', 'Debug'); + $menu->label = 'Awesome llama'; + $menu->save(); + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit. + $this->verifyPageCache('test-page', 'HIT'); + + + // Verify that after modifying the menu link, there is a cache miss. + $this->pass('Test modification of menu link.', 'Debug'); + $menu_link->link_title = 'Guanaco'; + $menu_link->save(); + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit. + $this->verifyPageCache('test-page', 'HIT'); + + + // Verify that after adding a menu link, there is a cache miss. + $this->pass('Test addition of menu link.', 'Debug'); + $menu_link_2 = entity_create('menu_link', array( + 'link_path' => '', + 'link_title' => 'Alpaca', + 'menu_name' => 'llama', + )); + $menu_link_2->save(); + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit. + $this->verifyPageCache('test-page', 'HIT'); + + + // Verify that after deleting the first menu link, there is a cache miss. + $this->pass('Test deletion of menu link.', 'Debug'); + $menu_link->delete(); + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit. + $this->verifyPageCache('test-page', 'HIT', array('content:1', 'menu:llama')); + + + // Verify that after deleting the menu, there is a cache miss. + $this->pass('Test deletion of menu.', 'Debug'); + $menu->delete(); + $this->verifyPageCache('test-page', 'MISS'); + + // Verify a cache hit. + $this->verifyPageCache('test-page', 'HIT', array('content:1')); + } + +} diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index d926528..ef63ae0 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -479,66 +479,6 @@ public function testBlockContextualLinks() { } /** - * Test that cache tags are properly set and bubbled up to the page cache. - * - * Ensures that invalidation of the "menu:" cache tags works. - */ - public function testMenuBlockPageCacheTags() { - // Enable page caching. - $config = \Drupal::config('system.performance'); - $config->set('cache.page.use_internal', 1); - $config->set('cache.page.max_age', 300); - $config->save(); - - // Create a Llama menu, add a link to it and place the corresponding block. - $menu = entity_create('menu', array( - 'id' => 'llama', - 'label' => 'Llama', - 'description' => 'Description text', - )); - $menu->save(); - $menu_link = entity_create('menu_link', array( - 'link_path' => '', - 'link_title' => 'Vicuña', - 'menu_name' => 'llama', - )); - $menu_link->save(); - $block = $this->drupalPlaceBlock('system_menu_block:llama', array('label' => 'Llama', 'module' => 'system', 'region' => 'footer')); - - // Prime the page cache. - $this->drupalGet('test-page'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); - - // Verify a cache hit, but also the presence of the correct cache tags. - $this->drupalGet('test-page'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT'); - $cid_parts = array(url('test-page', array('absolute' => TRUE)), 'html'); - $cid = sha1(implode(':', $cid_parts)); - $cache_entry = \Drupal::cache('page')->get($cid); - $this->assertIdentical($cache_entry->tags, array('content:1', 'menu:llama')); - - // The "Llama" menu is modified. - $menu->label = 'Awesome llama'; - $menu->save(); - - // Verify that after the modified menu, there is a cache miss. - $this->drupalGet('test-page'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); - - // Verify a cache hit. - $this->drupalGet('test-page'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT'); - - // A link in the "Llama" menu is modified. - $menu_link->link_title = 'Guanaco'; - $menu_link->save(); - - // Verify that after the modified menu link, there is a cache miss. - $this->drupalGet('test-page'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); - } - - /** * Tests menu link bundles. */ public function testMenuBundles() {