public function LayoutBuilderStyleRestrictionsTest::testLayoutRestrictions in Layout Builder Styles 8
Layout Restrictions apply.
File
- tests/
src/ Functional/ LayoutBuilderStyleRestrictionsTest.php, line 57
Class
- LayoutBuilderStyleRestrictionsTest
- Tests the Layout Builder Styles apply as expected.
Namespace
Drupal\Tests\layout_builder_styles\FunctionalCode
public function testLayoutRestrictions() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$block_node = $this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'manage layout builder styles',
'create and edit custom blocks',
]));
// Create an unrestricted layout style.
LayoutBuilderStyle::create([
'id' => 'unrestricted',
'label' => 'Unrestricted',
'classes' => 'unrestricted-class',
'type' => 'section',
])
->save();
// Restrict the 2nd layout style to 'layout_onecol'.
LayoutBuilderStyle::create([
'id' => 'onecol_only',
'label' => 'Onecol only',
'classes' => 'onecol-only',
'type' => 'section',
'layout_restrictions' => [
'layout_onecol',
],
])
->save();
// Restrict the 3rd layout style to 'layout_twocol'.
LayoutBuilderStyle::create([
'id' => 'twocol_only',
'label' => 'Twocol only',
'classes' => 'twocol-only',
'type' => 'section',
'layout_restrictions' => [
'layout_twocol_section',
],
])
->save();
// Examine which styles are allowed on onecol layout.
$this
->drupalGet($block_node
->toUrl());
$page
->clickLink('Layout');
$page
->clickLink('Add section');
$page
->clickLink('One column');
// One column can use "Unrestricted" and "Onecol only".
$assert_session
->elementExists('css', 'select#edit-layout-builder-style option[value="unrestricted"]');
$assert_session
->elementExists('css', 'select#edit-layout-builder-style option[value="onecol_only"]');
$assert_session
->elementNotExists('css', 'select#edit-layout-builder-style option[value="twocol_only"]');
// Examine which styles are allowed on twocol layout.
$this
->drupalGet($block_node
->toUrl());
$page
->clickLink('Layout');
$page
->clickLink('Add section');
$page
->clickLink('Two column');
// Two column can use "Unrestricted" and "Twocol only".
$assert_session
->elementExists('css', 'select#edit-layout-builder-style option[value="unrestricted"]');
$assert_session
->elementNotExists('css', 'select#edit-layout-builder-style option[value="onecol_only"]');
$assert_session
->elementExists('css', 'select#edit-layout-builder-style option[value="twocol_only"]');
// Examine which styles are allowed on three column layout.
$this
->drupalGet($block_node
->toUrl());
$page
->clickLink('Layout');
$page
->clickLink('Add section');
$page
->clickLink('Three column');
// Three column can only use "Unrestricted".
$assert_session
->elementExists('css', 'select#edit-layout-builder-style option[value="unrestricted"]');
$assert_session
->elementNotExists('css', 'select#edit-layout-builder-style option[value="onecol_only"]');
$assert_session
->elementNotExists('css', 'select#edit-layout-builder-style option[value="twocol_only"]');
}