You are here

public function LayoutBuilderTest::testAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testAccess()
  2. 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testAccess()

Tests that layout builder checks entity view access.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php, line 500

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testAccess() {
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'configure any layout',
    'administer node display',
  ]));
  $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

  // Allow overrides for the layout.
  $this
    ->drupalGet("{$field_ui_prefix}/display/default");
  $this
    ->submitForm([
    'layout[enabled]' => TRUE,
  ], 'Save');
  $this
    ->drupalGet("{$field_ui_prefix}/display/default");
  $this
    ->submitForm([
    'layout[allow_custom]' => TRUE,
  ], 'Save');
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'configure any layout',
  ]));
  $this
    ->drupalGet('node/1');
  $assert_session
    ->pageTextContains('The first node body');
  $assert_session
    ->pageTextNotContains('Powered by Drupal');
  $node = Node::load(1);
  $node
    ->setUnpublished();
  $node
    ->save();
  $this
    ->drupalGet('node/1');
  $assert_session
    ->pageTextNotContains('The first node body');
  $assert_session
    ->pageTextContains('Access denied');
  $this
    ->drupalGet('node/1/layout');
  $assert_session
    ->pageTextNotContains('The first node body');
  $assert_session
    ->pageTextContains('Access denied');
}