'layout_builder_views_test',
'layout_test',
'block',
+ 'block_test',
'node',
'layout_builder_test',
];
// The body field is only present once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// The extra field is only present once.
- $this->assertTextAppearsOnce('Placeholder for the "Extra label" field');
+ $assert_session->pageTextContainsOnce('Placeholder for the "Extra label" field');
// Save the defaults.
$assert_session->linkExists('Save Layout');
$this->clickLink('Save Layout');
// The body field is only present once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// The extra field is only present once.
- $this->assertTextAppearsOnce('Placeholder for the "Extra label" field');
+ $assert_session->pageTextContainsOnce('Placeholder for the "Extra label" field');
// Add a new block.
$assert_session->linkExists('Add Block');
}
/**
- * Asserts that a text string only appears once on the page.
+ * Tests the usage of placeholders for empty blocks.
*
- * @param string $needle
- * The string to look for.
+ * @see \Drupal\Core\Block\BlockPluginInterface::getPlaceholderString()
+ * @see \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()
*/
- protected function assertTextAppearsOnce($needle) {
- $this->assertEquals(1, substr_count($this->getSession()->getPage()->getContent(), $needle), "'$needle' only appears once on the page.");
+ public function testBlockPlaceholder() {
+ $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->drupalPostForm("$field_ui_prefix/display/default", ['layout[enabled]' => TRUE], 'Save');
+
+ // Customize the default view mode.
+ $this->drupalGet("$field_ui_prefix/display-layout/default");
+
+ // 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::state()->set('block_test.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);
+ }
+
+ /**
+ * Tests the Block UI when Layout Builder is installed.
+ */
+ public function testBlockUiListing() {
+ $assert_session = $this->assertSession();
+ $page = $this->getSession()->getPage();
+
+ $this->drupalLogin($this->drupalCreateUser([
+ 'administer blocks',
+ ]));
+
+ $this->drupalGet('admin/structure/block');
+ $page->clickLink('Place block');
+
+ // Ensure that blocks expected to appear are available.
+ $assert_session->pageTextContains('Test HTML block');
+ $assert_session->pageTextContains('Block test');
+ // Ensure that blocks not expected to appear are not available.
+ $assert_session->pageTextNotContains('Body');
+ $assert_session->pageTextNotContains('Content fields');
}
}