public function MenuTest::testMenuBundles

Tests menu link bundles.

File

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

Class

MenuTest

Namespace

Drupal\menu\Tests

Code

public function testMenuBundles() {
  $this
    ->drupalLogin($this->big_user);
  $menu = $this
    ->addCustomMenu();
  $bundles = entity_get_bundles('menu_link');
  $this
    ->assertTrue($bundles[$menu
    ->id()]);
  $menus = menu_list_system_menus();
  $menus[$menu
    ->id()] = $menu
    ->label();
  ksort($menus);
  $this
    ->assertIdentical(array_keys($bundles), array_keys($menus));

  // Test if moving a menu link between menus changes the bundle.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));
  $item = $this
    ->addMenuLink(0, 'node/' . $node->nid, 'tools');
  $this
    ->moveMenuLink($item, 0, $menu
    ->id());
  $this
    ->assertEqual($item
    ->bundle(), 'tools', 'Menu link bundle matches the menu');
  $moved_item = entity_load('menu_link', $item
    ->id(), TRUE);
  $this
    ->assertNotEqual($moved_item
    ->bundle(), $item
    ->bundle(), 'Menu link bundle was changed');
  $this
    ->assertEqual($moved_item
    ->bundle(), $menu
    ->id(), 'Menu link bundle matches the menu');
  $unsaved_item = entity_create('menu_link', array(
    'menu_name' => $menu
      ->id(),
    'link_title' => $this
      ->randomName(16),
    'link_path' => '<front>',
  ));
  $this
    ->assertEqual($unsaved_item
    ->bundle(), $menu
    ->id(), 'Unsaved menu link bundle matches the menu');
  $this
    ->assertEqual($unsaved_item->menu_name, $menu
    ->id(), 'Unsaved menu link menu name matches the menu');
}