You are here

public function DefaultRestrictionsTest::testNewCategoriesAllowed in Layout Builder Restrictions 8.2

When new categories are allowed, a newly available block is allowed.

File

tests/src/FunctionalJavascript/DefaultRestrictionsTest.php, line 47

Class

DefaultRestrictionsTest
Demonstrate that blocks can be individually restricted.

Namespace

Drupal\Tests\layout_builder_restrictions\FunctionalJavascript

Code

public function testNewCategoriesAllowed() {

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

  // From the manage display page, go to manage the layout.
  $this
    ->navigateToManageDisplay();

  // Checking is_enable will show allow_custom.
  $page
    ->checkField('layout[enabled]');
  $page
    ->checkField('layout[allow_custom]');
  $page
    ->pressButton('Save');

  // Restrict all new block categories.
  $this
    ->navigateToManageDisplay();
  $element = $page
    ->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-block-categories-allowed"]');
  $element
    ->click();
  $page
    ->pressButton('Save');

  // Enable the 'Help' module, which provides a plugin block.
  $this->container
    ->get('module_installer')
    ->install([
    'help',
  ]);
  $this
    ->navigateToNodeSettingsTray($node_id);

  // The new 'Help' block is allowed.
  $assert_session
    ->linkExists('Help');

  // Other blocks are allowed because they are listed in the allowed_blocks
  // schema.
  $this
    ->clickLink('Create custom block');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Add a new custom block'));
  $assert_session
    ->linkExists('Basic');
  $assert_session
    ->linkExists('Alternate');
}