View source
<?php
namespace Drupal\Tests\menu_ui\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class MenuUiContentModerationTest extends BrowserTestBase {
use ContentModerationTestTrait;
protected static $modules = [
'block',
'content_moderation',
'node',
'menu_ui',
'test_page_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:main');
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'page');
$workflow
->save();
}
public function testMenuUiWithPendingRevisions() {
$editor = $this
->drupalCreateUser([
'administer nodes',
'administer menu',
'create page content',
'edit any page content',
'use editorial transition create_new_draft',
'use editorial transition publish',
'view latest version',
'view any unpublished content',
]);
$this
->drupalLogin($editor);
$node = $this
->drupalCreateNode();
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$edit = [
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$edit = [
'menu[enabled]' => 1,
'menu[title]' => 'Test menu link',
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->linkExists('Test menu link');
$edit = [
'menu[weight]' => 1,
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only change the menu link weight for the published version of this content.');
$edit = [
'menu[menu_parent]' => 'main:test_page_test.front_page',
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only change the parent menu link for the published version of this content.');
$edit = [
'menu[enabled]' => 0,
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only remove the menu link in the published version of this content.');
$this
->assertSession()
->linkExists('Test menu link');
$edit = [
'menu[title]' => 'Test menu link draft',
'menu[description]' => 'Test menu link description',
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$this
->assertSession()
->linkExists('Test menu link');
$edit = [
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->linkExists('Test menu link draft');
$edit = [
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$node = $this
->drupalCreateNode();
$edit = [
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$edit = [
'menu[enabled]' => 1,
'menu[title]' => 'Second test menu link',
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$this
->assertSession()
->linkNotExists('Second test menu link');
$edit = [
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Page {$node->label()} has been updated.");
$this
->assertSession()
->linkExists('Second test menu link');
}
}