5 * Tests for menu.module.
8 class MenuTestCase extends DrupalWebTestCase {
14 public static function getInfo() {
16 'name' => 'Menu link creation/deletion',
17 'description' => 'Add a custom menu, add menu links to the custom menu and Navigation menu, check their data, and delete them using the menu module UI.',
23 parent::setUp('menu');
25 $this->big_user = $this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content'));
26 $this->std_user = $this->drupalCreateUser(array());
30 * Login users, add menus and menu links, and test menu functionality through the admin and user interfaces.
34 $this->drupalLogin($this->big_user);
35 $this->items = array();
37 // Do standard menu tests.
38 $this->doStandardMenuTests();
40 // Do custom menu tests.
41 $this->doCustomMenuTests();
43 // Do standard user tests.
45 $this->drupalLogin($this->std_user);
46 $this->verifyAccess(403);
47 foreach ($this->items as $item) {
48 $node = node_load(substr($item['link_path'], 5)); // Paths were set as 'node/$nid'.
49 $this->verifyMenuLink($item, $node);
53 $this->drupalLogin($this->big_user);
56 foreach ($this->items as $item) {
57 $this->deleteMenuLink($item);
60 // Delete custom menu.
61 $this->deleteCustomMenu($this->menu);
63 // Modify and reset a standard menu link.
64 $item = $this->getStandardMenuLink();
65 $old_title = $item['link_title'];
66 $this->modifyMenuLink($item);
67 $item = menu_link_load($item['mlid']);
68 // Verify that a change to the description is saved.
69 $description = $this->randomName(16);
70 $item['options']['attributes']['title'] = $description;
71 menu_link_save($item);
72 $saved_item = menu_link_load($item['mlid']);
73 $this->assertEqual($description, $saved_item['options']['attributes']['title'], 'Saving an existing link updates the description (title attribute)');
74 $this->resetMenuLink($item, $old_title);
76 // Test that the page title is correct when a local task appears in a
77 // top-level menu item. See https://www.drupal.org/node/1973262.
78 $item = $this->addMenuLink(0, 'user/register', 'user-menu');
79 $this->drupalGet('user/password');
80 $this->assertNoTitle('Home | Drupal');
81 $this->drupalLogout();
82 $this->drupalGet('user/register');
83 $this->assertTitle($item['link_title'] . ' | Drupal');
84 $this->drupalGet('user');
85 $this->assertNoTitle('Home | Drupal');
89 * Test standard menu functionality using navigation menu.
92 function doStandardMenuTests() {
94 $this->addInvalidMenuLink();
98 * Test custom menu functionality using navigation menu.
101 function doCustomMenuTests() {
102 $this->menu = $this->addCustomMenu();
103 $this->doMenuTests($this->menu['menu_name']);
104 $this->addInvalidMenuLink($this->menu['menu_name']);
105 $this->addCustomMenuCRUD();
109 * Add custom menu using CRUD functions.
111 function addCustomMenuCRUD() {
112 // Add a new custom menu.
113 $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
114 $title = $this->randomName(16);
117 'menu_name' => $menu_name,
119 'description' => 'Description text',
123 // Assert the new menu.
124 $this->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
125 $this->assertRaw($title, 'Custom menu was added.');
128 $new_title = $this->randomName(16);
129 $menu['title'] = $new_title;
131 $this->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
132 $this->assertRaw($new_title, 'Custom menu was edited.');
138 function addCustomMenu() {
141 // Try adding a menu using a menu_name that is too long.
142 $this->drupalGet('admin/structure/menu/add');
143 $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1);
144 $title = $this->randomName(16);
146 'menu_name' => $menu_name,
150 $this->drupalPost('admin/structure/menu/add', $edit, t('Save'));
152 // Verify that using a menu_name that is too long results in a validation message.
153 $this->assertRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
154 '!name' => t('Menu name'),
155 '%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
156 '%length' => drupal_strlen($menu_name),
159 // Change the menu_name so it no longer exceeds the maximum length.
160 $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
161 $edit['menu_name'] = $menu_name;
162 $this->drupalPost('admin/structure/menu/add', $edit, t('Save'));
164 // Verify that no validation error is given for menu_name length.
165 $this->assertNoRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
166 '!name' => t('Menu name'),
167 '%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
168 '%length' => drupal_strlen($menu_name),
170 // Unlike most other modules, there is no confirmation message displayed.
172 $this->drupalGet('admin/structure/menu');
173 $this->assertText($title, 'Menu created');
175 // Enable the custom menu block.
176 $menu_name = 'menu-' . $menu_name; // Drupal prepends the name with 'menu-'.
178 $edit['blocks[menu_' . $menu_name . '][region]'] = 'sidebar_first';
179 $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
180 $this->assertResponse(200);
181 $this->assertText(t('The block settings have been updated.'), 'Custom menu block was enabled');
183 return menu_load($menu_name);
187 * Delete custom menu.
189 * @param string $menu_name Custom menu name.
191 function deleteCustomMenu($menu) {
192 $menu_name = $this->menu['menu_name'];
193 $title = $this->menu['title'];
195 // Delete custom menu.
196 $this->drupalPost("admin/structure/menu/manage/$menu_name/delete", array(), t('Delete'));
197 $this->assertResponse(200);
198 $this->assertRaw(t('The custom menu %title has been deleted.', array('%title' => $title)), 'Custom menu was deleted');
199 $this->assertFalse(menu_load($menu_name), 'Custom menu was deleted');
200 // Test if all menu links associated to the menu were removed from database.
201 $result = db_query("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name))->fetchField();
202 $this->assertFalse($result, 'All menu links associated to the custom menu were deleted.');
206 * Test menu functionality using navigation menu.
209 function doMenuTests($menu_name = 'navigation') {
210 // Add nodes to use as links for menu links.
211 $node1 = $this->drupalCreateNode(array('type' => 'article'));
212 $node2 = $this->drupalCreateNode(array('type' => 'article'));
213 $node3 = $this->drupalCreateNode(array('type' => 'article'));
214 $node4 = $this->drupalCreateNode(array('type' => 'article'));
215 $node5 = $this->drupalCreateNode(array('type' => 'article'));
218 $item1 = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name);
219 $item2 = $this->addMenuLink($item1['mlid'], 'node/' . $node2->nid, $menu_name, FALSE);
220 $item3 = $this->addMenuLink($item2['mlid'], 'node/' . $node3->nid, $menu_name);
221 $this->assertMenuLink($item1['mlid'], array('depth' => 1, 'has_children' => 1, 'p1' => $item1['mlid'], 'p2' => 0));
222 $this->assertMenuLink($item2['mlid'], array('depth' => 2, 'has_children' => 1, 'p1' => $item1['mlid'], 'p2' => $item2['mlid'], 'p3' => 0));
223 $this->assertMenuLink($item3['mlid'], array('depth' => 3, 'has_children' => 0, 'p1' => $item1['mlid'], 'p2' => $item2['mlid'], 'p3' => $item3['mlid'], 'p4' => 0));
225 // Verify menu links.
226 $this->verifyMenuLink($item1, $node1);
227 $this->verifyMenuLink($item2, $node2, $item1, $node1);
228 $this->verifyMenuLink($item3, $node3, $item2, $node2);
230 // Add more menu links.
231 $item4 = $this->addMenuLink(0, 'node/' . $node4->nid, $menu_name);
232 $item5 = $this->addMenuLink($item4['mlid'], 'node/' . $node5->nid, $menu_name);
233 $this->assertMenuLink($item4['mlid'], array('depth' => 1, 'has_children' => 1, 'p1' => $item4['mlid'], 'p2' => 0));
234 $this->assertMenuLink($item5['mlid'], array('depth' => 2, 'has_children' => 0, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => 0));
236 // Modify menu links.
237 $this->modifyMenuLink($item1);
238 $this->modifyMenuLink($item2);
240 // Toggle menu links.
241 $this->toggleMenuLink($item1);
242 $this->toggleMenuLink($item2);
244 // Move link and verify that descendants are updated.
245 $this->moveMenuLink($item2, $item5['mlid'], $menu_name);
246 $this->assertMenuLink($item1['mlid'], array('depth' => 1, 'has_children' => 0, 'p1' => $item1['mlid'], 'p2' => 0));
247 $this->assertMenuLink($item4['mlid'], array('depth' => 1, 'has_children' => 1, 'p1' => $item4['mlid'], 'p2' => 0));
248 $this->assertMenuLink($item5['mlid'], array('depth' => 2, 'has_children' => 1, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => 0));
249 $this->assertMenuLink($item2['mlid'], array('depth' => 3, 'has_children' => 1, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => $item2['mlid'], 'p4' => 0));
250 $this->assertMenuLink($item3['mlid'], array('depth' => 4, 'has_children' => 0, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => $item2['mlid'], 'p4' => $item3['mlid'], 'p5' => 0));
252 // Enable a link via the overview form.
253 $this->disableMenuLink($item1);
256 // Note in the UI the 'mlid:x[hidden]' form element maps to enabled, or
258 $edit['mlid:' . $item1['mlid'] . '[hidden]'] = TRUE;
259 $this->drupalPost('admin/structure/menu/manage/' . $item1['menu_name'], $edit, t('Save configuration'));
261 // Verify in the database.
262 $this->assertMenuLink($item1['mlid'], array('hidden' => 0));
264 // Save menu links for later tests.
265 $this->items[] = $item1;
266 $this->items[] = $item2;
270 * Add and remove a menu link with a query string and fragment.
272 function testMenuQueryAndFragment() {
273 $this->drupalLogin($this->big_user);
275 // Make a path with query and fragment on.
276 $path = 'node?arg1=value1&arg2=value2';
277 $item = $this->addMenuLink(0, $path);
279 $this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
280 $this->assertFieldByName('link_path', $path, 'Path is found with both query and fragment.');
282 // Now change the path to something without query and fragment.
284 $this->drupalPost('admin/structure/menu/item/' . $item['mlid'] . '/edit', array('link_path' => $path), t('Save'));
285 $this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
286 $this->assertFieldByName('link_path', $path, 'Path no longer has query or fragment.');
290 * Add a menu link using the menu module UI.
292 * @param integer $plid Parent menu link id.
293 * @param string $link Link path.
294 * @param string $menu_name Menu name.
295 * @return array Menu link created.
297 function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE) {
298 // View add menu link page.
299 $this->drupalGet("admin/structure/menu/manage/$menu_name/add");
300 $this->assertResponse(200);
302 $title = '!link_' . $this->randomName(16);
304 'link_path' => $link,
305 'link_title' => $title,
307 'enabled' => TRUE, // Use this to disable the menu and test.
308 'expanded' => $expanded, // Setting this to true should test whether it works when we do the std_user tests.
309 'parent' => $menu_name . ':' . $plid,
314 $this->drupalPost(NULL, $edit, t('Save'));
315 $this->assertResponse(200);
316 // Unlike most other modules, there is no confirmation message displayed.
317 $this->assertText($title, 'Menu link was added');
319 $item = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(':title' => $title))->fetchAssoc();
320 $this->assertTrue(t('Menu link was found in database.'));
321 $this->assertMenuLink($item['mlid'], array('menu_name' => $menu_name, 'link_path' => $link, 'has_children' => 0, 'plid' => $plid));
327 * Attempt to add menu link with invalid path or no access permission.
329 * @param string $menu_name Menu name.
331 function addInvalidMenuLink($menu_name = 'navigation') {
332 foreach (array('-&-', 'admin/people/permissions', '#') as $link_path) {
334 'link_path' => $link_path,
335 'link_title' => 'title',
337 $this->drupalPost("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
338 $this->assertRaw(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $link_path)), 'Menu link was not created');
343 * Verify a menu link using the menu module UI.
345 * @param array $item Menu link.
346 * @param object $item_node Menu link content node.
347 * @param array $parent Parent menu link.
348 * @param object $parent_node Parent menu link content node.
350 function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) {
352 $this->drupalGet('');
353 $this->assertResponse(200);
355 // Verify parent menu link.
356 if (isset($parent)) {
358 $title = $parent['link_title'];
359 $this->assertLink($title, 0, 'Parent menu link was displayed');
361 // Verify menu link link.
362 $this->clickLink($title);
363 $title = $parent_node->title;
364 $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Parent menu link link target was correct');
368 $title = $item['link_title'];
369 $this->assertLink($title, 0, 'Menu link was displayed');
371 // Verify menu link link.
372 $this->clickLink($title);
373 $title = $item_node->title;
374 $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Menu link link target was correct');
378 * Change the parent of a menu link using the menu module UI.
380 function moveMenuLink($item, $plid, $menu_name) {
381 $mlid = $item['mlid'];
384 'parent' => $menu_name . ':' . $plid,
386 $this->drupalPost("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
387 $this->assertResponse(200);
391 * Modify a menu link using the menu module UI.
393 * @param array $item Menu link passed by reference.
395 function modifyMenuLink(&$item) {
396 $item['link_title'] = $this->randomName(16);
398 $mlid = $item['mlid'];
399 $title = $item['link_title'];
403 $edit['link_title'] = $title;
404 $this->drupalPost("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
405 $this->assertResponse(200);
406 // Unlike most other modules, there is no confirmation message displayed.
409 $this->drupalGet('admin/structure/menu/manage/' . $item['menu_name']);
410 $this->assertText($title, 'Menu link was edited');
414 * Reset a standard menu link using the menu module UI.
416 * @param array $item Menu link.
417 * @param string $old_title Original title for menu link.
419 function resetMenuLink($item, $old_title) {
420 $mlid = $item['mlid'];
421 $title = $item['link_title'];
424 $this->drupalPost("admin/structure/menu/item/$mlid/reset", array(), t('Reset'));
425 $this->assertResponse(200);
426 $this->assertRaw(t('The menu link was reset to its default settings.'), 'Menu link was reset');
429 $this->drupalGet('');
430 $this->assertNoText($title, 'Menu link was reset');
431 $this->assertText($old_title, 'Menu link was reset');
435 * Delete a menu link using the menu module UI.
437 * @param array $item Menu link.
439 function deleteMenuLink($item) {
440 $mlid = $item['mlid'];
441 $title = $item['link_title'];
444 $this->drupalPost("admin/structure/menu/item/$mlid/delete", array(), t('Confirm'));
445 $this->assertResponse(200);
446 $this->assertRaw(t('The menu link %title has been deleted.', array('%title' => $title)), 'Menu link was deleted');
449 $this->drupalGet('');
450 $this->assertNoText($title, 'Menu link was deleted');
454 * Alternately disable and enable a menu link.
459 function toggleMenuLink($item) {
460 $this->disableMenuLink($item);
462 // Verify menu link is absent.
463 $this->drupalGet('');
464 $this->assertNoText($item['link_title'], 'Menu link was not displayed');
465 $this->enableMenuLink($item);
467 // Verify menu link is displayed.
468 $this->drupalGet('');
469 $this->assertText($item['link_title'], 'Menu link was displayed');
473 * Disable a menu link.
478 function disableMenuLink($item) {
479 $mlid = $item['mlid'];
480 $edit['enabled'] = FALSE;
481 $this->drupalPost("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
483 // Unlike most other modules, there is no confirmation message displayed.
484 // Verify in the database.
485 $this->assertMenuLink($mlid, array('hidden' => 1));
489 * Enable a menu link.
494 function enableMenuLink($item) {
495 $mlid = $item['mlid'];
496 $edit['enabled'] = TRUE;
497 $this->drupalPost("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
499 // Verify in the database.
500 $this->assertMenuLink($mlid, array('hidden' => 0));
504 * Fetch the menu item from the database and compare it to the specified
510 * Array containing properties to verify.
512 function assertMenuLink($mlid, array $expected_item) {
513 // Retrieve menu link.
514 $item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array(':mlid' => $mlid))->fetchAssoc();
515 $options = unserialize($item['options']);
516 if (!empty($options['query'])) {
517 $item['link_path'] .= '?' . drupal_http_build_query($options['query']);
519 if (!empty($options['fragment'])) {
520 $item['link_path'] .= '#' . $options['fragment'];
522 foreach ($expected_item as $key => $value) {
523 $this->assertEqual($item[$key], $value, format_string('Parameter %key had expected value.', array('%key' => $key)));
528 * Test administrative users other than user 1 can access the menu parents AJAX callback.
530 public function testMenuParentsJsAccess() {
531 $admin = $this->drupalCreateUser(array('administer menu'));
532 $this->drupalLogin($admin);
533 // Just check access to the callback overall, the POST data is irrelevant.
534 $this->drupalGetAJAX('admin/structure/menu/parents');
535 $this->assertResponse(200);
537 // Do standard user tests.
539 $this->drupalLogin($this->std_user);
540 $this->drupalGetAJAX('admin/structure/menu/parents');
541 $this->assertResponse(403);
545 * Get standard menu link.
547 private function getStandardMenuLink() {
548 // Retrieve menu link id of the Log out menu link, which will always be on the front page.
549 $mlid = db_query("SELECT mlid FROM {menu_links} WHERE module = 'system' AND router_path = 'user/logout'")->fetchField();
550 $this->assertTrue($mlid > 0, 'Standard menu link id was found');
552 // Use api function so that link is translated for rendering.
553 $item = menu_link_load($mlid);
554 $this->assertTrue((bool) $item, 'Standard menu link was loaded');
559 * Verify the logged in user has the desired access to the various menu nodes.
561 * @param integer $response HTTP response code.
563 private function verifyAccess($response = 200) {
564 // View menu help node.
565 $this->drupalGet('admin/help/menu');
566 $this->assertResponse($response);
567 if ($response == 200) {
568 $this->assertText(t('Menu'), 'Menu help was displayed');
571 // View menu build overview node.
572 $this->drupalGet('admin/structure/menu');
573 $this->assertResponse($response);
574 if ($response == 200) {
575 $this->assertText(t('Menus'), 'Menu build overview node was displayed');
578 // View navigation menu customization node.
579 $this->drupalGet('admin/structure/menu/manage/navigation');
580 $this->assertResponse($response);
581 if ($response == 200) {
582 $this->assertText(t('Navigation'), 'Navigation menu node was displayed');
585 // View menu edit node.
586 $item = $this->getStandardMenuLink();
587 $this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
588 $this->assertResponse($response);
589 if ($response == 200) {
590 $this->assertText(t('Edit menu item'), 'Menu edit node was displayed');
593 // View menu settings node.
594 $this->drupalGet('admin/structure/menu/settings');
595 $this->assertResponse($response);
596 if ($response == 200) {
597 $this->assertText(t('Menus'), 'Menu settings node was displayed');
600 // View add menu node.
601 $this->drupalGet('admin/structure/menu/add');
602 $this->assertResponse($response);
603 if ($response == 200) {
604 $this->assertText(t('Menus'), 'Add menu node was displayed');
610 * Test menu settings for nodes.
612 class MenuNodeTestCase extends DrupalWebTestCase {
613 public static function getInfo() {
615 'name' => 'Menu settings for nodes',
616 'description' => 'Add, edit, and delete a node with menu link.',
622 parent::setUp('menu');
624 $this->admin_user = $this->drupalCreateUser(array(
625 'access administration pages',
626 'administer content types',
628 'create page content',
629 'edit any page content',
630 'delete any page content',
632 $this->drupalLogin($this->admin_user);
636 * Test creating, editing, deleting menu links via node form widget.
638 function testMenuNodeFormWidget() {
639 // Enable Navigation menu as available menu.
641 'menu_options[navigation]' => 1,
643 $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
644 // Change default parent item to Navigation menu, so we can assert more
647 'menu_parent' => 'navigation:0',
649 $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
651 // Verify that the menu link title on the node add form has the correct
653 $this->drupalGet('node/add/page');
654 $this->assertPattern('/<input .* id="edit-menu-link-title" .* maxlength="255" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
656 // Create a node with menu link disabled.
657 $node_title = $this->randomName();
658 $language = LANGUAGE_NONE;
660 "title" => $node_title,
661 "body[$language][0][value]" => $this->randomString(),
663 $this->drupalPost('node/add/page', $edit, t('Save'));
664 $node = $this->drupalGetNodeByTitle($node_title);
665 // Assert that there is no link for the node.
666 $this->drupalGet('');
667 $this->assertNoLink($node_title);
669 // Edit the node, enable the menu link setting, but skip the link title.
671 'menu[enabled]' => 1,
673 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
674 // Assert that there is no link for the node.
675 $this->drupalGet('');
676 $this->assertNoLink($node_title);
678 // Edit the node and create a menu link.
680 'menu[enabled]' => 1,
681 'menu[link_title]' => $node_title,
682 'menu[weight]' => 17,
684 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
685 // Assert that the link exists.
686 $this->drupalGet('');
687 $this->assertLink($node_title);
689 $this->drupalGet('node/' . $node->nid . '/edit');
690 $this->assertOptionSelected('edit-menu-weight', 17, 'Menu weight correct in edit form');
692 // Verify that the menu link title on the node edit form has the correct
694 $this->assertPattern('/<input .* id="edit-menu-link-title" .* maxlength="255" .* \/>/', 'Menu link title field has correct maxlength in node edit form.');
696 // Edit the node and remove the menu link.
698 'menu[enabled]' => FALSE,
700 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
701 // Assert that there is no link for the node.
702 $this->drupalGet('');
703 $this->assertNoLink($node_title);
705 // Add a menu link to the Management menu.
707 'link_path' => 'node/' . $node->nid,
708 'link_title' => $this->randomName(16),
709 'menu_name' => 'management',
711 menu_link_save($item);
713 // Assert that disabled Management menu is not shown on the node/$nid/edit page.
714 $this->drupalGet('node/' . $node->nid . '/edit');
715 $this->assertText('Provide a menu link', 'Link in not allowed menu not shown in node edit form');
716 // Assert that the link is still in the management menu after save.
717 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
718 $link = menu_link_load($item['mlid']);
719 $this->assertTrue($link, 'Link in not allowed menu still exists after saving node');
721 // Move the menu link back to the Navigation menu.
722 $item['menu_name'] = 'navigation';
723 menu_link_save($item);
724 // Create a second node.
725 $child_node = $this->drupalCreateNode(array('type' => 'article'));
726 // Assign a menu link to the second node, being a child of the first one.
728 'link_path' => 'node/'. $child_node->nid,
729 'link_title' => $this->randomName(16),
730 'plid' => $item['mlid'],
732 menu_link_save($child_item);
733 // Edit the first node.
734 $this->drupalGet('node/'. $node->nid .'/edit');
735 // Assert that it is not possible to set the parent of the first node to itself or the second node.
736 $this->assertNoOption('edit-menu-parent', 'navigation:'. $item['mlid']);
737 $this->assertNoOption('edit-menu-parent', 'navigation:'. $child_item['mlid']);
738 // Assert that unallowed Management menu is not available in options.
739 $this->assertNoOption('edit-menu-parent', 'management:0');
743 * Asserts that a select option in the current page does not exist.
746 * Id of select field to assert.
750 * Message to display.
752 * TRUE on pass, FALSE on fail.
754 * @todo move to simpletest drupal_web_test_case.php.
756 protected function assertNoOption($id, $option, $message = '') {
757 $selects = $this->xpath('//select[@id=:id]', array(':id' => $id));
758 $options = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option));
759 return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), t('Browser'));