3 namespace Drupal\Tests\menu_ui\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workflows\Entity\Workflow;
9 * Tests Menu UI and Content Moderation integration.
13 class MenuUiContentModerationTest extends BrowserTestBase {
20 public static $modules = ['block', 'content_moderation', 'node', 'menu_ui', 'test_page_test'];
25 protected function setUp() {
28 $this->drupalPlaceBlock('system_menu_block:main');
30 // Create a 'page' content type.
31 $this->drupalCreateContentType([
33 'name' => 'Basic page',
34 'display_submitted' => FALSE,
37 $workflow = Workflow::load('editorial');
38 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
43 * Tests that node drafts can not modify the menu settings.
45 public function testMenuUiWithPendingRevisions() {
46 $editor = $this->drupalCreateUser([
49 'create page content',
50 'edit any page content',
51 'use editorial transition create_new_draft',
52 'use editorial transition publish',
53 'view latest version',
54 'view any unpublished content',
56 $this->drupalLogin($editor);
59 $node = $this->drupalCreateNode();
61 // Publish the node with no changes.
62 $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
63 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
65 // Create a pending revision with no changes.
66 $edit = ['moderation_state[0][state]' => 'draft'];
67 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
68 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
70 // Add a menu link and save a new default (published) revision.
73 'menu[title]' => 'Test menu link',
74 'moderation_state[0][state]' => 'published',
76 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
78 $this->assertSession()->linkExists('Test menu link');
80 // Try to change the menu link title and save a new non-default (draft)
83 'menu[title]' => 'Test menu link draft',
84 'moderation_state[0][state]' => 'draft',
86 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
88 // Check that the menu settings were not applied.
89 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
90 $this->assertSession()->linkExists('Test menu link');
91 $this->assertSession()->linkNotExists('Test menu link draft');
93 // Try to change the menu link description and save a new non-default
96 'menu[description]' => 'Test menu link description',
97 'moderation_state[0][state]' => 'draft',
99 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
101 // Check that the menu settings were not applied.
102 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
104 // Try to change the menu link weight and save a new non-default (draft)
108 'moderation_state[0][state]' => 'draft',
110 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
112 // Check that the menu settings were not applied.
113 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
115 // Try to change the menu link parent and save a new non-default (draft)
118 'menu[menu_parent]' => 'main:test_page_test.front_page',
119 'moderation_state[0][state]' => 'draft',
121 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
123 // Check that the menu settings were not applied.
124 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
126 // Try to delete the menu link and save a new non-default (draft) revision.
128 'menu[enabled]' => 0,
129 'moderation_state[0][state]' => 'draft',
131 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
133 // Check that the menu settings were not applied.
134 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');
135 $this->assertSession()->linkExists('Test menu link');
137 // Try to save a new non-default (draft) revision without any changes and
138 // check that the error message is not shown.
139 $edit = ['moderation_state[0][state]' => 'draft'];
140 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
142 // Check that the menu settings were not applied.
143 $this->assertSession()->pageTextNotContains('You can only change the menu settings for the published version of this content.');
144 $this->assertSession()->linkExists('Test menu link');
147 $node = $this->drupalCreateNode();
149 // Publish the node with no changes.
150 $edit = ['moderation_state[0][state]' => 'published'];
151 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
152 $this->assertSession()->responseContains(t('Page %label has been updated.', ['%label' => $node->toLink($node->label())->toString()]));
154 // Add a menu link and save and create a new non-default (draft) revision.
156 'menu[enabled]' => 1,
157 'menu[title]' => 'Test menu link',
158 'moderation_state[0][state]' => 'draft',
160 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
161 $this->assertSession()->pageTextContains('You can only change the menu settings for the published version of this content.');