function MenuUiNodeAccessTest::testMenuLinkEditAccess

Tests menu link edit/delete access is enforced.

File

core/modules/menu_ui/tests/src/Functional/MenuUiNodeAccessTest.php, line 65

Class

MenuUiNodeAccessTest
Edit a node when you don't have permission to add or edit menu links.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testMenuLinkEditAccess() : void {
    $this->drupalLogin($this->drupalCreateUser([
        'administer menu',
        'edit any page content',
    ]));
    $mainLinkTitle = $this->randomMachineName();
    $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' => $mainLinkTitle,
        'menu_name' => 'main',
    ])
        ->save();
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()
        ->elementNotExists('css', 'input[name="menu[title]"]');
}

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