You are here

protected function LayoutBuilderNestedFormUiTest::addFormBlock in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderNestedFormUiTest::addFormBlock()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderNestedFormUiTest::addFormBlock()

Adds a form block specified by label layout and checks it can be saved.

Need to test saving and resaving, because nested forms can cause issues on the second save.

Parameters

string $label: The form block label that will be used to identify link to add block.

string $path: Root path of the entity (i.e. node/{NID) or the entity view display path.

string $expected_save_message: The message that should be displayed after successful layout save.

2 calls to LayoutBuilderNestedFormUiTest::addFormBlock()
LayoutBuilderNestedFormUiTest::testAddingFormBlocksToDefaults in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php
Tests blocks containing forms can be successfully saved editing defaults.
LayoutBuilderNestedFormUiTest::testAddingFormBlocksToOverrides in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php
Tests blocks containing forms can be successfully saved editing overrides.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php, line 134

Class

LayoutBuilderNestedFormUiTest
Tests placing blocks containing forms in theLayout Builder UI.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function addFormBlock($label, $path, $expected_save_message) {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();

  // Go to edit the layout.
  $this
    ->drupalGet($path . '/layout');

  // Add the form block.
  $assert_session
    ->linkExists('Add block');
  $this
    ->clickLink('Add block');
  $assert_session
    ->waitForElementVisible('named', [
    'link',
    $label,
  ]);
  $assert_session
    ->linkExists($label);
  $this
    ->clickLink($label);
  $assert_session
    ->waitForElementVisible('named', [
    'button',
    'Add block',
  ]);
  $page
    ->pressButton('Add block');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->pageTextContains($label);
  $assert_session
    ->addressEquals($path . '/layout');

  // Save the defaults.
  $page
    ->pressButton('Save layout');
  $assert_session
    ->pageTextContains($expected_save_message);
  $assert_session
    ->addressEquals($path);

  // Go back to edit layout and try to re-save.
  $this
    ->drupalGet($path . '/layout');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->pageTextContains($expected_save_message);
  $assert_session
    ->addressEquals($path);
}