function LayoutSectionTest::testLayoutSectionFormatterAccess
Tests the access checking of the section formatter.
File
- 
              core/modules/ layout_builder/ tests/ src/ Functional/ LayoutSectionTest.php, line 190 
Class
- LayoutSectionTest
- Tests the rendering of a layout section field.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
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('keyvalue')
    ->get('block_test')
    ->set('access', FALSE);
  $this->drupalGet($node->toUrl('canonical'));
  $this->assertLayoutSection('.layout--onecol', NULL, '', '', 'UNCACHEABLE (poor cacheability)');
  // 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('keyvalue')
    ->get('block_test')
    ->set('access', TRUE);
  $this->drupalGet($node->toUrl('canonical'));
  $this->assertLayoutSection('.layout--onecol', 'Hello test world', '', '', 'UNCACHEABLE (poor cacheability)');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
