function LayoutBuilderTest::testLayoutBuilderContexts

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

Tests the Layout Builder UI with a context defined at runtime.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php, line 789

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testLayoutBuilderContexts() : void {
  $node_url = 'node/1';
  $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');
  $this->drupalGet("{$field_ui_prefix}/display/default");
  $this->submitForm([
    'layout[allow_custom]' => TRUE,
  ], 'Save');
  $this->drupalGet($node_url);
  $assert_session->linkExists('Layout');
  $this->clickLink('Layout');
  $assert_session->linkExists('Add section');
  // Add the testing block.
  $page->clickLink('Add block');
  $this->clickLink('Can I have runtime contexts');
  $page->pressButton('Add block');
  // Ensure the runtime context value is rendered before saving.
  $assert_session->pageTextContains('for sure you can');
  // Save the layout, and test that the value is rendered after save.
  $page->pressButton('Save layout');
  $assert_session->addressEquals($node_url);
  $assert_session->pageTextContains('for sure you can');
  $assert_session->elementExists('css', '.layout');
}

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