You are here

protected function LayoutBuilderTestTrait::addBlock in Layout Builder Symmetric Translations 8

Adds a block in the Layout Builder.

Parameters

string $block_link_text: The link text to add the block.

string $rendered_locator: The CSS locator to confirm the block was rendered.

bool $label_display: Whether the label should be displayed.

string|null $label: The label use.

2 calls to LayoutBuilderTestTrait::addBlock()
ModeratedTranslationTest::testModerationTranslatedOverrides in tests/src/FunctionalJavascript/ModeratedTranslationTest.php
Tests a layout overrides that are moderated and translated.
TranslationTest::testLabelTranslation in tests/src/FunctionalJavascript/TranslationTest.php
Tests that block labels can be translated.

File

tests/src/FunctionalJavascript/LayoutBuilderTestTrait.php, line 22

Class

LayoutBuilderTestTrait
Common functions for testing Layout Builder.

Namespace

Drupal\Tests\layout_builder_st\FunctionalJavascript

Code

protected function addBlock($block_link_text, $rendered_locator, $label_display = FALSE, $label = NULL) {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $add_block_text = 'Add block';
  if (version_compare(\Drupal::VERSION, '8.8.0', '<')) {
    $add_block_text = ucwords($add_block_text);
  }

  // Add a new block.
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', "#layout-builder a:contains('{$add_block_text}')"));
  $this
    ->clickLink($add_block_text);
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', '#drupal-off-canvas'));
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->linkExists($block_link_text);
  $this
    ->clickLink($block_link_text);

  // Wait for off-canvas dialog to reopen with block form.
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', ".layout-builder-add-block"));
  $assert_session
    ->assertWaitOnAjaxRequest();
  if ($label_display) {
    $page
      ->checkField('settings[label_display]');
  }
  if ($label !== NULL) {
    $page
      ->fillField('settings[label]', $label);
  }
  $page
    ->pressButton($add_block_text);

  // Wait for block form to be rendered in the Layout Builder.
  $this
    ->assertNotEmpty($assert_session
    ->waitForElement('css', $rendered_locator));
}