function MenuLinkTreeTest::testDeleteLinksInMenu

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php \Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testDeleteLinksInMenu()
  2. 10 core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php \Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testDeleteLinksInMenu()
  3. 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\Menu

Code

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.