You are here

public function InlineBlockTest::testAddInlineBlocksPermission in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testAddInlineBlocksPermission()

Tests the 'create and edit custom blocks' permission to add a new block.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php, line 515

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testAddInlineBlocksPermission() {
  LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
    ->enableLayoutBuilder()
    ->setOverridable()
    ->save();
  $assert = function ($permissions, $expected) {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser($permissions));
    $this
      ->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    $page
      ->clickLink('Add block');
    $this
      ->assertNotEmpty($assert_session
      ->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
    if ($expected) {
      $assert_session
        ->linkExists('Create custom block');
    }
    else {
      $assert_session
        ->linkNotExists('Create custom block');
    }
  };
  $permissions = [
    'configure any layout',
    'administer node display',
  ];
  $assert($permissions, FALSE);
  $permissions[] = 'create and edit custom blocks';
  $assert($permissions, TRUE);
}