1 menu.test MenuTestCase::addCustomMenu()

Add custom menu.

File

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

Class

MenuTestCase

Code

function addCustomMenu() {
  // Add custom menu.

  // Try adding a menu using a menu_name that is too long.
  $this->backdropGet('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->backdropPost('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' => backdrop_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->backdropPost('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' => backdrop_strlen($menu_name),
  )));
  // Unlike most other modules, there is no confirmation message displayed.

  $this->backdropGet('admin/structure/menu');
  $this->assertText($title, 'Menu created');

  // Enable the custom menu block.
  $menu_name = 'menu-' . $menu_name;
  $layout = layout_load('default');
  $layout->addBlock('menu', $menu_name, 'sidebar');
  $layout->save();

  backdrop_static_reset();
  return menu_load($menu_name);
}