function MenuUiNodeTest::testMainMenuIsPrioritized

Same name in other branches
  1. 11.x core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php \Drupal\Tests\menu_ui\Functional\MenuUiNodeTest::testMainMenuIsPrioritized()

Tests main menu links are prioritized when editing nodes.

See also

menu_ui_get_menu_link_defaults()

File

core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php, line 431

Class

MenuUiNodeTest
Add, edit, and delete a node with menu link.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testMainMenuIsPrioritized() : void {
    $this->drupalLogin($this->drupalCreateUser([
        'administer menu',
        'edit any page content',
    ]));
    $menu_name = $this->randomMachineName();
    $mainLinkTitle = $this->randomMachineName();
    $nonMainLinkTitle = $this->randomMachineName();
    Menu::create([
        'id' => $menu_name,
        'label' => $menu_name,
    ])->save();
    $nodeType = NodeType::load('page');
    $nodeType->setThirdPartySetting('menu_ui', 'available_menus', [
        $menu_name,
        'main',
    ])
        ->save();
    $node = Node::create([
        'type' => 'page',
        'title' => $this->randomMachineName(),
        'uid' => $this->rootUser
            ->id(),
        'status' => 1,
    ]);
    $node->save();
    MenuLinkContent::create([
        'link' => [
            [
                'uri' => 'entity:node/' . $node->id(),
            ],
        ],
        'title' => $nonMainLinkTitle,
        'menu_name' => $menu_name,
    ])
        ->save();
    MenuLinkContent::create([
        'link' => [
            [
                'uri' => 'entity:node/' . $node->id(),
            ],
        ],
        'title' => $mainLinkTitle,
        'menu_name' => 'main',
    ])
        ->save();
    $this->drupalGet('node/' . $node->id() . '/edit');
    $element = $this->assertSession()
        ->elementExists('css', 'input[name="menu[title]"]');
    $this->assertEquals($mainLinkTitle, $element->getValue());
}

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