You are here

public function MenuUiTest::testExpandAllItems in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testExpandAllItems()

Tests the "expand all items" feature.

File

core/modules/menu_ui/tests/src/Functional/MenuUiTest.php, line 920

Class

MenuUiTest
Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testExpandAllItems() {
  $this
    ->drupalLogin($this->adminUser);
  $menu = $this
    ->addCustomMenu();
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);

  // Create three menu items, none of which are expanded.
  $parent = $this
    ->addMenuLink('', $node
    ->toUrl()
    ->toString(), $menu
    ->id(), FALSE);
  $child_1 = $this
    ->addMenuLink($parent
    ->getPluginId(), $node
    ->toUrl()
    ->toString(), $menu
    ->id(), FALSE);
  $child_2 = $this
    ->addMenuLink($parent
    ->getPluginId(), $node
    ->toUrl()
    ->toString(), $menu
    ->id(), FALSE);

  // The menu will not automatically show all levels of depth.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->linkExists($parent
    ->getTitle());
  $this
    ->assertSession()
    ->linkNotExists($child_1
    ->getTitle());
  $this
    ->assertSession()
    ->linkNotExists($child_2
    ->getTitle());

  // Update the menu block to show all levels of depth as expanded.
  $block_id = $this->blockPlacements[$menu
    ->id()];
  $this
    ->drupalGet('admin/structure/block/manage/' . $block_id);
  $this
    ->assertSession()
    ->checkboxNotChecked('settings[expand_all_items]');
  $this
    ->submitForm([
    'settings[depth]' => 2,
    'settings[level]' => 1,
    'settings[expand_all_items]' => 1,
  ], 'Save block');

  // Ensure the setting is persisted.
  $this
    ->drupalGet('admin/structure/block/manage/' . $block_id);
  $this
    ->assertSession()
    ->checkboxChecked('settings[expand_all_items]');

  // Ensure all three links are shown, including the children which would
  // usually be hidden without the "expand all items" setting.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->linkExists($parent
    ->getTitle());
  $this
    ->assertSession()
    ->linkExists($child_1
    ->getTitle());
  $this
    ->assertSession()
    ->linkExists($child_2
    ->getTitle());
}