Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / menu_ui / tests / src / Functional / MenuUiContentModerationTest.php
1 <?php
2
3 namespace Drupal\Tests\menu_ui\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workflows\Entity\Workflow;
7
8 /**
9  * Tests Menu UI and Content Moderation integration.
10  *
11  * @group menu_ui
12  */
13 class MenuUiContentModerationTest extends BrowserTestBase {
14
15   /**
16    * Modules to install.
17    *
18    * @var array
19    */
20   public static $modules = ['block', 'content_moderation', 'node', 'menu_ui', 'test_page_test'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     $this->drupalPlaceBlock('system_menu_block:main');
29
30     // Create a 'page' content type.
31     $this->drupalCreateContentType([
32       'type' => 'page',
33       'name' => 'Basic page',
34       'display_submitted' => FALSE,
35     ]);
36
37     $workflow = Workflow::load('editorial');
38     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
39     $workflow->save();
40   }
41
42   /**
43    * Tests that node drafts can not modify the menu settings.
44    */
45   public function testMenuUiWithPendingRevisions() {
46     $editor = $this->drupalCreateUser([
47       'administer nodes',
48       'administer menu',
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',
55     ]);
56     $this->drupalLogin($editor);
57
58     // Create a node.
59     $node = $this->drupalCreateNode();
60
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()]));
64
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()]));
69
70     // Add a menu link and save a new default (published) revision.
71     $edit = [
72       'menu[enabled]' => 1,
73       'menu[title]' => 'Test menu link',
74       'moderation_state[0][state]' => 'published',
75     ];
76     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
77
78     $this->assertSession()->linkExists('Test menu link');
79
80     // Try to change the menu link title and save a new non-default (draft)
81     // revision.
82     $edit = [
83       'menu[title]' => 'Test menu link draft',
84       'moderation_state[0][state]' => 'draft',
85     ];
86     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
87
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');
92
93     // Try to change the menu link description and save a new non-default
94     // (draft) revision.
95     $edit = [
96       'menu[description]' => 'Test menu link description',
97       'moderation_state[0][state]' => 'draft',
98     ];
99     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
100
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.');
103
104     // Try to change the menu link weight and save a new non-default (draft)
105     // revision.
106     $edit = [
107       'menu[weight]' => 1,
108       'moderation_state[0][state]' => 'draft',
109     ];
110     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
111
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.');
114
115     // Try to change the menu link parent and save a new non-default (draft)
116     // revision.
117     $edit = [
118       'menu[menu_parent]' => 'main:test_page_test.front_page',
119       'moderation_state[0][state]' => 'draft',
120     ];
121     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
122
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.');
125
126     // Try to delete the menu link and save a new non-default (draft) revision.
127     $edit = [
128       'menu[enabled]' => 0,
129       'moderation_state[0][state]' => 'draft',
130     ];
131     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
132
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');
136
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'));
141
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');
145
146     // Create a node.
147     $node = $this->drupalCreateNode();
148
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()]));
153
154     // Add a menu link and save and create a new non-default (draft) revision.
155     $edit = [
156       'menu[enabled]' => 1,
157       'menu[title]' => 'Test menu link',
158       'moderation_state[0][state]' => 'draft',
159     ];
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.');
162   }
163
164 }