function MenuLinkTreeTest::testDeleteLinksInMenu
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php \Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testDeleteLinksInMenu()
- 8.9.x core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php \Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testDeleteLinksInMenu()
- 10 core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php \Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testDeleteLinksInMenu()
Tests deleting all the links in a menu.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuLinkTreeTest.php, line 65
Class
- MenuLinkTreeTest
- Tests the menu link tree.
Namespace
Drupal\KernelTests\Core\MenuCode
public function testDeleteLinksInMenu() : void {
/** @var \Drupal\system\MenuStorage $storage */
$storage = \Drupal::entityTypeManager()->getStorage('menu');
$storage->create([
'id' => 'menu1',
'label' => 'Menu 1',
])
->save();
$storage->create([
'id' => 'menu2',
'label' => 'Menu 2',
])
->save();
\Drupal::entityTypeManager()->getStorage('menu_link_content')
->create([
'link' => [
'uri' => 'internal:/menu_name_test',
],
'menu_name' => 'menu1',
'bundle' => 'menu_link_content',
'title' => 'Link test',
])
->save();
\Drupal::entityTypeManager()->getStorage('menu_link_content')
->create([
'link' => [
'uri' => 'internal:/menu_name_test',
],
'menu_name' => 'menu1',
'bundle' => 'menu_link_content',
'title' => 'Link test',
])
->save();
\Drupal::entityTypeManager()->getStorage('menu_link_content')
->create([
'link' => [
'uri' => 'internal:/menu_name_test',
],
'menu_name' => 'menu2',
'bundle' => 'menu_link_content',
'title' => 'Link test',
])
->save();
$output = $this->linkTree
->load('menu1', new MenuTreeParameters());
$this->assertCount(2, $output);
$output = $this->linkTree
->load('menu2', new MenuTreeParameters());
$this->assertCount(1, $output);
$this->menuLinkManager
->deleteLinksInMenu('menu1');
$output = $this->linkTree
->load('menu1', new MenuTreeParameters());
$this->assertCount(0, $output);
$output = $this->linkTree
->load('menu2', new MenuTreeParameters());
$this->assertCount(1, $output);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.