.../menu/lib/Drupal/menu/Tests/MenuTest.php | 42 ++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index ca053dc..d03012d 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -458,14 +458,32 @@ 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(); - $block = $this->drupalPlaceBlock('system_menu_block:tools', array('label' => 'Tools', 'module' => 'system', 'region' => 'footer')); + // 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'); @@ -475,15 +493,11 @@ public function testMenuBlockPageCacheTags() { $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:tools')); + $this->assertIdentical($cache_entry->tags, array('content:1', 'menu:llama')); - // An admin user edits the "Tools" menu. - $this->drupalLogin($this->admin_user); - $edit = array( - 'label' => $this->randomName(16), - ); - $this->drupalPostForm('admin/structure/menu/manage/tools', $edit, t('Save')); - $this->drupalLogout(); + // 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'); @@ -493,13 +507,9 @@ public function testMenuBlockPageCacheTags() { $this->drupalGet('test-page'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT'); - // An admin user edits a link in the "Tools" menu. - $this->drupalLogin($this->admin_user); - $edit = array( - 'link_title' => $this->randomName(16), - ); - $this->drupalPostForm('admin/structure/menu/item/5/edit', $edit, t('Save')); - $this->drupalLogout(); + // 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');