function LayoutSectionTest::testLayoutSectionFormatterAccess

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

Class

LayoutSectionTest
Tests the rendering of a layout section field.

Namespace

Drupal\Tests\layout_builder\Functional

Code

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

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