You are here

class MenuTestCase in Drupal 7

@file Tests for menu.module.

Hierarchy

Expanded class hierarchy of MenuTestCase

File

modules/menu/menu.test, line 8
Tests for menu.module.

View source
class MenuTestCase extends DrupalWebTestCase {
  protected $big_user;
  protected $std_user;
  protected $menu;
  protected $items;
  public static function getInfo() {
    return array(
      'name' => 'Menu link creation/deletion',
      '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.',
      'group' => 'Menu',
    );
  }
  function setUp() {
    parent::setUp('menu');

    // Create users.
    $this->big_user = $this
      ->drupalCreateUser(array(
      'access administration pages',
      'administer blocks',
      'administer menu',
      'create article content',
    ));
    $this->std_user = $this
      ->drupalCreateUser(array());
  }

  /**
   * Login users, add menus and menu links, and test menu functionality through the admin and user interfaces.
   */
  function testMenu() {

    // Login the user.
    $this
      ->drupalLogin($this->big_user);
    $this->items = array();

    // Do standard menu tests.
    $this
      ->doStandardMenuTests();

    // Do custom menu tests.
    $this
      ->doCustomMenuTests();

    // Do standard user tests.
    // Login the user.
    $this
      ->drupalLogin($this->std_user);
    $this
      ->verifyAccess(403);
    foreach ($this->items as $item) {
      $node = node_load(substr($item['link_path'], 5));

      // Paths were set as 'node/$nid'.
      $this
        ->verifyMenuLink($item, $node);
    }

    // Login the user.
    $this
      ->drupalLogin($this->big_user);

    // Delete menu links.
    foreach ($this->items as $item) {
      $this
        ->deleteMenuLink($item);
    }

    // Delete custom menu.
    $this
      ->deleteCustomMenu($this->menu);

    // Modify and reset a standard menu link.
    $item = $this
      ->getStandardMenuLink();
    $old_title = $item['link_title'];
    $this
      ->modifyMenuLink($item);
    $item = menu_link_load($item['mlid']);

    // Verify that a change to the description is saved.
    $description = $this
      ->randomName(16);
    $item['options']['attributes']['title'] = $description;
    menu_link_save($item);
    $saved_item = menu_link_load($item['mlid']);
    $this
      ->assertEqual($description, $saved_item['options']['attributes']['title'], 'Saving an existing link updates the description (title attribute)');
    $this
      ->resetMenuLink($item, $old_title);

    // Test that the page title is correct when a local task appears in a
    // top-level menu item. See https://www.drupal.org/node/1973262.
    $item = $this
      ->addMenuLink(0, 'user/register', 'user-menu');
    $this
      ->drupalGet('user/password');
    $this
      ->assertNoTitle('Home | Drupal');
    $this
      ->drupalLogout();
    $this
      ->drupalGet('user/register');
    $this
      ->assertTitle($item['link_title'] . ' | Drupal');
    $this
      ->drupalGet('user');
    $this
      ->assertNoTitle('Home | Drupal');
  }

  /**
   * Test standard menu functionality using navigation menu.
   *
   */
  function doStandardMenuTests() {
    $this
      ->doMenuTests();
    $this
      ->addInvalidMenuLink();
  }

  /**
   * Test custom menu functionality using navigation menu.
   *
   */
  function doCustomMenuTests() {
    $this->menu = $this
      ->addCustomMenu();
    $this
      ->doMenuTests($this->menu['menu_name']);
    $this
      ->addInvalidMenuLink($this->menu['menu_name']);
    $this
      ->addCustomMenuCRUD();
  }

