function MenuUiContentModerationTest::testMenuUiWithUnpublishedContent

Same name and namespace in other branches
  1. 10 core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php \Drupal\Tests\menu_ui\Functional\MenuUiContentModerationTest::testMenuUiWithUnpublishedContent()

Tests that unpublished content can be selected through the menu UI.

File

core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php, line 197

Class

MenuUiContentModerationTest
Tests Menu UI and Content Moderation integration.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testMenuUiWithUnpublishedContent() : void {
    $editor_with_unpublished_content_access = $this->drupalCreateUser([
        'administer nodes',
        'administer menu',
        'create page content',
        'use editorial transition create_new_draft',
        'view any unpublished content',
    ]);
    $this->drupalLogin($editor_with_unpublished_content_access);
    // Create a node.
    $node_title = $this->randomMachineName();
    $edit = [
        'title[0][value]' => $node_title,
        'menu[enabled]' => 1,
        'menu[title]' => $node_title,
        'moderation_state[0][state]' => 'draft',
    ];
    $this->drupalGet('node/add/page');
    $this->submitForm($edit, 'Save');
    // Assert that the unpublished node can be selected as a parent menu link
    // for users with access to the node.
    $node = $this->drupalGetNodeByTitle($node_title);
    $this->assertTrue($node->access('view', $editor_with_unpublished_content_access));
    $this->assertEquals($edit['title[0][value]'], $node->getTitle());
    $this->drupalGet('node/add/page');
    $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
    
    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $link */
    $link = MenuLinkContent::load($link_id);
    $this->assertSession()
        ->optionExists('edit-menu-menu-parent', 'main:' . $link->getPluginId());
    // Assert that the unpublished node cannot be selected as a parent menu link
    // for users without access to the node.
    $editor_without_unpublished_content_access = $this->drupalCreateUser([
        'administer nodes',
        'administer menu',
        'create page content',
        'use editorial transition create_new_draft',
    ]);
    $this->drupalLogin($editor_without_unpublished_content_access);
    $this->assertFalse($node->access('view', $editor_without_unpublished_content_access));
    $this->drupalGet('node/add/page');
    $this->assertSession()
        ->optionNotExists('edit-menu-menu-parent', 'main:' . $link->getPluginId());
}

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