MenuLinkDefaultIntegrationTest.php in Drupal 9
File
core/tests/Drupal/KernelTests/Core/Menu/MenuLinkDefaultIntegrationTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Menu;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\KernelTests\KernelTestBase;
class MenuLinkDefaultIntegrationTest extends KernelTestBase {
protected static $modules = [
'menu_test',
];
public function testMoveToRoot() {
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$menu_link_manager
->rebuild();
$menu_link = $menu_link_manager
->getDefinition('menu_test.child');
$this
->assertEquals('menu_test.parent', $menu_link['parent']);
$this
->assertEquals('test', $menu_link['menu_name']);
$tree = \Drupal::menuTree()
->load('test', new MenuTreeParameters());
$this
->assertCount(1, $tree);
$this
->assertEquals('menu_test.parent', $tree['menu_test.parent']->link
->getPluginId());
$this
->assertEquals('menu_test.child', $tree['menu_test.parent']->subtree['menu_test.child']->link
->getPluginId());
$menu_link_manager
->updateDefinition('menu_test.child', [
'parent' => '',
]);
$menu_link = $menu_link_manager
->getDefinition('menu_test.child');
$this
->assertEquals('', $menu_link['parent']);
$this
->assertEquals('test', $menu_link['menu_name']);
$tree = \Drupal::menuTree()
->load('test', new MenuTreeParameters());
$this
->assertCount(2, $tree);
$this
->assertEquals('menu_test.parent', $tree['menu_test.parent']->link
->getPluginId());
$this
->assertEquals('menu_test.child', $tree['menu_test.child']->link
->getPluginId());
$this
->assertTrue(TRUE);
}
}