diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-12-14 20:23:01 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-12-14 20:23:01 +0000 |
commit | 0c2b526539f7fb50765bf9ef2dfa7c573764f9fd (patch) | |
tree | a024987330cd00d3881ed8aa1b17f10858168d34 /modules/menu | |
parent | 13984a7394ec27a2e99b6c7437469f663a331cc3 (diff) | |
download | brdo-0c2b526539f7fb50765bf9ef2dfa7c573764f9fd.tar.gz brdo-0c2b526539f7fb50765bf9ef2dfa7c573764f9fd.tar.bz2 |
- Patch #631550 by sun: fixed stale and improper logic for MENU_VISIBLE_IN_TREE and MENU_VISIBLE_IN_BREADCRUMB. Added lots of code comments, and added tests.
Diffstat (limited to 'modules/menu')
-rw-r--r-- | modules/menu/menu.module | 20 | ||||
-rw-r--r-- | modules/menu/menu.test | 11 |
2 files changed, 19 insertions, 12 deletions
diff --git a/modules/menu/menu.module b/modules/menu/menu.module index d639d9453..f4ec4c386 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -399,15 +399,23 @@ function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, } /** - * Reset a system-defined menu item. + * Reset a system-defined menu link. */ -function menu_reset_item($item) { - $new_item = _menu_link_build(menu_get_item($item['router_path'])); +function menu_reset_item($link) { + // To reset the link to its original values, we need to retrieve its + // definition from hook_menu(). Otherwise, for example, the link's menu would + // not be reset, because properties like the original 'menu_name' are not + // stored anywhere else. Since resetting a link happens rarely and this is a + // one-time operation, retrieving the full menu router does no harm. + $menu = menu_get_router(); + $router_item = $menu[$link['router_path']]; + $new_link = _menu_link_build($router_item); + // Merge existing menu link's ID and 'has_children' property. foreach (array('mlid', 'has_children') as $key) { - $new_item[$key] = $item[$key]; + $new_link[$key] = $link[$key]; } - menu_link_save($new_item); - return $new_item; + menu_link_save($new_link); + return $new_link; } /** diff --git a/modules/menu/menu.test b/modules/menu/menu.test index d4a2772e6..15fc84534 100644 --- a/modules/menu/menu.test +++ b/modules/menu/menu.test @@ -252,10 +252,9 @@ class MenuTestCase extends DrupalWebTestCase { ); // Add menu link. - $this->drupalPost("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); + $this->drupalPost(NULL, $edit, t('Save')); $this->assertResponse(200); // Unlike most other modules, there is no confirmation message displayed. - $this->assertText($title, 'Menu link was added'); // Retrieve menu link. @@ -267,7 +266,10 @@ class MenuTestCase extends DrupalWebTestCase { // We know link1 is at the top level, so $item1['deptj'] == 1 and $item1['plid'] == 0. // We know that the parent of link2 is link1, so $item2['plid'] == $item1['mlid']. // Both menu links were created in the navigation menu. - $this->assertTrue($item['menu_name'] == $menu_name && $item['plid'] == $plid && $item['link_path'] == $link && $item['link_title'] == $title, 'Menu link has correct data'); + $this->assertEqual($item['menu_name'], $menu_name); + $this->assertEqual($item['plid'], $plid); + $this->assertEqual($item['link_path'], $link); + $this->assertEqual($item['link_title'], $title); if ($plid == 0) { $this->assertTrue($item['depth'] == 1 && !$item['has_children'] && $item['p1'] == $item['mlid'] && $item['p2'] == 0, 'Menu link has correct data'); } @@ -370,9 +372,6 @@ class MenuTestCase extends DrupalWebTestCase { // Verify menu link. $this->drupalGet(''); $this->assertNoText($title, 'Menu link was reset'); - - // Verify menu link. - $this->drupalGet(''); $this->assertText($old_title, 'Menu link was reset'); } |