function LayoutBuilderPrepareLayoutTest::testAlterPrepareLayout

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

Tests that we can alter a Layout Builder element while preparing.

See also

\Drupal\layout_builder_element_test\EventSubscriber\TestPrepareLayout;

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderPrepareLayoutTest.php, line 78

Class

LayoutBuilderPrepareLayoutTest
Tests the ability to alter a layout builder element while preparing.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testAlterPrepareLayout() : void {
  $assert_session = $this->assertSession();
  $page = $this->getSession()
    ->getPage();
  $this->drupalLogin($this->drupalCreateUser([
    'access content',
    'administer blocks',
    'configure any layout',
    'administer node display',
    'configure all bundle_with_section_field node layout overrides',
  ]));
  // Add a block to the defaults.
  $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
  $page->clickLink('Manage layout');
  $page->clickLink('Add block');
  $page->clickLink('Powered by Drupal');
  $page->fillField('settings[label]', 'Default block title');
  $page->checkField('settings[label_display]');
  $page->pressButton('Add block');
  $page->pressButton('Save layout');
  // Check the block is on the node page.
  $this->drupalGet('node/1');
  $assert_session->pageTextContains('Default block title');
  // When we edit the layout, it gets the static blocks.
  $this->drupalGet('node/1/layout');
  $assert_session->pageTextContains('Test static block title');
  $assert_session->pageTextNotContains('Default block title');
  $assert_session->pageTextContains('Test second static block title');
  // When we edit the second node, only the first event fires.
  $this->drupalGet('node/2/layout');
  $assert_session->pageTextContains('Test static block title');
  $assert_session->pageTextNotContains('Default block title');
  $assert_session->pageTextNotContains('Test second static block title');
  // When we edit the third node, the default exists PLUS our static block.
  $this->drupalGet('node/3/layout');
  $assert_session->pageTextNotContains('Test static block title');
  $assert_session->pageTextContains('Default block title');
  $assert_session->pageTextContains('Test second static block title');
}

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