You are here

public function LayoutSectionTest::testLayoutSectionFormatterAccess in Drupal 9

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

Tests the access checking of the section formatter.

File

core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php, line 186

Class

LayoutSectionTest
Tests the rendering of a layout section field.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testLayoutSectionFormatterAccess() {
  $node = $this
    ->createSectionNode([
    [
      'section' => new Section('layout_onecol', [], [
        'baz' => new SectionComponent('baz', 'content', [
          'id' => 'test_access',
        ]),
      ]),
    ],
  ]);

  // Restrict access to the block.
  $this->container
    ->get('state')
    ->set('test_block_access', FALSE);
  $this
    ->drupalGet($node
    ->toUrl('canonical'));
  $this
    ->assertLayoutSection('.layout--onecol', NULL, '', '', 'UNCACHEABLE');

  // Ensure the block was not rendered.
  $this
    ->assertSession()
    ->pageTextNotContains('Hello test world');

  // Grant access to the block, and ensure it was rendered.
  $this->container
    ->get('state')
    ->set('test_block_access', TRUE);
  $this
    ->drupalGet($node
    ->toUrl('canonical'));
  $this
    ->assertLayoutSection('.layout--onecol', 'Hello test world', '', '', 'UNCACHEABLE');
}