3 namespace Drupal\Tests\layout_builder\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the Layout Builder UI.
10 * @group layout_builder
12 class LayoutBuilderTest extends BrowserTestBase {
17 public static $modules = [
27 protected function setUp() {
30 // @todo The Layout Builder UI relies on local tasks; fix in
31 // https://www.drupal.org/project/drupal/issues/2917777.
32 $this->drupalPlaceBlock('local_tasks_block');
35 $this->createContentType(['type' => 'bundle_with_section_field']);
37 'type' => 'bundle_with_section_field',
38 'title' => 'The first node title',
41 'value' => 'The first node body',
46 'type' => 'bundle_with_section_field',
47 'title' => 'The second node title',
50 'value' => 'The second node body',
59 public function testLayoutBuilderUi() {
60 $assert_session = $this->assertSession();
61 $page = $this->getSession()->getPage();
63 $this->drupalLogin($this->drupalCreateUser([
64 'configure any layout',
65 'administer node display',
66 'administer node fields',
69 $this->drupalGet('node/1');
70 $assert_session->pageTextContains('The first node body');
71 $assert_session->pageTextNotContains('Powered by Drupal');
72 $assert_session->linkNotExists('Layout');
74 $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
76 // From the manage display page, go to manage the layout.
77 $this->drupalGet("$field_ui_prefix/display/default");
78 $assert_session->linkExists('Manage layout');
79 $this->clickLink('Manage layout');
80 $assert_session->addressEquals("$field_ui_prefix/display-layout/default");
81 // The body field is present.
82 $assert_session->elementExists('css', '.field--name-body');
85 $assert_session->linkExists('Add Block');
86 $this->clickLink('Add Block');
87 $assert_session->linkExists('Powered by Drupal');
88 $this->clickLink('Powered by Drupal');
89 $page->fillField('settings[label]', 'This is the label');
90 $page->checkField('settings[label_display]');
91 $page->pressButton('Add Block');
92 $assert_session->pageTextContains('Powered by Drupal');
93 $assert_session->pageTextContains('This is the label');
94 $assert_session->addressEquals("$field_ui_prefix/display-layout/default");
97 $assert_session->linkExists('Save Layout');
98 $this->clickLink('Save Layout');
99 $assert_session->addressEquals("$field_ui_prefix/display/default");
101 // The node uses the defaults, no overrides available.
102 $this->drupalGet('node/1');
103 $assert_session->pageTextContains('The first node body');
104 $assert_session->pageTextContains('Powered by Drupal');
105 $assert_session->linkNotExists('Layout');
108 $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save');
109 $this->drupalGet('node/1');
111 // Remove the section from the defaults.
112 $assert_session->linkExists('Layout');
113 $this->clickLink('Layout');
114 $assert_session->linkExists('Remove section');
115 $this->clickLink('Remove section');
116 $page->pressButton('Remove');
118 // Add a new section.
119 $this->clickLink('Add Section');
120 $assert_session->linkExists('Two column');
121 $this->clickLink('Two column');
122 $assert_session->linkExists('Save Layout');
123 $this->clickLink('Save Layout');
124 $assert_session->pageTextNotContains('The first node body');
125 $assert_session->pageTextNotContains('Powered by Drupal');
127 // Assert that overrides cannot be turned off while overrides exist.
128 $this->drupalGet("$field_ui_prefix/display/default");
129 $assert_session->fieldDisabled('layout[allow_custom]');
131 // Alter the defaults.
132 $this->drupalGet("$field_ui_prefix/display-layout/default");
133 $assert_session->linkExists('Add Block');
134 $this->clickLink('Add Block');
135 $assert_session->linkExists('Title');
136 $this->clickLink('Title');
137 $page->pressButton('Add Block');
138 // The title field is present.
139 $assert_session->elementExists('css', '.field--name-title');
140 $this->clickLink('Save Layout');
142 // View the other node, which is still using the defaults.
143 $this->drupalGet('node/2');
144 $assert_session->pageTextContains('The second node title');
145 $assert_session->pageTextContains('The second node body');
146 $assert_session->pageTextContains('Powered by Drupal');
148 // The overridden node does not pick up the changes to defaults.
149 $this->drupalGet('node/1');
150 $assert_session->elementNotExists('css', '.field--name-title');
151 $assert_session->pageTextNotContains('The first node body');
152 $assert_session->pageTextNotContains('Powered by Drupal');
153 $assert_session->linkExists('Layout');
155 // Reverting the override returns it to the defaults.
156 $this->clickLink('Layout');
157 $assert_session->linkExists('Revert to defaults');
158 $this->clickLink('Revert to defaults');
159 $page->pressButton('Revert');
160 $assert_session->pageTextContains('The layout has been reverted back to defaults.');
161 $assert_session->elementExists('css', '.field--name-title');
162 $assert_session->pageTextContains('The first node body');
163 $assert_session->pageTextContains('Powered by Drupal');
165 // Assert that overrides can be turned off now that all overrides are gone.
166 $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => FALSE], 'Save');
167 $this->drupalGet('node/1');
168 $assert_session->linkNotExists('Layout');
172 'new_storage_type' => 'string',
173 'label' => 'My text field',
174 'field_name' => 'my_text',
176 $this->drupalPostForm("$field_ui_prefix/fields/add-field", $edit, 'Save and continue');
177 $page->pressButton('Save field settings');
178 $page->pressButton('Save settings');
179 $this->drupalGet("$field_ui_prefix/display-layout/default");
180 $assert_session->pageTextContains('My text field');
181 $assert_session->elementExists('css', '.field--name-field-my-text');
184 $this->drupalPostForm("$field_ui_prefix/fields/node.bundle_with_section_field.field_my_text/delete", [], 'Delete');
185 $this->drupalGet("$field_ui_prefix/display-layout/default");
186 $assert_session->pageTextNotContains('My text field');
187 $assert_session->elementNotExists('css', '.field--name-field-my-text');
191 * Tests that component's dependencies are respected during removal.
193 public function testPluginDependencies() {
194 $assert_session = $this->assertSession();
195 $page = $this->getSession()->getPage();
197 $this->container->get('module_installer')->install(['menu_ui']);
198 $this->drupalLogin($this->drupalCreateUser([
199 'configure any layout',
200 'administer node display',
204 // Create a new menu.
205 $this->drupalGet('admin/structure/menu/add');
206 $page->fillField('label', 'My Menu');
207 $page->fillField('id', 'mymenu');
208 $page->pressButton('Save');
209 $this->drupalGet('admin/structure/menu/add');
210 $page->fillField('label', 'My Menu');
211 $page->fillField('id', 'myothermenu');
212 $page->pressButton('Save');
214 $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display-layout/default');
215 $assert_session->linkExists('Add Section');
216 $this->clickLink('Add Section');
217 $assert_session->linkExists('Layout plugin (with dependencies)');
218 $this->clickLink('Layout plugin (with dependencies)');
219 $assert_session->elementExists('css', '.layout--layout-test-dependencies-plugin');
220 $assert_session->elementExists('css', '.field--name-body');
221 $assert_session->linkExists('Save Layout');
222 $this->clickLink('Save Layout');
223 $this->drupalPostForm('admin/structure/menu/manage/myothermenu/delete', [], 'Delete');
224 $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display-layout/default');
225 $assert_session->elementNotExists('css', '.layout--layout-test-dependencies-plugin');
226 $assert_session->elementExists('css', '.field--name-body');
229 $assert_session->linkExists('Add Block');
230 $this->clickLink('Add Block');
231 $assert_session->linkExists('My Menu');
232 $this->clickLink('My Menu');
233 $page->pressButton('Add Block');
235 // Add another block alongside the menu.
236 $assert_session->linkExists('Add Block');
237 $this->clickLink('Add Block');
238 $assert_session->linkExists('Powered by Drupal');
239 $this->clickLink('Powered by Drupal');
240 $page->pressButton('Add Block');
242 // Assert that the blocks are visible, and save the layout.
243 $assert_session->pageTextContains('Powered by Drupal');
244 $assert_session->pageTextContains('My Menu');
245 $assert_session->elementExists('css', '.block.menu--mymenu');
246 $assert_session->linkExists('Save Layout');
247 $this->clickLink('Save Layout');
250 $this->drupalPostForm('admin/structure/menu/manage/mymenu/delete', [], 'Delete');
252 // Ensure that the menu block is gone, but that the other block remains.
253 $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display-layout/default');
254 $assert_session->pageTextContains('Powered by Drupal');
255 $assert_session->pageTextNotContains('My Menu');
256 $assert_session->elementNotExists('css', '.block.menu--mymenu');