X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Ftests%2Fsrc%2FFunctional%2FLayoutBuilderTest.php;h=5f7df456ef5ef32be2e03188d13e201b5e408119;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=50e84f13d770412bfe21a6018ef6bdcc4d6e44c5;hpb=0bf8d09d2542548982e81a441b1f16e75873a04f;p=yaffs-website diff --git a/web/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/web/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 50e84f13d..5f7df456e 100644 --- a/web/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/web/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -22,6 +22,7 @@ class LayoutBuilderTest extends BrowserTestBase { 'layout_builder_views_test', 'layout_test', 'block', + 'block_test', 'node', 'layout_builder_test', ]; @@ -90,7 +91,7 @@ class LayoutBuilderTest extends BrowserTestBase { // 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'); @@ -105,7 +106,7 @@ class LayoutBuilderTest extends BrowserTestBase { // 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'); @@ -514,13 +515,68 @@ class LayoutBuilderTest extends BrowserTestBase { } /** - * 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'); } }