diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/menu/menu.module | 20 | ||||
-rw-r--r-- | modules/menu/menu.test | 11 | ||||
-rw-r--r-- | modules/simpletest/tests/menu.test | 99 | ||||
-rw-r--r-- | modules/simpletest/tests/menu_test.module | 106 |
4 files changed, 219 insertions, 17 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'); } diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index 475dac334..4a34369fe 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -6,11 +6,11 @@ * Provides SimpleTests for menu.inc. */ -class MenuIncTestCase extends DrupalWebTestCase { +class MenuRouterTestCase extends DrupalWebTestCase { public static function getInfo() { return array( - 'name' => 'Hook menu tests', - 'description' => 'Test menu hook functionality.', + 'name' => 'Menu router', + 'description' => 'Tests menu router and hook_menu() functionality.', 'group' => 'Menu', ); } @@ -197,9 +197,9 @@ class MenuIncTestCase extends DrupalWebTestCase { } /** - * Tests for menu hiearchy. + * Tests for menu hierarchy. */ - function testMenuHiearchy() { + function testMenuHierarchy() { $parent_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent'))->fetchAssoc(); $child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc(); $unattached_child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc(); @@ -209,6 +209,95 @@ class MenuIncTestCase extends DrupalWebTestCase { } /** + * Tests menu link depth and parents of local tasks and menu callbacks. + */ + function testMenuHidden() { + // Verify links for one dynamic argument. + $links = db_select('menu_links', 'ml') + ->fields('ml') + ->condition('ml.router_path', 'menu-test/hidden/menu%', 'LIKE') + ->orderBy('ml.router_path') + ->execute() + ->fetchAllAssoc('router_path', PDO::FETCH_ASSOC); + + $parent = $links['menu-test/hidden/menu']; + $depth = $parent['depth'] + 1; + $plid = $parent['mlid']; + + $link = $links['menu-test/hidden/menu/list']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/add']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/settings']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/manage/%']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $parent = $links['menu-test/hidden/menu/manage/%']; + $depth = $parent['depth'] + 1; + $plid = $parent['mlid']; + + $link = $links['menu-test/hidden/menu/manage/%/list']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/manage/%/add']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/manage/%/edit']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/menu/manage/%/delete']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + // Verify links for two dynamic arguments. + $links = db_select('menu_links', 'ml') + ->fields('ml') + ->condition('ml.router_path', 'menu-test/hidden/block%', 'LIKE') + ->orderBy('ml.router_path') + ->execute() + ->fetchAllAssoc('router_path', PDO::FETCH_ASSOC); + + $parent = $links['menu-test/hidden/block']; + $depth = $parent['depth'] + 1; + $plid = $parent['mlid']; + + $link = $links['menu-test/hidden/block/list']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/block/add']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/block/manage/%/%']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $parent = $links['menu-test/hidden/block/manage/%/%']; + $depth = $parent['depth'] + 1; + $plid = $parent['mlid']; + + $link = $links['menu-test/hidden/block/manage/%/%/configure']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + + $link = $links['menu-test/hidden/block/manage/%/%/delete']; + $this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth))); + $this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid))); + } + + /** * Test menu_set_item(). */ function testMenuSetItem() { diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module index a89451780..264861240 100644 --- a/modules/simpletest/tests/menu_test.module +++ b/modules/simpletest/tests/menu_test.module @@ -58,6 +58,112 @@ function menu_test_menu() { 'page arguments' => array(TRUE), 'access arguments' => array('access content'), ); + + // Hidden tests; base parents. + // Same structure as in Menu and Block modules. Since those structures can + // change, we need to simulate our own in here. + $items['menu-test'] = array( + 'title' => 'Menu test root', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + ); + $items['menu-test/hidden'] = array( + 'title' => 'Menu test parent', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + ); + + // Hidden tests; one dynamic argument. + $items['menu-test/hidden/menu'] = array( + 'title' => 'Menus', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + ); + $items['menu-test/hidden/menu/list'] = array( + 'title' => 'List menus', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + $items['menu-test/hidden/menu/add'] = array( + 'title' => 'Add menu', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_ACTION, + ); + $items['menu-test/hidden/menu/settings'] = array( + 'title' => 'Settings', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 5, + ); + $items['menu-test/hidden/menu/manage/%menu'] = array( + 'title' => 'Customize menu', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + $items['menu-test/hidden/menu/manage/%menu/list'] = array( + 'title' => 'List links', + 'weight' => -10, + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, + ); + $items['menu-test/hidden/menu/manage/%menu/add'] = array( + 'title' => 'Add link', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_ACTION, + ); + $items['menu-test/hidden/menu/manage/%menu/edit'] = array( + 'title' => 'Edit menu', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, + ); + $items['menu-test/hidden/menu/manage/%menu/delete'] = array( + 'title' => 'Delete menu', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + // Hidden tests; two dynamic arguments. + $items['menu-test/hidden/block'] = array( + 'title' => 'Blocks', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + ); + $items['menu-test/hidden/block/list'] = array( + 'title' => 'List', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + $items['menu-test/hidden/block/add'] = array( + 'title' => 'Add block', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_ACTION, + ); + $items['menu-test/hidden/block/manage/%/%'] = array( + 'title' => 'Configure block', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + ); + $items['menu-test/hidden/block/manage/%/%/configure'] = array( + 'title' => 'Configure block', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'context' => MENU_CONTEXT_INLINE, + ); + $items['menu-test/hidden/block/manage/%/%/delete'] = array( + 'title' => 'Delete block', + 'page callback' => 'node_page_default', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_NONE, + ); + return $items; } |