BlacklistedRestrictionsTest.php in Layout Builder Restrictions 8.2
File
tests/src/FunctionalJavascript/BlacklistedRestrictionsTest.php
View source
<?php
namespace Drupal\Tests\layout_builder_restrictions\FunctionalJavascript;
class BlacklistedRestrictionsTest 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-blacklisted');
$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-blacklisted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-blacklisted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-custom-block-types-restriction-blacklisted"]');
$element
->click();
$page
->pressButton('Save');
$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-blacklisted');
$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-blacklisted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-blacklisted"]');
$element
->click();
$page
->pressButton('Save');
$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');
$assert_session
->linkExists('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-blacklisted');
$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
->linkNotExists('Body');
$assert_session
->linkExists('Promoted to front page');
$assert_session
->linkExists('Sticky at top of lists');
$assert_session
->linkNotExists('Basic Block 1');
$assert_session
->linkNotExists('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
->linkNotExists('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-blacklisted"]');
$element
->click();
$page
->checkField('layout_builder_restrictions[allowed_blocks][Custom blocks][available_blocks][block_content:' . $blocks['Basic Block 1'] . ']');
$page
->checkField('layout_builder_restrictions[allowed_blocks][Custom blocks][available_blocks][block_content:' . $blocks['Alternate Block 1'] . ']');
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkNotExists('Basic Block 1');
$assert_session
->linkExists('Basic Block 2');
$assert_session
->linkNotExists('Alternate Block 1');
}
}