function LayoutBuilderTest::testAccess

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testAccess()
  2. 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testAccess()
  3. 11.x 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 322

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testAccess() : void {
  $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');
}

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