diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php index ba9841b..f5fd23e 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php @@ -10,7 +10,7 @@ namespace Drupal\menu\Tests; use Drupal\simpletest\WebTestBase; /** - * Test menu settings for nodes. + * Tests menu settings for nodes. */ class MenuNodeTest extends WebTestBase { @@ -21,6 +21,18 @@ class MenuNodeTest extends WebTestBase { */ public static $modules = array('menu'); + /** + * An administrative user. + * + * @var + */ + protected $adminUser; + + /** + * The profile to use with this test class. + * + * @var string + */ protected $profile = 'standard'; public static function getInfo() { @@ -34,7 +46,7 @@ class MenuNodeTest extends WebTestBase { function setUp() { parent::setUp(); - $this->admin_user = $this->drupalCreateUser(array( + $this->adminUser = $this->drupalCreateUser(array( 'access administration pages', 'administer content types', 'administer menu', @@ -42,11 +54,11 @@ class MenuNodeTest extends WebTestBase { 'edit any page content', 'delete any page content', )); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); } /** - * Test creating, editing, deleting menu links via node form widget. + * Tests creating, editing, deleting menu links via node form widget. */ function testMenuNodeFormWidget() { // Enable Navigation menu as available menu. @@ -114,7 +126,8 @@ class MenuNodeTest extends WebTestBase { ); menu_link_save($item); - // Assert that disabled Management menu is not shown on the node/$nid/edit page. + // Assert that disabled Management menu is not shown on the node/$nid/edit + // page. $this->drupalGet('node/' . $node->nid . '/edit'); $this->assertText('Provide a menu link', 'Link in not allowed menu not shown in node edit form'); // Assert that the link is still in the management menu after save. @@ -136,7 +149,8 @@ class MenuNodeTest extends WebTestBase { menu_link_save($child_item); // Edit the first node. $this->drupalGet('node/'. $node->nid .'/edit'); - // Assert that it is not possible to set the parent of the first node to itself or the second node. + // Assert that it is not possible to set the parent of the first node to + // itself or the second node. $this->assertNoOption('edit-menu-parent', 'navigation:'. $item['mlid']); $this->assertNoOption('edit-menu-parent', 'navigation:'. $child_item['mlid']); // Assert that unallowed Management menu is not available in options. diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index b4cd7e7..27587a0 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -9,6 +9,9 @@ namespace Drupal\menu\Tests; use Drupal\simpletest\WebTestBase; +/** + * Tests the menu module. + */ class MenuTest extends WebTestBase { /** @@ -18,11 +21,39 @@ class MenuTest extends WebTestBase { */ public static $modules = array('menu'); + /** + * The profile to use with this test class. + * + * @var string + */ protected $profile = 'standard'; - protected $big_user; - protected $std_user; + /** + * An administrative user. + * + * @var + */ + protected $adminUser; + + /** + * A standard user. + * + * @var + */ + protected $standardUser; + + /** + * A menu definition. + * + * @var + */ protected $menu; + + /** + * Menu items. + * + * @var + */ protected $items; public static function getInfo() { @@ -37,16 +68,19 @@ class MenuTest extends WebTestBase { parent::setUp(); // Create users. - $this->big_user = $this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content')); - $this->std_user = $this->drupalCreateUser(array()); + $this->adminUser = $this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content')); + $this->standardUser = $this->drupalCreateUser(array()); } /** - * Login users, add menus and menu links, and test menu functionality through the admin and user interfaces. + * Tests menu functionality through the admin and user interfaces. + * + * This test logs in users, adds menus and menu links, and tests menu + * functionality through the admin and user interfaces. */ function testMenu() { // Login the user. - $this->drupalLogin($this->big_user); + $this->drupalLogin($this->adminUser); $this->items = array(); // Do standard menu tests. @@ -57,15 +91,16 @@ class MenuTest extends WebTestBase { // Do standard user tests. // Login the user. - $this->drupalLogin($this->std_user); + $this->drupalLogin($this->standardUser); $this->verifyAccess(403); foreach ($this->items as $item) { - $node = node_load(substr($item['link_path'], 5)); // Paths were set as 'node/$nid'. + // Paths were set as 'node/$nid'. + $node = node_load(substr($item['link_path'], 5)); $this->verifyMenuLink($item, $node); } // Login the user. - $this->drupalLogin($this->big_user); + $this->drupalLogin($this->adminUser); // Delete menu links. foreach ($this->items as $item) { @@ -90,8 +125,7 @@ class MenuTest extends WebTestBase { } /** - * Test standard menu functionality using navigation menu. - * + * Tests standard menu functionality using navigation menu. */ function doStandardMenuTests() { $this->doMenuTests(); @@ -99,8 +133,7 @@ class MenuTest extends WebTestBase { } /** - * Test custom menu functionality using navigation menu. - * + * Tests custom menu functionality using navigation menu. */ function doCustomMenuTests() { $this->menu = $this->addCustomMenu(); @@ -110,7 +143,7 @@ class MenuTest extends WebTestBase { } /** - * Add custom menu using CRUD functions. + * Tests the addition of custom menu using CRUD functions. */ function addCustomMenuCRUD() { // Add a new custom menu. @@ -137,7 +170,7 @@ class MenuTest extends WebTestBase { } /** - * Add custom menu. + * Tests the addition of a custom menu. */ function addCustomMenu() { // Add custom menu. @@ -153,7 +186,8 @@ class MenuTest extends WebTestBase { ); $this->drupalPost('admin/structure/menu/add', $edit, t('Save')); - // Verify that using a menu_name that is too long results in a validation message. + // Verify that using a menu_name that is too long results in a validation + // message. $this->assertRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array( '!name' => t('Menu name'), '%max' => MENU_MAX_MENU_NAME_LENGTH_UI, @@ -188,9 +222,10 @@ class MenuTest extends WebTestBase { } /** - * Delete custom menu. + * Tests the deletion of a custom menu. * - * @param string $menu_name Custom menu name. + * @param string $menu_name + * A custom menu name. */ function deleteCustomMenu($menu) { $menu_name = $this->menu['menu_name']; @@ -207,8 +242,10 @@ class MenuTest extends WebTestBase { } /** - * Test menu functionality using navigation menu. + * Tests menu functionality using navigation menu. * + * @param $menu_name + * (optional) The name of menu. Defaults to 'navigation'. */ function doMenuTests($menu_name = 'navigation') { // Add nodes to use as links for menu links. @@ -254,7 +291,7 @@ class MenuTest extends WebTestBase { $this->assertMenuLink($item3['mlid'], array('depth' => 4, 'has_children' => 0, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => $item2['mlid'], 'p4' => $item3['mlid'], 'p5' => 0)); // Add 102 menu links with increasing weights, then make sure the last-added - // item's weight doesn't get changed because of the old hardcoded delta=50 + // item's weight doesn't get changed because of the old hardcoded delta=50. $items = array(); for ($i = -50; $i <= 51; $i++) { $items[$i] = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name, TRUE, strval($i)); @@ -279,10 +316,10 @@ class MenuTest extends WebTestBase { } /** - * Add and remove a menu link with a query string and fragment. + * Tests addition and removal of a menu link with a query string and fragment. */ function testMenuQueryAndFragment() { - $this->drupalLogin($this->big_user); + $this->drupalLogin($this->adminUser); // Make a path with query and fragment on. $path = 'node?arg1=value1&arg2=value2'; @@ -299,13 +336,22 @@ class MenuTest extends WebTestBase { } /** - * Add a menu link using the menu module UI. + * Tests the addition of a menu link using the menu module UI. * - * @param integer $plid Parent menu link id. - * @param string $link Link path. - * @param string $menu_name Menu name. - * @param string $weight Menu weight - * @return array Menu link created. + * @param integer $plid + * (optional) Parent menu link id. Defaults to zero. + * @param string $link + * (optional) Link path. Defaults to ''. + * @param string $menu_name + * (optional) Menu name. Defaults to 'navigation'. + * @param bool $expanded + * (optional) A boolean indicating whether the meny should be expanded. + * Defautls to TRUE. + * @param string $weight + * (optional) Menu weight. Defaults to '0'. + * + * @return array + * The cretaed menu link. */ function addMenuLink($plid = 0, $link = '', $menu_name = 'navigation', $expanded = TRUE, $weight = '0') { // View add menu link page. @@ -317,8 +363,11 @@ class MenuTest extends WebTestBase { 'link_path' => $link, 'link_title' => $title, 'description' => '', - 'enabled' => TRUE, // Use this to disable the menu and test. - 'expanded' => $expanded, // Setting this to true should test whether it works when we do the std_user tests. + // Use this to disable the menu and test. + 'enabled' => TRUE, + // Setting this to true should test whether it works when we do the + // standardUser tests. + 'expanded' => $expanded, 'parent' => $menu_name . ':' . $plid, 'weight' => $weight, ); @@ -337,9 +386,10 @@ class MenuTest extends WebTestBase { } /** - * Attempt to add menu link with invalid path or no access permission. + * Attempts to add menu link with invalid path or no access permission. * - * @param string $menu_name Menu name. + * @param string $menu_name + * (optional) The menu name. Defaults to 'navigation'. */ function addInvalidMenuLink($menu_name = 'navigation') { foreach (array('-&-', 'admin/people/permissions', '#') as $link_path) { @@ -353,12 +403,16 @@ class MenuTest extends WebTestBase { } /** - * Verify a menu link using the menu module UI. + * Verifies a menu link using the menu module UI. * - * @param array $item Menu link. - * @param object $item_node Menu link content node. - * @param array $parent Parent menu link. - * @param object $parent_node Parent menu link content node. + * @param array $item + * A menu link. + * @param object $item_node + * Menu link content node. + * @param array $parent + * (optional) Parent menu link. Defaults to NULL. + * @param object $parent_node + * (optional) Parent menu link content node. Defaults to NULL. */ function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) { // View home page. @@ -388,7 +442,14 @@ class MenuTest extends WebTestBase { } /** - * Change the parent of a menu link using the menu module UI. + * Changes the parent of a menu link using the menu module UI. + * + * @param array $item + * A menu link. + * @param integer $plid + * Parent menu link id. + * @param string $menu_name + * Menu name. */ function moveMenuLink($item, $plid, $menu_name) { $mlid = $item['mlid']; @@ -401,9 +462,10 @@ class MenuTest extends WebTestBase { } /** - * Modify a menu link using the menu module UI. + * Modifies a menu link using the menu module UI. * - * @param array $item Menu link passed by reference. + * @param array $item + * Menu link passed by reference. */ function modifyMenuLink(&$item) { $item['link_title'] = $this->randomName(16); @@ -424,10 +486,12 @@ class MenuTest extends WebTestBase { } /** - * Reset a standard menu link using the menu module UI. + * Resets a standard menu link using the menu module UI. * - * @param array $item Menu link. - * @param string $old_title Original title for menu link. + * @param array $item + * Menu link. + * @param string $old_title + * Original title for menu link. */ function resetMenuLink($item, $old_title) { $mlid = $item['mlid']; @@ -445,9 +509,10 @@ class MenuTest extends WebTestBase { } /** - * Delete a menu link using the menu module UI. + * Deletes a menu link using the menu module UI. * - * @param array $item Menu link. + * @param array $item + * Menu link. */ function deleteMenuLink($item) { $mlid = $item['mlid']; @@ -464,9 +529,9 @@ class MenuTest extends WebTestBase { } /** - * Alternately disable and enable a menu link. + * Disables and enables a menu link alternatively. * - * @param $item + * @param array $item * Menu link. */ function toggleMenuLink($item) { @@ -483,9 +548,9 @@ class MenuTest extends WebTestBase { } /** - * Disable a menu link. + * Disables a menu link. * - * @param $item + * @param array $item * Menu link. */ function disableMenuLink($item) { @@ -499,9 +564,9 @@ class MenuTest extends WebTestBase { } /** - * Enable a menu link. + * Enables a menu link. * - * @param $item + * @param array $item * Menu link. */ function enableMenuLink($item) { @@ -514,12 +579,11 @@ class MenuTest extends WebTestBase { } /** - * Fetch the menu item from the database and compare it to the specified - * array. + * Fetches the menu item from database and compares it to specified array. * * @param $mlid * Menu item id. - * @param $item + * @param $expected_item * Array containing properties to verify. */ function assertMenuLink($mlid, array $expected_item) { @@ -538,7 +602,10 @@ class MenuTest extends WebTestBase { } /** - * Get standard menu link. + * Gets standard menu link. + * + * @return + * A standard menu link. */ private function getStandardMenuLink() { // Retrieve menu link id of the Log out menu link, which will always be on the front page. @@ -552,9 +619,10 @@ class MenuTest extends WebTestBase { } /** - * Verify the logged in user has the desired access to the various menu nodes. + * Verifies the logged in user has the desired access to various menu nodes. * - * @param integer $response HTTP response code. + * @param integer $response + * (optional) The HTTP response code. Defaults to 200. */ private function verifyAccess($response = 200) { // View menu help node. diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index c8be6af..6942352 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -183,8 +183,11 @@ function menu_overview_form_submit($form, &$form_state) { // parent. To prevent this, save items in the form in the same order they // are sent by $_POST, ensuring parents are saved first, then their children. // See http://drupal.org/node/181126#comment-632270 - $order = array_flip(array_keys($form_state['input'])); // Get the $_POST order. - $form = array_intersect_key(array_merge($order, $form), $form); // Update our original form with the new order. + + // Get the $_POST order. + $order = array_flip(array_keys($form_state['input'])); + // Update our original form with the new order. + $form = array_intersect_key(array_merge($order, $form), $form); $updated_items = array(); $fields = array('weight', 'plid'); @@ -290,10 +293,10 @@ function theme_menu_overview_form($variables) { * When $type is 'add', an array representing the menu the link will be added * to; when $type is 'edit', NULL. * - * @see menu_menu() - * @see menu_edit_item_validate() * @see menu_edit_item_submit() + * @see menu_edit_item_validate() * @see menu_item_delete_submit() + * @see menu_menu() * @ingroup forms */ function menu_edit_item($form, &$form_state, $type, $item, $menu) { @@ -468,8 +471,8 @@ function menu_item_delete_submit($form, &$form_state) { function menu_edit_item_submit($form, &$form_state) { $item = &$form_state['values']; - // The value of "hidden" is the opposite of the value - // supplied by the "enabled" checkbox. + // The value of "hidden" is the opposite of the value supplied by the + // "enabled" checkbox. $item['hidden'] = (int) !$item['enabled']; unset($item['enabled']); @@ -491,11 +494,11 @@ function menu_edit_item_submit($form, &$form_state) { * The type of operation being done, 'add' or 'edit'. * @param $menu * (optional) When $type is 'edit', an array representing the menu that is to - * be edited. + * be edited. Defaults to empty array. * - * @see menu_menu() - * @see menu_edit_menu_submit() * @see menu_custom_delete_submit() + * @see menu_edit_menu_submit() + * @see menu_menu() * @ingroup forms */ function menu_edit_menu($form, &$form_state, $type, $menu = array()) { @@ -577,6 +580,7 @@ function menu_custom_delete_submit($form, &$form_state) { * @return array * A renderable array. * + * @see menu_delete_menu_confirm() * @see menu_menu() */ function menu_delete_menu_page($menu) { @@ -653,7 +657,6 @@ function menu_delete_menu_confirm_submit($form, &$form_state) { * TRUE if the menu name already exists; FALSE otherwise. * * @see menu_edit_menu() - * @see form_validate_machine_name() */ function menu_edit_menu_name_exists($value) { // 'menu-' is added to the menu name to avoid name-space conflicts. @@ -710,6 +713,7 @@ function menu_edit_menu_submit($form, &$form_state) { * @return aray * A renderable array. * + * @see menu_item_delete_form() * @see menu_menu() */ function menu_item_delete_page($item) { @@ -775,9 +779,9 @@ function menu_reset_item_confirm_submit($form, &$form_state) { /** * Form constructor for the menu configuration form. * - * @ingroup forms - * @see menu_menu() * @see menu_configure_submit() + * @see menu_menu() + * @ingroup forms */ function menu_configure($form, &$form_state) { $config = config('menu.settings'); diff --git a/core/modules/menu/menu.api.php b/core/modules/menu/menu.api.php index 4f4cbac..22256e1 100644 --- a/core/modules/menu/menu.api.php +++ b/core/modules/menu/menu.api.php @@ -11,7 +11,7 @@ */ /** - * Respond to custom menu creation. + * Responds to custom menu creation. * * This hook is used to notify modules that a custom menu has been created. * Contributed modules may use the information to perform actions based on the @@ -23,8 +23,8 @@ * - title: The human readable menu title. * - description: The custom menu description. * - * @see hook_menu_update() * @see hook_menu_delete() + * @see hook_menu_update() */ function hook_menu_insert($menu) { // For example, we track available menus in a variable. @@ -34,7 +34,7 @@ function hook_menu_insert($menu) { } /** - * Respond to a custom menu update. + * Responds to a custom menu update. * * This hook is used to notify modules that a custom menu has been updated. * Contributed modules may use the information to perform actions based on the @@ -59,7 +59,7 @@ function hook_menu_update($menu) { } /** - * Respond to custom menu deletion. + * Responds to custom menu deletion. * * This hook is used to notify modules that a custom menu along with all links * contained in it (if any) has been deleted. Contributed modules may use the diff --git a/core/modules/menu/menu.js b/core/modules/menu/menu.js index dee71ec..16bf5cc 100644 --- a/core/modules/menu/menu.js +++ b/core/modules/menu/menu.js @@ -21,7 +21,7 @@ Drupal.behaviors.menuFieldsetSummaries = { }; /** - * Automatically fill in a menu link title, if possible. + * Fills in a menu link title automatically, if possible. */ Drupal.behaviors.menuLinkAutomaticTitle = { attach: function (context) { @@ -37,8 +37,9 @@ Drupal.behaviors.menuLinkAutomaticTitle = { if (!($checkbox.length && $link_title.length && $title.length)) { return; } - // If there is a link title already, mark it as overridden. The user expects - // that toggling the checkbox twice will take over the node's title. + // If there is a link title already, mark it as overridden. The user + // expects that toggling the checkbox twice will take over the node's + // title. if ($checkbox.is(':checked') && $link_title.val().length) { $link_title.data('menuLinkAutomaticTitleOveridden', true); } diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index e0c3b7d..8e995a4 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -189,7 +189,8 @@ function menu_enable() { $base_link['module'] = 'menu'; $result = db_query("SELECT * FROM {menu_custom}", array(), array('fetch' => PDO::FETCH_ASSOC)); foreach ($result as $menu) { - // $link is passed by reference to menu_link_save(), so we make a copy of $base_link. + // $link is passed by reference to menu_link_save(), so we make a copy of + // $base_link. $link = $base_link; $link['mlid'] = 0; $link['link_title'] = $menu['title']; @@ -212,6 +213,9 @@ function menu_enable() { * @param $menu * An array defining a custom menu. * + * @return + * An unsanitized string that is the title of a custom menu. + * * @see menu_menu() */ function menu_overview_title($menu) { @@ -352,8 +356,8 @@ function menu_delete($menu) { * The menu item or the node type for which to generate a list of parents. If * $item['mlid'] == 0 then the complete tree is returned. * @param $type - * The node type for which to generate a list of parents. If $item itself is a - * node type then $type is ignored. + * (optional) The node type for which to generate a list of parents. If $item + * itself is a node type then $type is ignored. Defaults to an empty string. * * @return * An array of menu link titles keyed on the a string containing the menu name @@ -398,6 +402,9 @@ function menu_parent_options($menus, $item, $type = '') { * * The menus and menu items are output as a JavaScript array. * + * @return Symfony\Component\HttpFoundation\JsonResponse + * A JSON response object. + * * @see menu_menu() */ function menu_parent_options_js() { @@ -520,8 +527,8 @@ function menu_block_info() { $blocks = array(); foreach ($menus as $name => $title) { $blocks[$name]['info'] = check_plain($title); - // Menu blocks can't be cached because each menu item can have - // a custom access callback. menu.inc manages its own caching. + // Menu blocks cannot be cached because each menu item can have a custom + // access callback. menu.inc manages its own caching. $blocks[$name]['cache'] = DRUPAL_NO_CACHE; } return $blocks; @@ -684,14 +691,15 @@ function _menu_parent_depth_limit($item) { * @see menu_node_submit() */ function menu_form_node_form_alter(&$form, $form_state) { - // Generate a list of possible parents (not including this link or descendants). + // Generate a list of possible parents (not including this link or + // descendants). // @todo This must be handled in a #process handler. $node = $form_state['controller']->getEntity($form_state); $link = $node->menu; $type = $node->type; // menu_parent_options() is goofy and can actually handle either a menu link - // or a node type both as second argument. Pick based on whether there is - // a link already (menu_node_prepare() sets mlid default to 0). + // or a node type both as second argument. Pick based on whether there is a + // link already (menu_node_prepare() sets mlid default to 0). $options = menu_parent_options(menu_get_menus(), $link['mlid'] ? $link : $type, $type); // If no possible parent menu items were found, there is nothing to display. if (empty($options)) { @@ -772,7 +780,7 @@ function menu_form_node_form_alter(&$form, $form_state) { } } if ($delta < 50) { - // Old hardcoded value + // Old hardcoded value. $delta = 50; } $form['menu']['link']['weight'] = array( @@ -836,8 +844,8 @@ function menu_form_node_type_form_alter(&$form, $form_state) { '#attributes' => array('class' => array('menu-title-select')), ); - // Call Drupal.menuUpdateParentList() to filter the list of - // available default parent menu items based on the selected menus. + // Call Drupal.menuUpdateParentList() to filter the list of available default + // parent menu items based on the selected menus. drupal_add_js( '(function ($) { Drupal.menuUpdateParentList(); })(jQuery);', array('scope' => 'footer', 'type' => 'inline') @@ -848,8 +856,8 @@ function menu_form_node_type_form_alter(&$form, $form_state) { * Returns an associative array of the custom menu names. * * @param $all - * If FALSE return only user-added menus, or if TRUE also include - * the menus defined by the system. + * (optional) If FALSE return only user-added menus, or if TRUE also include + * the menus defined by the system. Defaults to TRUE. * * @return * An array with the machine-readable names as the keys, and human-readable