function MenuTest::addCustomMenu

Add custom menu.

2 calls to MenuTest::addCustomMenu()
MenuTest::testMenu in drupal/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
Login users, add menus and menu links, and test menu functionality through the admin and user interfaces.
MenuTest::testMenuBundles in drupal/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
Tests menu link bundles.

File

drupal/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php, line 124
Definition of Drupal\menu\Tests\MenuTest.

Class

MenuTest

Namespace

Drupal\menu\Tests

Code

function addCustomMenu() {

  // 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);
  $label = $this
    ->randomName(16);
  $edit = array(
    'id' => $menu_name,
    'description' => '',
    'label' => $label,
  );
  $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['id'] = $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),
  )));

  // Verify that confirmation message displayed.
  $this
    ->assertRaw(t('Menu %label has been added.', array(
    '%label' => $label,
  )));
  $this
    ->drupalGet('admin/structure/menu');
  $this
    ->assertText($label, 'Menu created');

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

  // Drupal prepends the name with 'menu-'.
  // Confirm that the custom menu block is available.
  $this
    ->drupalGet('admin/structure/block/list/block_plugin_ui:' . config('system.theme')
    ->get('default') . '/add');
  $this
    ->assertText($label);

  // Enable the block.
  $this
    ->drupalPlaceBlock('menu_menu_block:' . $menu_name);
  return menu_load($menu_name);
}