Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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\Tests\content_moderation\Traits\ContentModerationTestTrait;
7
8 /**
9  * Tests Menu UI and Content Moderation integration.
10  *
11  * @group menu_ui
12  */
13 class MenuUiContentModerationTest extends BrowserTestBase {
14
15   use ContentModerationTestTrait;
16
17   /**
18    * Modules to install.
19    *
20    * @var array
21    */
22   public static $modules = ['block', 'content_moderation', 'node', 'menu_ui', 'test_page_test'];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     $this->drupalPlaceBlock('system_menu_block:main');
31
32     // Create a 'page' content type.
33     $this->drupalCreateContentType([
34       'type' => 'page',
35       'name' => 'Basic page',
36       'display_submitted' => FALSE,
37     ]);
38
39     $workflow = $this->createEditorialWorkflow();
40     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
41     $workflow->save();
42   }
43
44   /**
45    * Tests that node drafts can not modify the menu settings.
46    */
47   public function testMenuUiWithPendingRevisions() {
48     $editor = $this->drupalCreateUser([
49       'administer nodes',
50       'administer menu',
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',
57     ]);
58     $this->drupalLogin($editor);
59
60     // Create a node.
61     $node = $this->drupalCreateNode();
62
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()]));
66
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()]));
71
72     // Add a menu link and save a new default (published) revision.
73     $edit = [
74       'menu[enabled]' => 1,
75       'menu[title]' => 'Test menu link',
76       'moderation_state[0][state]' => 'published',
77     ];
78     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
79
80     $this->assertSession()->linkExists('Test menu link');
81
82     // Try to change the menu link title and save a new non-default (draft)
83     // revision.
84     $edit = [
85       'menu[title]' => 'Test menu link draft',
86       'moderation_state[0][state]' => 'draft',
87     ];
88     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
89
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');
94
95     // Try to change the menu link description and save a new non-default
96     // (draft) revision.
97     $edit = [
98       'menu[description]' => 'Test menu link description',
99       'moderation_state[0][state]' => 'draft',
100     ];
101     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
102
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.');
105
106     // Try to change the menu link weight and save a new non-default (draft)
107     // revision.
108     $edit = [
109       'menu[weight]' => 1,
110       'moderation_state[0][state]' => 'draft',
111     ];
112     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
113
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.');
116
117     // Try to change the menu link parent and save a new non-default (draft)
118     // revision.
119     $edit = [
120       'menu[menu_parent]' => 'main:test_page_test.front_page',
121       'moderation_state[0][state]' => 'draft',
122     ];
123     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
124
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.');
127
128     // Try to delete the menu link and save a new non-default (draft) revision.
129     $edit = [
130       'menu[enabled]' => 0,
131       'moderation_state[0][state]' => 'draft',
132     ];
133     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
134
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');
138
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'));
143
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');
147
148     // Create a node.
149     $node = $this->drupalCreateNode();
150
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()]));
155
156     // Add a menu link and save and create a new non-default (draft) revision.
157     $edit = [
158       'menu[enabled]' => 1,
159       'menu[title]' => 'Test menu link',
160       'moderation_state[0][state]' => 'draft',
161     ];
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.');
164   }
165
166 }