You are here

public function MenuUiTest::testUnpublishedNodeMenuItem in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testUnpublishedNodeMenuItem()
  2. 10 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 564

Class

MenuUiTest
Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testUnpublishedNodeMenuItem() {
  $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
    ->assertNoText($item
    ->getTitle(), "Menu link pointing to unpublished node is only visible to users with 'bypass node access' permission");

  // The cache contexts associated with the (in)accessible menu links are
  // bubbled. See DefaultMenuLinkTreeManipulators::menuLinkCheckAccess().
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
}