View source
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Section;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Entity\View;
class LayoutBuilderTest extends BrowserTestBase {
protected static $modules = [
'field_ui',
'views',
'layout_builder',
'layout_builder_views_test',
'layout_test',
'block',
'block_test',
'contextual',
'node',
'layout_builder_test',
];
protected $defaultTheme = 'classy';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The second node title',
'body' => [
[
'value' => 'The second node body',
],
],
]);
}
public function testDeleteField() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node fields',
]));
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
->enableLayoutBuilder()
->setOverridable()
->save();
$this
->drupalGet('node/1/layout');
$page
->pressButton('Save layout');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/fields/node.bundle_with_section_field.body/delete');
$page
->pressButton('Delete');
$this
->drupalGet('node/1');
$assert_session
->statusCodeEquals(200);
$this
->drupalGet('node/1/layout');
$assert_session
->statusCodeEquals(200);
}
public function testOverridesWithoutDefaultsAccess() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
]));
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
->enableLayoutBuilder()
->setOverridable()
->save();
$this
->drupalGet('node/1');
$page
->clickLink('Layout');
$assert_session
->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item.');
$assert_session
->linkNotExists('Edit the template for all Bundle with section field content items instead.');
}
public function testOverridesWithoutFieldUi() {
$this->container
->get('module_installer')
->uninstall([
'field_ui',
]);
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->rootUser);
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
->enableLayoutBuilder()
->setOverridable()
->save();
$this
->drupalGet('node/1');
$page
->clickLink('Layout');
$assert_session
->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item.');
$assert_session
->linkNotExists('Edit the template for all Bundle with section field content items instead.');
}
public function testOverrides() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this->container
->get('entity_field.manager')
->clearCachedFieldDefinitions();
$this
->drupalGet('node/1');
$page
->clickLink('Layout');
$assert_session
->fieldNotExists('title[0][value]');
$assert_session
->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item. Edit the template for all Bundle with section field content items instead.');
$assert_session
->linkExists('Edit the template for all Bundle with section field content items instead.');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is an override');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('This is an override');
$components = Node::load(1)
->get('layout_builder__layout')
->getSection(0)
->getComponents();
end($components);
$uuid = key($components);
$this
->drupalGet('layout_builder/update/block/overrides/node.1/0/content/' . $uuid);
$page
->uncheckField('settings[label_display]');
$page
->pressButton('Update');
$assert_session
->pageTextNotContains('This is an override');
$page
->pressButton('Save layout');
$assert_session
->pageTextNotContains('This is an override');
}
public function testNonBundleEntityType() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer user display',
]));
$this
->drupalGet('admin/config/people/accounts/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$assert_session
->pageTextContains('You are editing the layout template for all users.');
$this
->drupalGet('user');
$page
->clickLink('Layout');
$assert_session
->pageTextContains('You are editing the layout for this user. Edit the template for all users instead.');
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
]));
$this
->drupalGet('user');
$page
->clickLink('Layout');
$assert_session
->pageTextContains('You are editing the layout for this user.');
$assert_session
->pageTextNotContains('Edit the template for all users instead.');
}
public function testPreserverEntityValues() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this->container
->get('entity_field.manager')
->clearCachedFieldDefinitions();
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The first node body');
$page
->clickLink('Layout');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->pressButton('Add block');
$node = Node::load(1);
$node
->set('body', 'updated body');
$node
->save();
$page
->clickLink('View');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextContains('updated body');
$page
->clickLink('Layout');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('node/1');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextContains('updated body');
}
public function testLayoutBuilderUi() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$this
->drupalGet('node/1');
$assert_session
->elementNotExists('css', '.layout-builder-block');
$assert_session
->pageTextContains('The first node body');
$assert_session
->pageTextNotContains('Powered by Drupal');
$assert_session
->linkNotExists('Layout');
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$assert_session
->linkNotExists('Manage layout');
$assert_session
->fieldDisabled('layout[allow_custom]');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default/layout");
$assert_session
->elementTextContains('css', '.layout-builder__message.layout-builder__message--defaults', 'You are editing the layout template for all Bundle with section field content items.');
$assert_session
->elementsCount('css', '.field--name-body', 1);
$assert_session
->pageTextContainsOnce('Placeholder for the "Extra label" field');
$assert_session
->elementExists('css', '.layout-builder-block');
$page
->pressButton('Save layout');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default");
$this
->drupalGet("{$field_ui_prefix}/display/default");
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default/layout");
$assert_session
->elementsCount('css', '.field--name-body', 1);
$assert_session
->pageTextContainsOnce('Placeholder for the "Extra label" field');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('Powered by Drupal');
$this
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is the label');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('This is the label');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default/layout");
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('The layout has been saved.');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default");
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The first node body');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('Extra, Extra read all about it.');
$assert_session
->pageTextNotContains('Placeholder for the "Extra label" field');
$assert_session
->linkNotExists('Layout');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->linkExists('Layout');
$this
->clickLink('Layout');
$assert_session
->pageTextContains('Placeholder for the "Extra label" field');
$assert_session
->linkExists('Remove Section 1');
$this
->clickLink('Remove Section 1');
$page
->pressButton('Remove');
$this
->clickLink('Add section');
$this
->assertCorrectLayouts();
$assert_session
->linkExists('Two column');
$this
->clickLink('Two column');
$assert_session
->buttonExists('Add section');
$page
->pressButton('Add section');
$page
->pressButton('Save');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextNotContains('Powered by Drupal');
$assert_session
->pageTextNotContains('Extra, Extra read all about it.');
$assert_session
->pageTextNotContains('Placeholder for the "Extra label" field');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$assert_session
->checkboxChecked('layout[allow_custom]');
$assert_session
->fieldDisabled('layout[allow_custom]');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('Title');
$this
->clickLink('Title');
$page
->pressButton('Add block');
$assert_session
->elementExists('css', '.field--name-title');
$page
->pressButton('Save layout');
$this
->drupalGet('node/2');
$assert_session
->pageTextContains('The second node title');
$assert_session
->pageTextContains('The second node body');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('Extra, Extra read all about it.');
$assert_session
->pageTextNotContains('Placeholder for the "Extra label" field');
$this
->drupalGet('node/1');
$assert_session
->elementNotExists('css', '.field--name-title');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextNotContains('Powered by Drupal');
$assert_session
->pageTextNotContains('Extra, Extra read all about it.');
$assert_session
->pageTextNotContains('Placeholder for the "Extra label" field');
$assert_session
->linkExists('Layout');
$this
->clickLink('Layout');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('ID');
$this
->clickLink('ID');
$page
->pressButton('Add block');
$assert_session
->elementExists('css', '.field--name-nid');
$assert_session
->pageTextContains('ID');
$assert_session
->pageTextContains('1');
$page
->pressButton('Revert to defaults');
$page
->pressButton('Revert');
$assert_session
->addressEquals('node/1');
$assert_session
->pageTextContains('The layout has been reverted back to defaults.');
$assert_session
->elementExists('css', '.field--name-title');
$assert_session
->elementNotExists('css', '.field--name-nid');
$assert_session
->pageTextContains('The first node body');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('Extra, Extra read all about it.');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => FALSE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->linkNotExists('Layout');
$edit = [
'new_storage_type' => 'string',
'label' => 'My text field',
'field_name' => 'my_text',
];
$this
->drupalGet("{$field_ui_prefix}/fields/add-field");
$this
->submitForm($edit, 'Save and continue');
$page
->pressButton('Save field settings');
$page
->pressButton('Save settings');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$assert_session
->pageTextContains('My text field');
$assert_session
->elementExists('css', '.field--name-field-my-text');
$this
->drupalGet("{$field_ui_prefix}/fields/node.bundle_with_section_field.field_my_text/delete");
$this
->submitForm([], 'Delete');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$assert_session
->pageTextNotContains('My text field');
$assert_session
->elementNotExists('css', '.field--name-field-my-text');
$this
->clickLink('Add section');
$this
->clickLink('One column');
$page
->fillField('layout_settings[label]', 'My Cool Section');
$page
->pressButton('Add section');
$expected_labels = [
'My Cool Section',
'Content region in My Cool Section',
'Section 2',
'Content region in Section 2',
];
$labels = [];
foreach ($page
->findAll('css', '[role="group"]') as $element) {
$labels[] = $element
->getAttribute('aria-label');
}
$this
->assertSame($expected_labels, $labels);
}
public function testHtmlEntityFormControllerDecoration() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
\Drupal::service('module_installer')
->install([
'layout_builder_decoration_test',
]);
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$assert_session
->pageTextContains('Manage Display');
}
public function testAccess() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
]));
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The first node body');
$assert_session
->pageTextNotContains('Powered by Drupal');
$node = Node::load(1);
$node
->setUnpublished();
$node
->save();
$this
->drupalGet('node/1');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextContains('Access denied');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextNotContains('The first node body');
$assert_session
->pageTextContains('Access denied');
}
public function testNonDefaultViewMode() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$this
->clickLink('Manage layout');
$assert_session
->elementsCount('css', '.field--name-body', 1);
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->clickLink('Teaser');
$assert_session
->addressEquals("{$field_ui_prefix}/display/teaser");
$assert_session
->elementNotExists('css', '#layout-builder__layout');
$assert_session
->checkboxNotChecked('layout[enabled]');
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$assert_session
->linkExists('Manage layout');
$page
->clickLink('Manage layout');
$assert_session
->elementsCount('css', '.field--name-body', 1);
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$assert_session
->addressEquals("{$field_ui_prefix}/display/teaser");
$page
->clickLink('Default');
$assert_session
->addressEquals("{$field_ui_prefix}/display");
$assert_session
->linkNotExists('Full content');
$page
->checkField('display_modes_custom[full]');
$page
->pressButton('Save');
$assert_session
->linkExists('Full content');
$page
->clickLink('Full content');
$assert_session
->addressEquals("{$field_ui_prefix}/display/full");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$assert_session
->linkExists('Manage layout');
$page
->clickLink('Manage layout');
$assert_session
->elementsCount('css', '.field--name-body', 1);
}
public function testPluginDependencies() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this->container
->get('module_installer')
->install([
'menu_ui',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer menu',
]));
$this
->drupalGet('admin/structure/menu/add');
$page
->fillField('label', 'My Menu');
$page
->fillField('id', 'my-menu');
$page
->pressButton('Save');
$this
->drupalGet('admin/structure/menu/add');
$page
->fillField('label', 'My Menu');
$page
->fillField('id', 'my-other-menu');
$page
->pressButton('Save');
$page
->clickLink('Add link');
$page
->fillField('title[0][value]', 'My link');
$page
->fillField('link[0][uri]', '/');
$page
->pressButton('Save');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->linkExists('Add section');
$this
->clickLink('Add section');
$assert_session
->linkExists('Layout plugin (with dependencies)');
$this
->clickLink('Layout plugin (with dependencies)');
$page
->pressButton('Add section');
$assert_session
->elementExists('css', '.layout--layout-test-dependencies-plugin');
$assert_session
->elementExists('css', '.field--name-body');
$page
->pressButton('Save layout');
$this
->drupalGet('admin/structure/menu/manage/my-other-menu/delete');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session
->elementNotExists('css', '.layout--layout-test-dependencies-plugin');
$assert_session
->elementExists('css', '.field--name-body');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('My Menu');
$this
->clickLink('My Menu');
$page
->pressButton('Add block');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('Powered by Drupal');
$this
->clickLink('Powered by Drupal');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('My Menu');
$assert_session
->elementExists('css', '.block.menu--my-menu');
$page
->pressButton('Save layout');
$this
->drupalGet('admin/structure/menu/manage/my-menu/delete');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextNotContains('My Menu');
$assert_session
->elementNotExists('css', '.block.menu--my-menu');
}
public function testPluginsProvidingCustomAttributesAndContextualLinks() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'access contextual links',
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add section');
$page
->clickLink('Layout Builder Test Plugin');
$page
->pressButton('Add section');
$page
->clickLink('Add block');
$page
->clickLink('Test Attributes');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->elementExists('css', '.attribute-test-class');
$assert_session
->elementExists('css', '[custom-attribute=test]');
$assert_session
->elementExists('css', 'div[data-contextual-id*="layout_builder_test"]');
}
public function testPreviewAwarePlugins() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add section');
$page
->clickLink('Layout Builder Test Plugin');
$page
->pressButton('Add section');
$page
->clickLink('Add block');
$page
->clickLink('Preview-aware block');
$page
->pressButton('Add block');
$assert_session
->elementExists('css', '.go-birds-preview');
$assert_session
->pageTextContains('This block is being rendered in preview mode.');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->elementNotExists('css', '.go-birds-preview');
$assert_session
->pageTextContains('This block is being rendered normally.');
}
public function testLayoutBuilderUiFullViewMode() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => FALSE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$this
->clickLink('Add block');
$this
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is the default view mode');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('This is the default view mode');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/full");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/full");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/full/layout");
$this
->clickLink('Add block');
$this
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is the full view mode');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('This is the full view mode');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => FALSE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => TRUE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->clickLink('Add block');
$this
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is an override of the full view mode');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('This is an override of the full view mode');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->drupalGet("{$field_ui_prefix}/display/full/layout");
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$page
->pressButton('Revert to default');
$page
->pressButton('Revert');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextNotContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->clickLink('Add block');
$this
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is an override of the full view mode');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('This is an override of the full view mode');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'display_modes_custom[full]' => FALSE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('This is the full view mode');
$assert_session
->pageTextContains('This is an override of the full view mode');
$assert_session
->pageTextNotContains('This is the default view mode');
$this
->drupalGet('node/1/layout');
$page
->pressButton('Revert to default');
$page
->pressButton('Revert');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('This is the default view mode');
$assert_session
->pageTextNotContains('This is the full view mode');
$page
->pressButton('Discard changes');
$page
->pressButton('Confirm');
}
public function testFullViewModeMultipleBundles() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->createContentType([
'type' => 'full_bundle',
]);
$this
->drupalGet('admin/structure/types/manage/full_bundle/display/default');
$page
->checkField('display_modes_custom[full]');
$page
->pressButton('Save');
$this
->createContentType([
'type' => 'default_bundle',
]);
$this
->drupalGet('admin/structure/types/manage/default_bundle/display/default');
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$assert_session
->checkboxChecked('layout[allow_custom]');
}
public function testLayoutBuilderChooseBlocksAlter() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$this
->clickLink('Add block');
$assert_session
->linkExists('Powered by Drupal');
$assert_session
->linkExists('Default revision');
$assert_session
->linkNotExists('Help');
$assert_session
->linkNotExists('Sticky at top of lists');
$assert_session
->linkNotExists('Main page content');
$assert_session
->linkNotExists('Page title');
$assert_session
->linkNotExists('Changed');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->clickLink('Manage layout');
$this
->clickLink('Add section', 1);
$assert_session
->linkExists('Two column');
$this
->clickLink('Two column');
$assert_session
->buttonExists('Add section');
$this
->getSession()
->getPage()
->pressButton('Add section');
$this
->clickLink('Add block', 1);
$assert_session
->linkExists('Changed');
}
public function testExtraFields() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('node');
$assert_session
->linkExists('Read more');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default/layout");
$this
->clickLink('Add block');
$assert_session
->elementTextContains('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details', 'Extra label');
$this
->drupalGet('node');
$assert_session
->linkExists('Read more');
$this
->drupalGet('node/1');
$assert_session
->pageTextNotContains('Extra Field 2 is hidden by default.');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session
->pageTextNotContains('Extra Field 2');
$page = $this
->getSession()
->getPage();
$page
->clickLink('Add block');
$page
->clickLink('Extra Field 2');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('Extra Field 2');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('Extra Field 2 is hidden by default.');
}
public function testPendingRevision() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$node = $storage
->load(1);
$pending_revision = $storage
->createRevision($node, FALSE);
$pending_revision
->set('title', 'The pending title of the first node');
$pending_revision
->save();
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The first node title');
$page
->clickLink('Layout');
$assert_session
->pageTextNotContains('The first node title');
$assert_session
->pageTextContains('The pending title of the first node');
}
public function testDeletedView() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->linkExists('Layout');
$this
->clickLink('Layout');
$this
->clickLink('Add block');
$this
->clickLink('Test Block View');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('Test Block View');
$assert_session
->elementExists('css', '.block-views-blocktest-block-view-block-1');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Test Block View');
$assert_session
->elementExists('css', '.block-views-blocktest-block-view-block-1');
View::load('test_block_view')
->delete();
$this
->drupalGet('node/1');
$assert_session
->pageTextContains(Node::load(1)
->getTitle());
$assert_session
->pageTextNotContains('Test Block View');
}
public function testFormAlter() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$assert_session
->pageTextContains('Layout Builder Storage: node.bundle_with_section_field.default');
$assert_session
->pageTextContains('Layout Builder Section: layout_onecol');
$assert_session
->pageTextContains('Layout Builder Component: system_powered_by_block');
}
public function testSectionLabels() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$this
->drupalGet('node/1/layout');
$page
->clickLink('Add section');
$page
->clickLink('One column');
$page
->fillField('layout_settings[label]', 'My Cool Section');
$page
->pressButton('Add section');
$assert_session
->pageTextContains('My Cool Section');
$page
->pressButton('Save layout');
$assert_session
->pageTextNotContains('My Cool Section');
}
public function testContextAwareLayouts() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$account = $this
->drupalCreateUser([
'configure any layout',
'administer node display',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add section');
$page
->clickLink('Layout Builder Test: Context Aware');
$page
->pressButton('Add section');
$assert_session
->elementExists('css', '.user--' . $account
->getAccountName());
$page
->clickLink('Configure Section 1');
$page
->fillField('layout_settings[label]', 'My section');
$page
->pressButton('Update');
$assert_session
->linkExists('Configure My section');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->elementExists('css', '.user--' . $account
->getAccountName());
}
public function testCustomSectionAttributes() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add section');
$page
->clickLink('Layout Builder Test Plugin');
$page
->pressButton('Add section');
$assert_session
->elementExists('css', '.go-birds');
}
public function testBlockPlaceholder() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$this
->clickLink('Add block');
$this
->clickLink('Test block caching');
$page
->fillField('settings[label]', 'The block label');
$page
->pressButton('Add block');
$block_content = 'I am content';
$placeholder_content = 'Placeholder for the "The block label" block';
$assert_session
->pageTextContains($placeholder_content);
$assert_session
->pageTextNotContains($block_content);
\Drupal::state()
->set('block_test.content', $block_content);
$this
->getSession()
->reload();
$assert_session
->pageTextNotContains($placeholder_content);
$assert_session
->pageTextContains($block_content);
}
public function testOverridesFormAlter() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer nodes',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet('node/1');
$page
->clickLink('Layout');
$assert_session
->checkboxChecked('status[value]');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('The layout override has been saved.');
$page
->clickLink('Layout');
$page
->uncheckField('status[value]');
$page
->pressButton('Save layout');
$assert_session
->statusCodeEquals(403);
$assert_session
->pageTextContains('The layout override has been saved.');
}
public function testBlockUiListing() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'administer blocks',
]));
$this
->drupalGet('admin/structure/block');
$page
->clickLink('Place block');
$assert_session
->pageTextContains('Test HTML block');
$assert_session
->pageTextContains('Block test');
$assert_session
->pageTextNotContains('Body');
$assert_session
->pageTextNotContains('Content fields');
}
public function testBreadcrumb() {
$page = $this
->getSession()
->getPage();
$this
->drupalPlaceBlock('system_breadcrumb_block');
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer content types',
'access administration pages',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$page
->clickLink('Manage layout');
$breadcrumb_titles = [];
foreach ($page
->findAll('css', '.breadcrumb a') as $link) {
$breadcrumb_titles[$link
->getText()] = $link
->getAttribute('href');
}
$base_path = base_path();
$expected = [
'Home' => $base_path,
'Administration' => $base_path . 'admin',
'Structure' => $base_path . 'admin/structure',
'Content types' => $base_path . 'admin/structure/types',
'Bundle with section field' => $base_path . 'admin/structure/types/manage/bundle_with_section_field',
'Manage display' => $base_path . 'admin/structure/types/manage/bundle_with_section_field/display/default',
'External link' => 'http://www.example.com',
];
$this
->assertSame($expected, $breadcrumb_titles);
}
public function testSimpleConfigBasedLayout() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->createUser([
'configure any layout',
]));
$this->container
->get('config.factory')
->getEditable('layout_builder_test.test_simple_config.existing')
->set('sections', [
(new Section('layout_twocol'))
->toArray(),
])
->save();
$this
->drupalGet('layout-builder-test-simple-config/existing');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->elementsCount('css', '.layout--twocol', 1);
$this
->drupalGet('layout-builder-test-simple-config/new');
$assert_session
->elementNotExists('css', '.layout');
}
public function testRemovingAllSections() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet('node/1');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->pageTextContains('The first node body');
$page
->clickLink('Layout');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 2);
$page
->clickLink('Remove Section 1');
$page
->pressButton('Remove');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 1);
$page
->pressButton('Save layout');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->pageTextNotContains('The first node body');
$page
->clickLink('Layout');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 1);
$page
->clickLink('Add section');
$page
->clickLink('One column');
$page
->pressButton('Add section');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 2);
$page
->pressButton('Save layout');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->pageTextNotContains('The first node body');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 2);
$page
->clickLink('Remove Section 1');
$page
->pressButton('Remove');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 1);
$page
->pressButton('Save layout');
$page
->clickLink('Manage layout');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 0);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 1);
$this
->drupalGet('node/1');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->pageTextNotContains('The first node body');
$page
->clickLink('Layout');
$assert_session
->elementsCount('css', '.layout', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-block', 1);
$assert_session
->elementsCount('css', '.layout-builder__add-section', 2);
$page
->pressButton('Revert to defaults');
$page
->pressButton('Revert');
$assert_session
->elementsCount('css', '.layout', 0);
$assert_session
->pageTextNotContains('The first node body');
}
public function testRemovingSectionWithoutLayoutLabel() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default/layout");
$page
->clickLink('Add section');
$assert_session
->linkExists('Layout Without Label');
$page
->clickLink('Layout Without Label');
$page
->pressButton('Add section');
$assert_session
->elementsCount('css', '.layout', 2);
$assert_session
->linkExists('Remove Section 1');
$this
->clickLink('Remove Section 1');
$page
->pressButton('Remove');
$assert_session
->statusCodeEquals(200);
$assert_session
->elementsCount('css', '.layout', 1);
}
protected function assertCorrectLayouts() : void {
$assert_session = $this
->assertSession();
$expected_layouts_hrefs = [
'layout_builder/configure/section/overrides/node.1/0/layout_onecol',
'layout_builder/configure/section/overrides/node.1/0/layout_twocol_section',
'layout_builder/configure/section/overrides/node.1/0/layout_threecol_section',
'layout_builder/configure/section/overrides/node.1/0/layout_fourcol_section',
];
foreach ($expected_layouts_hrefs as $expected_layouts_href) {
$assert_session
->linkByHrefExists($expected_layouts_href);
}
$unexpected_layouts = [
'twocol',
'twocol_bricks',
'threecol_25_50_25',
'threecol_33_34_33',
];
foreach ($unexpected_layouts as $unexpected_layout) {
$assert_session
->linkByHrefNotExists("layout_builder/add/section/overrides/node.1/0/{$unexpected_layout}");
$assert_session
->linkByHrefNotExists("layout_builder/configure/section/overrides/node.1/0/{$unexpected_layout}");
}
}
public function testLayoutBuilderContexts() {
$node_url = 'node/1';
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet($node_url);
$assert_session
->linkExists('Layout');
$this
->clickLink('Layout');
$assert_session
->linkExists('Add section');
$page
->clickLink('Add block');
$this
->clickLink('Can I have runtime contexts');
$page
->pressButton('Add block');
$assert_session
->pageTextContains('for sure you can');
$page
->pressButton('Save layout');
$assert_session
->addressEquals($node_url);
$assert_session
->pageTextContains('for sure you can');
$assert_session
->elementExists('css', '.layout');
}
}