  /**
   * Add custom menu using CRUD functions.
   */
  function addCustomMenuCRUD() {

    // Add a new custom menu.
    $menu_name = substr(hash('sha256', $this
      ->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
    $title = $this
      ->randomName(16);
    $menu = array(
      'menu_name' => $menu_name,
      'title' => $title,
      'description' => 'Description text',
    );
    menu_save($menu);

    // Assert the new menu.
    $this
      ->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
    $this
      ->assertRaw($title, 'Custom menu was added.');

    // Edit the menu.
    $new_title = $this
      ->randomName(16);
    $menu['title'] = $new_title;
    menu_save($menu);
    $this
      ->drupalGet('admin/structure/menu/manage/' . $menu_name . '/edit');
    $this
      ->assertRaw($new_title, 'Custom menu was edited.');
  }

  /**
   * Add custom menu.
   */
  function addCustomMenu() {

    // Add custom menu.
    // Try adding a menu using a menu_name that is too long.
    $this
      ->drupalGet('admin/structure/menu/add');
    $menu_name = substr(hash('sha256', $this
      ->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1);
    $title = $this
      ->randomName(16);
    $edit = array(
      'menu_name' => $menu_name,
      'description' => '',
      'title' => $title,
    );
    $this
      ->drupalPost('admin/structure/menu/add', $edit, t('Save'));

    // 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,
      '%length' => drupal_strlen($menu_name),
    )));

    // Change the menu_name so it no longer exceeds the maximum length.
    $menu_name = substr(hash('sha256', $this
      ->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
    $edit['menu_name'] = $menu_name;
    $this
      ->drupalPost('admin/structure/menu/add', $edit, t('Save'));

    // Verify that no validation error is given for menu_name length.
    $this
      ->assertNoRaw(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,
      '%length' => drupal_strlen($menu_name),
    )));

    // Unlike most other modules, there is no confirmation message displayed.
    $this
      ->drupalGet('admin/structure/menu');
    $this
      ->assertText($title, 'Menu created');

    // Enable the custom menu block.
    $menu_name = 'menu-' . $menu_name;

    // Drupal prepends the name with 'menu-'.
    $edit = array();
    $edit['blocks[menu_' . $menu_name . '][region]'] = 'sidebar_first';
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
    $this
      ->assertResponse(200);
    $this
      ->assertText(t('The block settings have been updated.'), 'Custom menu block was enabled');
    return menu_load($menu_name);
  }

  /**
   * Delete custom menu.
   *
   * @param string $menu_name Custom menu name.
   */
  function deleteCustomMenu($menu) {
    $menu_name = $this->menu['menu_name'];
    $title = $this->menu['title'];

    // Delete custom menu.
    $this
      ->drupalPost("admin/structure/menu/manage/{$menu_name}/delete", array(), t('Delete'));
    $this
      ->assertResponse(200);
    $this
      ->assertRaw(t('The custom menu %title has been deleted.', array(
      '%title' => $title,
    )), 'Custom menu was deleted');
    $this
      ->assertFalse(menu_load($menu_name), 'Custom menu was deleted');

    // Test if all menu links associated to the menu were removed from database.
    $result = db_query("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu_name", array(
      ':menu_name' => $menu_name,
    ))
      ->fetchField();
    $this
      ->assertFalse($result, 'All menu links associated to the custom menu were deleted.');
  }

