function MenuTest::addCustomMenuCRUD

Add custom menu using CRUD functions.

1 call to MenuTest::addCustomMenuCRUD()
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.

File

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

Class

MenuTest

Namespace

Drupal\menu\Tests

Code

function addCustomMenuCRUD() {

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

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

  // Edit the menu.
  $new_label = $this
    ->randomName(16);
  $menu
    ->set('label', $new_label);
  $menu
    ->save();
  $this
    ->drupalGet('admin/structure/menu/manage/' . $menu_name);
  $this
    ->assertRaw($new_label, 'Custom menu was edited.');
}