You are here

function MenuTest::testUnpublishedNodeMenuItem in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest::testUnpublishedNodeMenuItem()

Tests that menu items pointing to unpublished nodes are editable.

File

core/modules/menu_ui/src/Tests/MenuTest.php, line 545
Contains \Drupal\menu_ui\Tests\MenuTest.

Class

MenuTest
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\menu_ui\Tests

Code

function testUnpublishedNodeMenuItem() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer blocks',
    'administer menu',
    'create article content',
    'bypass node access',
  )));

  // Create an unpublished node.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'status' => NODE_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
    ->assertCacheContext('user.permissions');
}