function InlineBlockTest::testEditInlineBlocksPermission

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testEditInlineBlocksPermission()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testEditInlineBlocksPermission()
  3. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testEditInlineBlocksPermission()

Tests 'create and edit custom blocks' permission to edit an existing block.

File

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

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testEditInlineBlocksPermission() : void {
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')->enableLayoutBuilder()
        ->setOverridable()
        ->save();
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
        'administer node display',
        'create and edit custom blocks',
    ]));
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    $this->addInlineBlockToLayout('The block label', 'The body value');
    $assert = function ($permissions, $expected) {
        $assert_session = $this->assertSession();
        $this->drupalLogin($this->drupalCreateUser($permissions));
        $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
        $this->clickContextualLink(static::INLINE_BLOCK_LOCATOR, 'Configure');
        $assert_session->assertWaitOnAjaxRequest();
        if ($expected) {
            $assert_session->fieldExists('settings[block_form][body][0][value]');
        }
        else {
            $assert_session->fieldNotExists('settings[block_form][body][0][value]');
        }
    };
    $permissions = [
        'access contextual links',
        'configure any layout',
        'administer node display',
    ];
    $assert($permissions, FALSE);
    $permissions[] = 'create and edit custom blocks';
    $assert($permissions, TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.