summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2008-09-02 19:23:02 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2008-09-02 19:23:02 +0000
commitc17a5e70bca3113bc7e9dbb42c01e9abe47aa063 (patch)
tree5dd373f83c2921f7217f7b65516e07b90c18a64c
parent6511f56e4b62f667138b6bab184b20c53e651cee (diff)
downloadbrdo-c17a5e70bca3113bc7e9dbb42c01e9abe47aa063.tar.gz
brdo-c17a5e70bca3113bc7e9dbb42c01e9abe47aa063.tar.bz2
#285309 by pwolanin: menu_name in hook_menu is ignored on updates
-rw-r--r--includes/menu.inc7
-rw-r--r--modules/simpletest/tests/hook_menu.info8
-rw-r--r--modules/simpletest/tests/hook_menu.module20
-rw-r--r--modules/simpletest/tests/menu.test47
4 files changed, 80 insertions, 2 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index b5a64af25..367369dcb 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -1787,8 +1787,11 @@ function _menu_navigation_links_rebuild($menu) {
$existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system'));
if ($existing_item) {
$item['mlid'] = $existing_item['mlid'];
- $item['menu_name'] = $existing_item['menu_name'];
- $item['plid'] = $existing_item['plid'];
+ // A change in hook_menu may move the link to a different menu
+ if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
+ $item['menu_name'] = $existing_item['menu_name'];
+ $item['plid'] = $existing_item['plid'];
+ }
$item['has_children'] = $existing_item['has_children'];
$item['updated'] = $existing_item['updated'];
}
diff --git a/modules/simpletest/tests/hook_menu.info b/modules/simpletest/tests/hook_menu.info
new file mode 100644
index 000000000..facbf6882
--- /dev/null
+++ b/modules/simpletest/tests/hook_menu.info
@@ -0,0 +1,8 @@
+; $Id$
+name = "Hook menu tests"
+description = "Support module for menu hook testing."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = hook_menu.module
+hidden = TRUE
diff --git a/modules/simpletest/tests/hook_menu.module b/modules/simpletest/tests/hook_menu.module
new file mode 100644
index 000000000..3b11fa042
--- /dev/null
+++ b/modules/simpletest/tests/hook_menu.module
@@ -0,0 +1,20 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Dummy module implementing hook menu to test changing the menu name.
+ */
+
+ /**
+ * The name of the menu changes during the course of this test. Use a $_GET.
+ */
+function hook_menu_menu() {
+
+ $items['menu_name_test'] = array(
+ 'title' => t('Test menu_name router item'),
+ 'page callback' => 'node_save',
+ 'menu_name' => isset($_GET["hook_menu_name"]) ? $_GET["hook_menu_name"] : 'original',
+ );
+ return $items;
+} \ No newline at end of file
diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test
new file mode 100644
index 000000000..93e4a4a53
--- /dev/null
+++ b/modules/simpletest/tests/menu.test
@@ -0,0 +1,47 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides SimpleTests for menu.inc.
+ */
+
+class MenuIncTestCase extends DrupalWebTestCase {
+ /**
+ * Implementation of getInfo().
+ */
+ function getInfo() {
+ return array(
+ 'name' => t('Hook menu tests'),
+ 'description' => t('Test menu hook functionality.'),
+ 'group' => t('Menu'),
+ );
+ }
+
+ /**
+ * Implementation of setUp().
+ */
+ function setUp() {
+ // Enable dummy module that implements hook_menu.
+ parent::setUp('hook_menu');
+ }
+
+ /**
+ * Tests for menu_name parameter for hook_menu().
+ */
+ function testMenuName() {
+ $admin_user = $this->drupalCreateUser(array('administer site configuration'));
+ $this->drupalLogin($admin_user);
+
+ $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
+ $name = db_result(db_query($sql));
+ $this->assertEqual($name, 'original', t('Menu name is "original".'));
+
+ // Force a menu rebuild by going to the modules page.
+ $this->drupalGet('admin/build/modules', array('query' => array("hook_menu_name" => 'changed')));
+
+ $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
+ $name = db_result(db_query($sql));
+ $this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.'));
+ }
+}