function LayoutBuilderBlocksTest::testBlockPlaceholder

Same name and namespace in other branches
  1. 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderBlocksTest::testBlockPlaceholder()

Tests the usage of placeholders for empty blocks.

See also

\Drupal\Core\Render\PreviewFallbackInterface::getPreviewFallbackString()

\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()

File

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

Class

LayoutBuilderBlocksTest
Tests the Layout Builder UI with blocks.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testBlockPlaceholder() : void {
  $assert_session = $this->assertSession();
  $page = $this->getSession()
    ->getPage();
  $this->drupalLogin($this->drupalCreateUser([
    'configure any layout',
    'administer node display',
  ]));
  $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
  $this->drupalGet("{$field_ui_prefix}/display/default");
  $this->submitForm([
    'layout[enabled]' => TRUE,
  ], 'Save');
  // Customize the default view mode.
  $this->drupalGet("{$field_ui_prefix}/display/default/layout");
  // Add a block whose content is controlled by state and is empty by default.
  $this->clickLink('Add block');
  $this->clickLink('Test block caching');
  $page->fillField('settings[label]', 'The block label');
  $page->pressButton('Add block');
  $block_content = 'I am content';
  $placeholder_content = 'Placeholder for the "The block label" block';
  // The block placeholder is displayed and there is no content.
  $assert_session->pageTextContains($placeholder_content);
  $assert_session->pageTextNotContains($block_content);
  // Set block content and reload the page.
  \Drupal::keyValue('block_test')->set('content', $block_content);
  $this->getSession()
    ->reload();
  // The block placeholder is no longer displayed and the content is visible.
  $assert_session->pageTextNotContains($placeholder_content);
  $assert_session->pageTextContains($block_content);
}

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