You are here

public function LanguageCategoriesTest::testBlockRestriction in Layout Builder Restrictions 8.2

Verify that the UI can restrict blocks in Layout Builder settings tray.

File

tests/src/FunctionalJavascript/LanguageCategoriesTest.php, line 108

Class

LanguageCategoriesTest
Demonstrate that blocks can be individually restricted.

Namespace

Drupal\Tests\layout_builder_restrictions\FunctionalJavascript

Code

public function testBlockRestriction() {

  // Create 2 custom block types, with 3 block instances.
  $blocks = $this
    ->generateTestBlocks();
  $node_id = $this
    ->generateTestNode();
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->navigateToNodeSettingsTray($node_id);

  // Initially, the body field is available.
  $assert_session
    ->linkExists('Body');

  // Initially, the Hjelp block is available.
  $assert_session
    ->linkExists('Hjelp');

  // Impose Custom Block type restrictions.
  $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');

  // Restrict all 'Content' fields from options.
  $element = $page
    ->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-whitelisted"]');
  $element
    ->click();

  // Restrict the Hjelp block.
  $element = $page
    ->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-help-restriction-whitelisted"]');
  $element
    ->click();
  $element = $page
    ->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-help-available-blocks-help-block"]');
  $element
    ->click();
  $page
    ->pressButton('Save');
  $this
    ->navigateToNodeSettingsTray($node_id);

  // Establish that the 'body' field is no longer present.
  $assert_session
    ->linkNotExists('Body');

  // Establish that the Hjelp block is still present.
  $assert_session
    ->linkExists('Hjelp');
}