function MenuLinkTest::testHierarchicalMenuLinkVisibility

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php \Drupal\Tests\views\Functional\Plugin\MenuLinkTest::testHierarchicalMenuLinkVisibility()
  2. 10 core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php \Drupal\Tests\views\Functional\Plugin\MenuLinkTest::testHierarchicalMenuLinkVisibility()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php \Drupal\Tests\views\Functional\Plugin\MenuLinkTest::testHierarchicalMenuLinkVisibility()

Test that menu links using menu_link_content as parent are visible.

File

core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php, line 67

Class

MenuLinkTest
Tests the menu links created in views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testHierarchicalMenuLinkVisibility() {
    $this->drupalLogin($this->adminUser);
    $node = $this->drupalCreateNode([
        'type' => 'page',
    ]);
    // Create a primary level menu link to the node.
    $link = MenuLinkContent::create([
        'title' => 'Primary level node',
        'menu_name' => 'main',
        'bundle' => 'menu_link_content',
        'parent' => '',
        'link' => [
            [
                'uri' => 'entity:node/' . $node->id(),
            ],
        ],
    ]);
    $link->save();
    $parent_menu_value = 'main:menu_link_content:' . $link->uuid();
    // Alter the view's menu link in view page to use the menu link from the
    // node as parent.
    $this->drupalPostForm("admin/structure/views/nojs/display/test_menu_link/page_1/menu", [
        'menu[type]' => 'normal',
        'menu[title]' => 'Secondary level view page',
        'menu[parent]' => $parent_menu_value,
    ], 'Apply');
    // Save view which has pending changes.
    $this->drupalPostForm(NULL, [], 'Save');
    // Test if the node as parent menu item is selected in our views settings.
    $this->drupalGet('admin/structure/views/nojs/display/test_menu_link/page_1/menu');
    $this->assertOptionSelected('edit-menu-parent', $parent_menu_value);
    $this->drupalGet('');
    // Test if the primary menu item (node) is visible, and the secondary menu
    // item (view) is hidden.
    $this->assertText('Primary level node');
    $this->assertNoText('Secondary level view page');
    // Go to the node page and ensure that both the first and second level items
    // are visible.
    $this->drupalGet($node->toUrl());
    $this->assertText('Primary level node');
    $this->assertText('Secondary level view page');
}

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