  /**
   * Test menu functionality using navigation menu.
   *
   */
  function doMenuTests($menu_name = 'navigation') {

    // Add nodes to use as links for menu links.
    $node1 = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $node2 = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $node3 = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $node4 = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $node5 = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));

    // Add menu links.
    $item1 = $this
      ->addMenuLink(0, 'node/' . $node1->nid, $menu_name);
    $item2 = $this
      ->addMenuLink($item1['mlid'], 'node/' . $node2->nid, $menu_name, FALSE);
    $item3 = $this
      ->addMenuLink($item2['mlid'], 'node/' . $node3->nid, $menu_name);
    $this
      ->assertMenuLink($item1['mlid'], array(
      'depth' => 1,
      'has_children' => 1,
      'p1' => $item1['mlid'],
      'p2' => 0,
    ));
    $this
      ->assertMenuLink($item2['mlid'], array(
      'depth' => 2,
      'has_children' => 1,
      'p1' => $item1['mlid'],
      'p2' => $item2['mlid'],
      'p3' => 0,
    ));
    $this
      ->assertMenuLink($item3['mlid'], array(
      'depth' => 3,
      'has_children' => 0,
      'p1' => $item1['mlid'],
      'p2' => $item2['mlid'],
      'p3' => $item3['mlid'],
      'p4' => 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
    $items = array();
    for ($i = -50; $i <= 51; $i++) {
      $items[$i] = $this
        ->addMenuLink(0, 'node/' . $node1->nid, $menu_name, TRUE, strval($i));
    }
    $this
      ->assertMenuLink($items[51]['mlid'], array(
      'weight' => '51',
    ));

    // Verify menu links.
    $this
      ->verifyMenuLink($item1, $node1);
    $this
      ->verifyMenuLink($item2, $node2, $item1, $node1);
    $this
      ->verifyMenuLink($item3, $node3, $item2, $node2);

    // Add more menu links.
    $item4 = $this
      ->addMenuLink(0, 'node/' . $node4->nid, $menu_name);
    $item5 = $this
      ->addMenuLink($item4['mlid'], 'node/' . $node5->nid, $menu_name);
    $this
      ->assertMenuLink($item4['mlid'], array(
      'depth' => 1,
      'has_children' => 1,
      'p1' => $item4['mlid'],
      'p2' => 0,
    ));
    $this
      ->assertMenuLink($item5['mlid'], array(
      'depth' => 2,
      'has_children' => 0,
      'p1' => $item4['mlid'],
      'p2' => $item5['mlid'],
      'p3' => 0,
    ));

    // Modify menu links.
    $this
      ->modifyMenuLink($item1);
    $this
      ->modifyMenuLink($item2);

    // Toggle menu links.
    $this
      ->toggleMenuLink($item1);
    $this
      ->toggleMenuLink($item2);

    // Move link and verify that descendants are updated.
    $this
      ->moveMenuLink($item2, $item5['mlid'], $menu_name);
    $this
      ->assertMenuLink($item1['mlid'], array(
      'depth' => 1,
      'has_children' => 0,
      'p1' => $item1['mlid'],
      'p2' => 0,
    ));
    $this
      ->assertMenuLink($item4['mlid'], array(
      'depth' => 1,
      'has_children' => 1,
      'p1' => $item4['mlid'],
      'p2' => 0,
    ));
    $this
      ->assertMenuLink($item5['mlid'], array(
      'depth' => 2,
      'has_children' => 1,
      'p1' => $item4['mlid'],
      'p2' => $item5['mlid'],
      'p3' => 0,
    ));
    $this
      ->assertMenuLink($item2['mlid'], array(
      'depth' => 3,
      'has_children' => 1,
      'p1' => $item4['mlid'],
      'p2' => $item5['mlid'],
      'p3' => $item2['mlid'],
      'p4' => 0,
    ));
    $this
      ->assertMenuLink($item3['mlid'], array(
      'depth' => 4,
      'has_children' => 0,
      'p1' => $item4['mlid'],
      'p2' => $item5['mlid'],
      'p3' => $item2['mlid'],
      'p4' => $item3['mlid'],
      'p5' => 0,
    ));

    // Enable a link via the overview form.
    $this
      ->disableMenuLink($item1);
    $edit = array();

    // Note in the UI the 'mlid:x[hidden]' form element maps to enabled, or
    // NOT hidden.
    $edit['mlid:' . $item1['mlid'] . '[hidden]'] = TRUE;
    $this
      ->drupalPost('admin/structure/menu/manage/' . $item1['menu_name'], $edit, t('Save configuration'));

    // Verify in the database.
    $this
      ->assertMenuLink($item1['mlid'], array(
      'hidden' => 0,
    ));

    // Save menu links for later tests.
    $this->items[] = $item1;
    $this->items[] = $item2;
  }

  /**
   * Add and remove a menu link with a query string and fragment.
   */
  function testMenuQueryAndFragment() {
    $this
      ->drupalLogin($this->big_user);

    // Make a path with query and fragment on.
    $path = 'node?arg1=value1&arg2=value2';
    $item = $this
      ->addMenuLink(0, $path);
    $this
      ->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
    $this
      ->assertFieldByName('link_path', $path, 'Path is found with both query and fragment.');

    // Now change the path to something without query and fragment.
    $path = 'node';
    $this
      ->drupalPost('admin/structure/menu/item/' . $item['mlid'] . '/edit', array(
      'link_path' => $path,
    ), t('Save'));
    $this
      ->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
    $this
      ->assertFieldByName('link_path', $path, 'Path no longer has query or fragment.');
  }

  /**
   * Tries to use the navigation menu as the source for secondary links.
   */
  function testNavigationAsSecondaryMenu() {
    $this
      ->drupalLogin($this->big_user);

    // Go to the menu settings page and make the navigation the source for the
    // secondary menu.
    $edit = array(
      'menu_main_links_source' => 'main-menu',
      'menu_secondary_links_source' => 'navigation',
    );
    $this
      ->drupalGet('admin/structure/menu/settings');
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));

    // Now visit the user page. There should be an 'Add content' link in the
    // navigation block and one in the secondary menu.
    $this
      ->drupalGet('user');
    $this
      ->assertNoUniqueText(t('Add content'));
  }

  /**
   * Add 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 link weight
   * @return array Menu link created.
   */
  function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE, $weight = '0') {

    // View add menu link page.
    $this
      ->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
    $this
      ->assertResponse(200);
    $title = '!link_' . $this
      ->randomName(16);
    $edit = array(
      '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.
      'parent' => $menu_name . ':' . $plid,
      'weight' => $weight,
    );

    // Add menu link.
    $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');
    $item = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(
      ':title' => $title,
    ))
      ->fetchAssoc();
    $this
      ->assertTrue(t('Menu link was found in database.'));
    $this
      ->assertMenuLink($item['mlid'], array(
      'menu_name' => $menu_name,
      'link_path' => $link,
      'has_children' => 0,
      'plid' => $plid,
    ));
    return $item;
  }

  /**
   * Attempt to add menu link with invalid path or no access permission.
   *
   * @param string $menu_name Menu name.
   */
  function addInvalidMenuLink($menu_name = 'navigation') {
    foreach (array(
      '-&-',
      'admin/people/permissions',
      '#',
    ) as $link_path) {
      $edit = array(
        'link_path' => $link_path,
        'link_title' => 'title',
      );
      $this
        ->drupalPost("admin/structure/menu/manage/{$menu_name}/add", $edit, t('Save'));
      $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');
    }
  }

  /**
   * Verify 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.
   */
  function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) {

    // View home page.
    $this
      ->drupalGet('');
    $this
      ->assertResponse(200);

    // Verify parent menu link.
    if (isset($parent)) {

      // Verify menu link.
      $title = $parent['link_title'];
      $this
        ->assertLink($title, 0, 'Parent menu link was displayed');

      // Verify menu link link.
      $this
        ->clickLink($title);
      $title = $parent_node->title;
      $this
        ->assertTitle(t("@title | Drupal", array(
        '@title' => $title,
      )), 'Parent menu link link target was correct');
    }

    // Verify menu link.
    $title = $item['link_title'];
    $this
      ->assertLink($title, 0, 'Menu link was displayed');

    // Verify menu link link.
    $this
      ->clickLink($title);
    $title = $item_node->title;
    $this
      ->assertTitle(t("@title | Drupal", array(
      '@title' => $title,
    )), 'Menu link link target was correct');
  }

  /**
   * Change the parent of a menu link using the menu module UI.
   */
  function moveMenuLink($item, $plid, $menu_name) {
    $mlid = $item['mlid'];
    $edit = array(
      'parent' => $menu_name . ':' . $plid,
    );
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
    $this
      ->assertResponse(200);
  }

  /**
   * Modify a menu link using the menu module UI.
   *
   * @param array $item Menu link passed by reference.
   */
  function modifyMenuLink(&$item) {
    $item['link_title'] = $this
      ->randomName(16);
    $mlid = $item['mlid'];
    $title = $item['link_title'];

    // Edit menu link.
    $edit = array();
    $edit['link_title'] = $title;
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
    $this
      ->assertResponse(200);

    // Unlike most other modules, there is no confirmation message displayed.
    // Verify menu link.
    $this
      ->drupalGet('admin/structure/menu/manage/' . $item['menu_name']);
    $this
      ->assertText($title, 'Menu link was edited');
  }

  /**
   * Reset a standard menu link using the menu module UI.
   *
   * @param array $item Menu link.
   * @param string $old_title Original title for menu link.
   */
  function resetMenuLink($item, $old_title) {
    $mlid = $item['mlid'];
    $title = $item['link_title'];

    // Reset menu link.
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/reset", array(), t('Reset'));
    $this
      ->assertResponse(200);
    $this
      ->assertRaw(t('The menu link was reset to its default settings.'), 'Menu link was reset');

    // Verify menu link.
    $this
      ->drupalGet('');
    $this
      ->assertNoText($title, 'Menu link was reset');
    $this
      ->assertText($old_title, 'Menu link was reset');
  }

  /**
   * Delete a menu link using the menu module UI.
   *
   * @param array $item Menu link.
   */
  function deleteMenuLink($item) {
    $mlid = $item['mlid'];
    $title = $item['link_title'];

    // Delete menu link.
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/delete", array(), t('Confirm'));
    $this
      ->assertResponse(200);
    $this
      ->assertRaw(t('The menu link %title has been deleted.', array(
      '%title' => $title,
    )), 'Menu link was deleted');

    // Verify deletion.
    $this
      ->drupalGet('');
    $this
      ->assertNoText($title, 'Menu link was deleted');
  }

  /**
   * Alternately disable and enable a menu link.
   *
   * @param $item
   *   Menu link.
   */
  function toggleMenuLink($item) {
    $this
      ->disableMenuLink($item);

    // Verify menu link is absent.
    $this
      ->drupalGet('');
    $this
      ->assertNoText($item['link_title'], 'Menu link was not displayed');
    $this
      ->enableMenuLink($item);

    // Verify menu link is displayed.
    $this
      ->drupalGet('');
    $this
      ->assertText($item['link_title'], 'Menu link was displayed');
  }

  /**
   * Disable a menu link.
   *
   * @param $item
   *   Menu link.
   */
  function disableMenuLink($item) {
    $mlid = $item['mlid'];
    $edit['enabled'] = FALSE;
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));

    // Unlike most other modules, there is no confirmation message displayed.
    // Verify in the database.
    $this
      ->assertMenuLink($mlid, array(
      'hidden' => 1,
    ));
  }

  /**
   * Enable a menu link.
   *
   * @param $item
   *   Menu link.
   */
  function enableMenuLink($item) {
    $mlid = $item['mlid'];
    $edit['enabled'] = TRUE;
    $this
      ->drupalPost("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));

    // Verify in the database.
    $this
      ->assertMenuLink($mlid, array(
      'hidden' => 0,
    ));
  }

  /**
   * Fetch the menu item from the database and compare it to the specified
   * array.
   *
   * @param $mlid
   *   Menu item id.
   * @param $item
   *   Array containing properties to verify.
   */
  function assertMenuLink($mlid, array $expected_item) {

    // Retrieve menu link.
    $item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array(
      ':mlid' => $mlid,
    ))
      ->fetchAssoc();
    $options = unserialize($item['options']);
    if (!empty($options['query'])) {
      $item['link_path'] .= '?' . drupal_http_build_query($options['query']);
    }
    if (!empty($options['fragment'])) {
      $item['link_path'] .= '#' . $options['fragment'];
    }
    foreach ($expected_item as $key => $value) {
      $this
        ->assertEqual($item[$key], $value, format_string('Parameter %key had expected value.', array(
        '%key' => $key,
      )));
    }
  }

  /**
   * Test administrative users other than user 1 can access the menu parents AJAX callback.
   */
  public function testMenuParentsJsAccess() {
    $admin = $this
      ->drupalCreateUser(array(
      'administer menu',
    ));
    $this
      ->drupalLogin($admin);

    // Just check access to the callback overall, the POST data is irrelevant.
    $this
      ->drupalGetAJAX('admin/structure/menu/parents');
    $this
      ->assertResponse(200);

    // Do standard user tests.
    // Login the user.
    $this
      ->drupalLogin($this->std_user);
    $this
      ->drupalGetAJAX('admin/structure/menu/parents');
    $this
      ->assertResponse(403);
  }

  /**
   * Get standard menu link.
   */
  private function getStandardMenuLink() {

    // Retrieve menu link id of the Log out menu link, which will always be on the front page.
    $mlid = db_query("SELECT mlid FROM {menu_links} WHERE module = 'system' AND router_path = 'user/logout'")
      ->fetchField();
    $this
      ->assertTrue($mlid > 0, 'Standard menu link id was found');

    // Load menu link.
    // Use api function so that link is translated for rendering.
    $item = menu_link_load($mlid);
    $this
      ->assertTrue((bool) $item, 'Standard menu link was loaded');
    return $item;
  }

  /**
   * Verify the logged in user has the desired access to the various menu nodes.
   *
   * @param integer $response HTTP response code.
   */
  private function verifyAccess($response = 200) {

    // View menu help node.
    $this
      ->drupalGet('admin/help/menu');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Menu'), 'Menu help was displayed');
    }

    // View menu build overview node.
    $this
      ->drupalGet('admin/structure/menu');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Menus'), 'Menu build overview node was displayed');
    }

    // View navigation menu customization node.
    $this
      ->drupalGet('admin/structure/menu/manage/navigation');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Navigation'), 'Navigation menu node was displayed');
    }

    // View menu edit node.
    $item = $this
      ->getStandardMenuLink();
    $this
      ->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Edit menu item'), 'Menu edit node was displayed');
    }

    // View menu settings node.
    $this
      ->drupalGet('admin/structure/menu/settings');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Menus'), 'Menu settings node was displayed');
    }

    // View add menu node.
    $this
      ->drupalGet('admin/structure/menu/add');
    $this
      ->assertResponse($response);
    if ($response == 200) {
      $this
        ->assertText(t('Menus'), 'Add menu node was displayed');
    }
  }

  /**
   * Tests that menu admin lists can include menu items for unpublished nodes.
   */
  function testUnpublishedNodeMenuItem() {

    // Log in as an administrator who can view unpublished nodes.
    $menu_and_node_admin_user = $this
      ->drupalCreateUser(array(
      'bypass node access',
      'administer menu',
    ));
    $this
      ->drupalLogin($menu_and_node_admin_user);

    // Create an unpublished node with a menu link.
    $title = $this
      ->randomName();
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'article',
      'title' => $title,
      'status' => NODE_NOT_PUBLISHED,
    ));
    $edit = array(
      'link_path' => 'node/' . $node->nid,
      'link_title' => $title,
      'description' => '',
      'enabled' => TRUE,
      'expanded' => TRUE,
      'parent' => 'navigation:0',
      'weight' => '0',
    );
    $this
      ->drupalPost('admin/structure/menu/manage/navigation/add', $edit, t('Save'));

    // Verify that the administrator can see the menu link (with a label
    // indicating that it is unpublished) on the menu management page.
    $this
      ->drupalGet('admin/structure/menu/manage/navigation');
    $this
      ->assertText($title . ' (unpublished)', 'Menu link to unpublished node is visible to users with "bypass node access" permission.');

    // Verify that a user who cannot view unpublished nodes does not see the
    // menu link on the menu management page.
    $menu_admin_user = $this
      ->drupalCreateUser(array(
      'administer menu',
    ));
    $this
      ->drupalLogin($menu_admin_user);
    $this
      ->drupalGet('admin/structure/menu/manage/navigation');
    $this
      ->assertResponse(200);
    $this
      ->assertNoText($title, 'Menu link to unpublished node is not visible to users without the "bypass node access" permission.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
MenuTestCase::$big_user protected property
MenuTestCase::$items protected property
MenuTestCase::$menu protected property
MenuTestCase::$std_user protected property
MenuTestCase::addCustomMenu function Add custom menu.
MenuTestCase::addCustomMenuCRUD function Add custom menu using CRUD functions.
MenuTestCase::addInvalidMenuLink function Attempt to add menu link with invalid path or no access permission.
MenuTestCase::addMenuLink function Add a menu link using the menu module UI.
MenuTestCase::assertMenuLink function Fetch the menu item from the database and compare it to the specified array.
MenuTestCase::deleteCustomMenu function Delete custom menu.
MenuTestCase::deleteMenuLink function Delete a menu link using the menu module UI.
MenuTestCase::disableMenuLink function Disable a menu link.
MenuTestCase::doCustomMenuTests function Test custom menu functionality using navigation menu.
MenuTestCase::doMenuTests function Test menu functionality using navigation menu.
MenuTestCase::doStandardMenuTests function Test standard menu functionality using navigation menu.
MenuTestCase::enableMenuLink function Enable a menu link.
MenuTestCase::getInfo public static function
MenuTestCase::getStandardMenuLink private function Get standard menu link.
MenuTestCase::modifyMenuLink function Modify a menu link using the menu module UI.
MenuTestCase::moveMenuLink function Change the parent of a menu link using the menu module UI.
MenuTestCase::resetMenuLink function Reset a standard menu link using the menu module UI.
MenuTestCase::setUp function Sets up a Drupal site for running functional and integration tests. Overrides DrupalWebTestCase::setUp
MenuTestCase::testMenu function Login users, add menus and menu links, and test menu functionality through the admin and user interfaces.
MenuTestCase::testMenuParentsJsAccess public function Test administrative users other than user 1 can access the menu parents AJAX callback.
MenuTestCase::testMenuQueryAndFragment function Add and remove a menu link with a query string and fragment.
MenuTestCase::testNavigationAsSecondaryMenu function Tries to use the navigation menu as the source for secondary links.
MenuTestCase::testUnpublishedNodeMenuItem function Tests that menu admin lists can include menu items for unpublished nodes.
MenuTestCase::toggleMenuLink function Alternately disable and enable a menu link.
MenuTestCase::verifyAccess private function Verify the logged in user has the desired access to the various menu nodes.
MenuTestCase::verifyMenuLink function Verify a menu link using the menu module UI.