You are here

public function MenuLinkDefaultIntegrationTest::testMoveToRoot in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php \Drupal\system\Tests\Menu\MenuLinkDefaultIntegrationTest::testMoveToRoot()

Tests moving a static menu link without a specified menu to the root.

File

core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php, line 41
Contains \Drupal\system\Tests\Menu\MenuLinkDefaultIntegrationTest.

Class

MenuLinkDefaultIntegrationTest
Tests integration of static menu links.

Namespace

Drupal\system\Tests\Menu

Code

public function testMoveToRoot() {

  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  $menu_link_manager
    ->rebuild();
  $menu_link = $menu_link_manager
    ->getDefinition('menu_test.child');
  $this
    ->assertEqual($menu_link['parent'], 'menu_test.parent');
  $this
    ->assertEqual($menu_link['menu_name'], 'test');
  $tree = \Drupal::menuTree()
    ->load('test', new MenuTreeParameters());
  $this
    ->assertEqual(count($tree), 1);
  $this
    ->assertEqual($tree['menu_test.parent']->link
    ->getPluginId(), 'menu_test.parent');
  $this
    ->assertEqual($tree['menu_test.parent']->subtree['menu_test.child']->link
    ->getPluginId(), 'menu_test.child');

  // Ensure that the menu name is not forgotten.
  $menu_link_manager
    ->updateDefinition('menu_test.child', array(
    'parent' => '',
  ));
  $menu_link = $menu_link_manager
    ->getDefinition('menu_test.child');
  $this
    ->assertEqual($menu_link['parent'], '');
  $this
    ->assertEqual($menu_link['menu_name'], 'test');
  $tree = \Drupal::menuTree()
    ->load('test', new MenuTreeParameters());
  $this
    ->assertEqual(count($tree), 2);
  $this
    ->assertEqual($tree['menu_test.parent']->link
    ->getPluginId(), 'menu_test.parent');
  $this
    ->assertEqual($tree['menu_test.child']->link
    ->getPluginId(), 'menu_test.child');
  $this
    ->assertTrue(TRUE);
}