WhitelistedRestrictionsTest.php in Layout Builder Restrictions 8.2
File
tests/src/FunctionalJavascript/WhitelistedRestrictionsTest.php
View source
<?php
namespace Drupal\Tests\layout_builder_restrictions\FunctionalJavascript;
class WhitelistedRestrictionsTest extends LayoutBuilderRestrictionsTestBase {
public function testBlockRestriction() {
$blocks = $this
->generateTestBlocks();
$node_id = $this
->generateTestNode();
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkExists('Body');
$assert_session
->linkExists('Basic Block 1');
$assert_session
->linkExists('Basic Block 2');
$assert_session
->linkExists('Alternate Block 1');
$this
->clickLink('Create custom block');
$this
->assertNotEmpty($assert_session
->waitForText('Add a new custom block'));
$assert_session
->linkExists('Basic');
$assert_session
->linkExists('Alternate');
$this
->navigateToManageDisplay();
$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-whitelisted');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-whitelisted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-whitelisted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-custom-block-types-restriction-whitelisted"]');
$element
->click();
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkNotExists('Body');
$assert_session
->linkNotExists('Basic Block 1');
$assert_session
->linkNotExists('Basic Block 2');
$assert_session
->linkNotExists('Alternate Block 1');
$this
->clickLink('Create custom block');
$this
->assertNotEmpty($assert_session
->waitForText('Add a new custom block'));
$assert_session
->linkExists('Basic');
$assert_session
->linkExists('Alternate');
$this
->navigateToManageDisplay();
$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-whitelisted');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-all');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-whitelisted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-whitelisted"]');
$element
->click();
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkNotExists('Body');
$assert_session
->linkNotExists('Basic Block 1');
$assert_session
->linkNotExists('Basic Block 2');
$assert_session
->linkNotExists('Alternate Block 1');
$assert_session
->linkNotExists('Create custom block');
$this
->navigateToManageDisplay();
$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-whitelisted');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Content fields][available_blocks][field_block:node:bundle_with_section_field:body]');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Custom block types][available_blocks][basic]');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Inline blocks][available_blocks][inline_block:alternate]');
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkExists('Body');
$assert_session
->linkNotExists('Promoted to front page');
$assert_session
->linkNotExists('Sticky at top of lists');
$assert_session
->linkExists('Basic Block 1');
$assert_session
->linkExists('Basic Block 2');
$assert_session
->linkNotExists('Alternate Block 1');
$this
->clickLink('Create custom block');
$this
->assertNotEmpty($assert_session
->waitForText('Add a new custom block'));
$assert_session
->linkNotExists('Basic');
$assert_session
->linkExists('Alternate');
$this
->navigateToManageDisplay();
$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-custom-blocks-restriction-whitelisted"]');
$element
->click();
$page
->checkField('layout_builder_restrictions[allowed_blocks][Custom blocks][available_blocks][block_content:' . $blocks['Alternate Block 1'] . ']');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Custom blocks][available_blocks][block_content:' . $blocks['Basic Block 1'] . ']');
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkExists('Basic Block 1');
$assert_session
->linkNotExists('Basic Block 2');
$assert_session
->linkExists('Alternate Block 1');
}
}