3 namespace Drupal\Tests\menu_ui\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
9 * Tests Menu UI and Content Moderation integration.
13 class MenuUiContentModerationTest extends BrowserTestBase {
15 use ContentModerationTestTrait;
22 public static $modules = ['block', 'content_moderation', 'node', 'menu_ui', 'test_page_test'];
27 protected function setUp() {
30 $this->drupalPlaceBlock('system_menu_block:main');
32 // Create a 'page' content type.
33 $this->drupalCreateContentType([
35 'name' => 'Basic page',
36 'display_submitted' => FALSE,
39 $workflow = $this->createEditorialWorkflow();
40 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
45 * Tests that node drafts can not modify the menu settings.
47 public function testMenuUiWithPendingRevisions() {
48 $editor = $this->drupalCreateUser([
51 'create page content',
52 'edit any page content',
53 'use editorial transition create_new_draft',
54 'use editorial transition publish',
55 'view latest version',
56 'view any unpublished content',
58 $this->drupalLogin($editor);
61 $node = $this->drupalCreateNode();
63 // Publish the node with no changes.
64 $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
65 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
67 // Create a pending revision with no changes.
68 $edit = ['moderation_state[0][state]' => 'draft'];
69 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
70 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
72 // Add a menu link and save a new default (published) revision.
75 'menu[title]' => 'Test menu link',
76 'moderation_state[0][state]' => 'published',
78 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
80 $this->assertSession()->linkExists('Test menu link');
82 // Try to change the menu link title and save a new non-default (draft)
85 'menu[title]' => 'Test menu link draft',
86 'moderation_state[0][state]' => 'draft',
88 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
90 // Check that the menu settings were not applied.
91 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
92 $this->assertSession()->linkExists('Test menu link');
93 $this->assertSession()->linkNotExists('Test menu link draft');
95 // Try to change the menu link description and save a new non-default
98 'menu[description]' => 'Test menu link description',
99 'moderation_state[0][state]' => 'draft',
101 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
103 // Check that the menu settings were not applied.
104 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
106 // Try to change the menu link weight and save a new non-default (draft)
110 'moderation_state[0][state]' => 'draft',
112 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
114 // Check that the menu settings were not applied.
115 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
117 // Try to change the menu link parent and save a new non-default (draft)
120 'menu[menu_parent]' => 'main:test_page_test.front_page',
121 'moderation_state[0][state]' => 'draft',
123 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
125 // Check that the menu settings were not applied.
126 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
128 // Try to delete the menu link and save a new non-default (draft) revision.
130 'menu[enabled]' => 0,
131 'moderation_state[0][state]' => 'draft',
133 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
135 // Check that the menu settings were not applied.
136 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
137 $this->assertSession()->linkExists('Test menu link');
139 // Try to save a new non-default (draft) revision without any changes and
140 // check that the error message is not shown.
141 $edit = ['moderation_state[0][state]' => 'draft'];
142 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
144 // Check that the menu settings were not applied.
145 $this->assertSession()->pageTextNotContains('You can only change the menu settings for the published version of this content.');
146 $this->assertSession()->linkExists('Test menu link');
149 $node = $this->drupalCreateNode();
151 // Publish the node with no changes.
152 $edit = ['moderation_state[0][state]' => 'published'];
153 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
154 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
156 // Add a menu link and save and create a new non-default (draft) revision.
158 'menu[enabled]' => 1,
159 'menu[title]' => 'Test menu link',
160 'moderation_state[0][state]' => 'draft',
162 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
163 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');