LayoutBuilderRestrictionsTest.php in Layout Builder Restrictions 8
File
tests/src/FunctionalJavascript/LayoutBuilderRestrictionsTest.php
View source
<?php
namespace Drupal\Tests\layout_builder_restrictions\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class LayoutBuilderRestrictionsTest extends WebDriverTestBase {
public static $modules = [
'block',
'layout_builder',
'layout_builder_restrictions',
'node',
'field_ui',
];
protected function setUp() {
parent::setUp();
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'administer blocks',
'administer node display',
'administer node fields',
'configure any layout',
]));
}
public function testBlockRestriction() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$page
->checkField('layout[enabled]');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$this
->clickLink('Add Block');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkExists('Body');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$element = $page
->find('xpath', '//*[@id="edit-layout-layout-builder-restrictions-allowed-blocks"]/summary');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-all"]');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-restricted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-restricted"]');
$element
->click();
$page
->pressButton('Save');
$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
->elementExists('css', '.field--name-body');
$this
->clickLink('Add Block');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkNotExists('Body');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$element = $page
->find('xpath', '//*[@id="edit-layout-layout-builder-restrictions-allowed-blocks"]/summary');
$element
->click();
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-restricted');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Content fields][field_block:node:bundle_with_section_field:body]');
$page
->pressButton('Save');
$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
->elementExists('css', '.field--name-body');
$this
->clickLink('Add Block');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkExists('Body');
$assert_session
->linkNotExists('Promoted to front page');
$assert_session
->linkNotExists('Sticky at top of lists');
}
public function testLayoutRestriction() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$page
->checkField('layout[enabled]');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default/layout");
$assert_session
->elementExists('css', '.field--name-body');
$this
->clickLink('Add Section');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkExists('One column');
$assert_session
->linkExists('Two column');
$this
->drupalGet("{$field_ui_prefix}/display/default");
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts"]/summary');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layout-restriction-all"]');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-layouts-layout-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-layouts-layout-restriction-restricted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layout-restriction-restricted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layouts-layout-twocol-section"]');
$element
->click();
$page
->pressButton('Save');
$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");
$this
->clickLink('Add Section');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkNotExists('One column');
$assert_session
->linkExists('Two column');
}
}