function MenuUiTest::testExpandAllItems

Same name in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testExpandAllItems()
  2. 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testExpandAllItems()
  3. 11.x 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 1073

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testExpandAllItems() : void {
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.