class MenuLinkDefaultIntegrationTest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Menu/MenuLinkDefaultIntegrationTest.php \Drupal\KernelTests\Core\Menu\MenuLinkDefaultIntegrationTest
- 9 core/tests/Drupal/KernelTests/Core/Menu/MenuLinkDefaultIntegrationTest.php \Drupal\KernelTests\Core\Menu\MenuLinkDefaultIntegrationTest
Tests integration of static menu links.
@group Menu
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Menu\MenuLinkDefaultIntegrationTest
Expanded class hierarchy of MenuLinkDefaultIntegrationTest
File
- core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuLinkDefaultIntegrationTest.php, line 13
Namespace
Drupal\KernelTests\Core\MenuView source
class MenuLinkDefaultIntegrationTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'menu_test',
];
/**
* Tests moving a static menu link without a specified menu to the root.
*/
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
->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());
// Ensure that the menu name is not forgotten.
$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);
}
}