function LayoutBuilderEntityViewDisplayTest::testBuildOnlyWhenSupported

Tests that buildMultiple doesn't build sections if storage isn't supported.

File

core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php, line 126

Class

LayoutBuilderEntityViewDisplayTest
Tests Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay.

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testBuildOnlyWhenSupported() : void {
  $display = LayoutBuilderEntityViewDisplay::load('entity_test.entity_test.default');
  $entity = EntityTest::create([
    'type' => 'entity_test',
    'name' => 'test',
  ]);
  $entity->save();
  $buildList = $display->buildMultiple([
    $entity->id() => $entity,
  ]);
  $this->assertArrayHasKey('_layout_builder', $buildList[$entity->id()]);
  // Disable layout_builder for this display and check sections aren't
  // built.
  $display->disableLayoutBuilder()
    ->save();
  $buildList = $display->buildMultiple([
    $entity->id() => $entity,
  ]);
  $this->assertArrayNotHasKey('_layout_builder', $buildList[$entity->id()]);
}

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