function MenuUiTest::testUnpublishedNodeMenuItem

Same name in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testUnpublishedNodeMenuItem()
  2. 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testUnpublishedNodeMenuItem()
  3. 11.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testUnpublishedNodeMenuItem()

Tests that menu items pointing to unpublished nodes are editable.

File

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

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testUnpublishedNodeMenuItem() : void {
    $this->drupalLogin($this->drupalCreateUser([
        'access administration pages',
        'administer blocks',
        'administer menu',
        'create article content',
        'bypass node access',
    ]));
    // Create an unpublished node.
    $node = $this->drupalCreateNode([
        'type' => 'article',
        'status' => NodeInterface::NOT_PUBLISHED,
    ]);
    $item = $this->addMenuLink('', '/node/' . $node->id());
    $this->modifyMenuLink($item);
    // Test that a user with 'administer menu' but without 'bypass node access'
    // cannot see the menu item.
    $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/structure/menu/manage/' . $item->getMenuName());
    $this->assertSession()
        ->linkExists($item->getTitle());
    // The cache contexts associated with the (in)accessible menu links are
    // bubbled. See DefaultMenuLinkTreeManipulators::menuLinkCheckAccess().
    $this->assertSession()
        ->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
    // The menu link admin is able to administer the link but cannot access the
    // route as is not granted with 'bypass node access' permission.
    $this->clickLink($item->getTitle());
    $this->assertSession()
        ->statusCodeEquals(403);
}

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