function MenuLinkTreeTest::testDeleteLinksInMenu
Same name in other branches
- 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()
- 11.x 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 62
Class
- MenuLinkTreeTest
- Tests the menu link tree.
Namespace
Drupal\KernelTests\Core\MenuCode
public function testDeleteLinksInMenu() {
\Drupal::entityTypeManager()->getStorage('menu')
->create([
'id' => 'menu1',
])
->save();
\Drupal::entityTypeManager()->getStorage('menu')
->create([
'id' => 'menu2',
])
->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.