From 9bc9208d108cf47d8445d0472ef456bef2edaa0d Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Mon, 5 Mar 2012 23:02:41 -0500
Subject: [PATCH] Issue #282775 by pillarsdotnet, Dmitriy.trt, sun, laGreen,
 jenlampton: Hide disabled menu items.

---
 admin_menu.inc        |    4 +-
 tests/admin_menu.test |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/admin_menu.inc b/admin_menu.inc
index cd5b78c4f8787353b61f513f8063058d68c02408..42c6815bff0b99b461e7e1281c91b8f1223c3918 100644
--- a/admin_menu.inc
+++ b/admin_menu.inc
@@ -373,10 +373,10 @@ function admin_menu_expand_args($arguments) {
 function admin_menu_links_menu($tree) {
   $links = array();
   foreach ($tree as $data) {
-    // Skip inaccessible items, items that link to their parent
+    // Skip items that are inaccessible, invisible, or link to their parent.
     // (MENU_DEFAULT_LOCAL_TASK), and MENU_CALLBACK-alike items that should only
     // appear in the breadcrumb.
-    if (!$data['link']['access'] || $data['link']['type'] & MENU_LINKS_TO_PARENT || $data['link']['type'] == MENU_VISIBLE_IN_BREADCRUMB) {
+    if (!$data['link']['access'] || $data['link']['type'] & MENU_LINKS_TO_PARENT || $data['link']['type'] == MENU_VISIBLE_IN_BREADCRUMB || $data['link']['hidden'] == 1) {
       continue;
     }
     // Hide 'Administer' and make child links appear on this level.
diff --git a/tests/admin_menu.test b/tests/admin_menu.test
index af1291eaf021570808269a1391283c1019214d58..d7d35820ec110f480ed13d2c375f21f07c29d81d 100644
--- a/tests/admin_menu.test
+++ b/tests/admin_menu.test
@@ -168,6 +168,71 @@ class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
 }
 
 /**
+ * Tests menu customizations.
+ */
+class AdminMenuCustomTestCase extends AdminMenuWebTestCase {
+  protected $profile = 'testing';
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Customizations',
+      'description' => 'Tests menu customizations.',
+      'group' => 'Administration menu',
+    );
+  }
+
+  function setUp() {
+    parent::setUp(array('menu'));
+
+    $this->admin_user = $this->drupalCreateUser(array(
+      'access administration menu',
+      'access administration pages',
+      'administer menu',
+    ));
+    $this->drupalLogin($this->admin_user);
+
+    $this->nodeType = $this->drupalCreateContentType();
+  }
+
+  /**
+   * Test link contents.
+   */
+  function testDisabledCustomLink() {
+    $node = $this->drupalCreateNode(array('type' => $this->nodeType->type));
+
+    $text = $this->randomName();
+    $xpath = $this->buildXPathQuery('//div[@id=:id]/descendant::a[contains(text(), :text)]', array(
+      ':id' => 'admin-menu',
+      ':text' => $text,
+    ));
+    $elements = $this->xpath($xpath);
+    $this->assertFalse($elements, 'Custom link not found.');
+
+    $mlid_admin = db_query("SELECT mlid FROM {menu_links} WHERE menu_name = 'management' AND link_path = 'admin'")->fetchField();
+    $edit = array(
+      'link_path' => 'node/' . $node->nid,
+      'link_title' => $text,
+      'parent' => 'management:' . $mlid_admin,
+    );
+    $this->drupalPost('admin/structure/menu/manage/management/add', $edit, t('Save'));
+
+    $this->drupalGet('');
+    $elements = $this->xpath($xpath);
+    $this->assertTrue($elements, 'Custom link found.');
+
+    $mlid = db_query("SELECT mlid FROM {menu_links} WHERE menu_name = 'management' AND link_path = 'node/" . $node->nid . "'")->fetchField();
+    $edit = array(
+      'enabled' => FALSE,
+    );
+    $this->drupalPost('admin/structure/menu/item/' . $mlid . '/edit', $edit, t('Save'));
+
+    $this->drupalGet('');
+    $elements = $this->xpath($xpath);
+    $this->assertFalse($elements, 'Disabled custom link not found.');
+  }
+}
+
+/**
  * Tests appearance, localization, and escaping of dynamic links.
  */
 class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
-- 
1.7.5.4

