function InlineBlockTest::testAddInlineBlocksPermission

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testAddInlineBlocksPermission()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTest::testAddInlineBlocksPermission()
  3. 11.x 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);
}

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