function InlineBlockTest::testAccess

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

Tests access to the block edit form of inline blocks.

This module does not provide links to these forms but in case the paths are accessed directly they should accessible by users with the 'configure any layout' permission.

See also

layout_builder_block_content_access()

File

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

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testAccess() : void {
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
        'administer node display',
        'administer node fields',
        'create and edit custom blocks',
    ]));
    $assert_session = $this->assertSession();
    // Enable layout builder and overrides.
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
        'layout[allow_custom]' => TRUE,
    ], 'Save');
    // Ensure we have 2 copies of the block in node overrides.
    $this->drupalGet('node/1/layout');
    $this->addInlineBlockToLayout('Block title', 'Block body');
    $this->assertSaveLayout();
    $node_1_block_id = $this->getLatestBlockEntityId();
    $this->drupalGet("block/{$node_1_block_id}");
    $assert_session->pageTextNotContains('You are not authorized to access this page');
    $this->drupalLogout();
    $this->drupalLogin($this->drupalCreateUser([
        'administer nodes',
    ]));
    $this->drupalGet("block/{$node_1_block_id}");
    $assert_session->pageTextContains('You are not authorized to access this page');
    $this->drupalLogin($this->drupalCreateUser([
        'create and edit custom blocks',
    ]));
    $this->drupalGet("block/{$node_1_block_id}");
    $assert_session->pageTextNotContains('You are not authorized to access this page');
}

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