public function MenuLinkTreeTest::testDeleteLinksInMenu in Drupal 8
Same name and namespace in other branches
- 9 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 63
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);
}