1 menu.test MenuTestCase::addMenuLink($plid = 0, $link = '', $menu_name = 'main-menu', $expanded = TRUE, $weight = 0)

Add a menu link using the menu module UI.

Parameters

integer $plid: Parent menu link ID.

string $link: Link path.

string $menu_name: Menu name.

int $weight: Menu link weight

Return value

array: Menu link created.

File

core/modules/menu/tests/menu.test, line 340
Tests for menu.module.

Class

MenuTestCase

Code

function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'main-menu', $expanded = TRUE, $weight = 0) {
  // View add menu link page.
  $this->backdropGet("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->backdropPost(NULL, $edit, t('Save'));
  $this->assertResponse(200);
  // Unlike most other modules, there is no confirmation message displayed.
  $this->assertText($title, 'Menu link was added');

  // Resolve aliases if used.
  $source = backdrop_lookup_path('source', $link);
  if (empty($source)) {
    $source = $link;
  }

  $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' => $source, 'has_children' => 0, 'plid' => $plid));

  return $item;
}