You are here

protected function JavascriptTranslationTestTrait::updateBlockTranslation in Layout Builder Symmetric Translations 8

Updates a block label translation.

Parameters

string $block_selector: The CSS selector for the block.

string $untranslated_label: The label untranslated.

string $new_label: The new label to set.

string $expected_label: The expected existing translated label.

array $unexpected_element_selectors: A list of selectors for elements that should be present.

3 calls to JavascriptTranslationTestTrait::updateBlockTranslation()
InlineBlockTranslationTest::testInlineBlockContentTranslation in tests/src/FunctionalJavascript/InlineBlockTranslationTest.php
Tests that inline blocks works with content translation.
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/JavascriptTranslationTestTrait.php, line 31

Class

JavascriptTranslationTestTrait
Common functions for testing Layout Builder with translations.

Namespace

Drupal\Tests\layout_builder_st\FunctionalJavascript

Code

protected function updateBlockTranslation($block_selector, $untranslated_label, $new_label, $expected_label = '', array $unexpected_element_selectors = []) {

  /** @var \Drupal\Tests\WebAssert $assert_session */
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $translation_selector_prefix = $this->usingConfigTranslation ? '#drupal-off-canvas .translation-set ' : '#drupal-off-canvas ';
  $this
    ->clickContextualLink($block_selector, 'Translate block');
  $label_input = $assert_session
    ->waitForElementVisible('css', $translation_selector_prefix . '[name="translation[label]"]');
  $this
    ->assertNotEmpty($label_input);
  $this
    ->assertEquals($expected_label, $label_input
    ->getValue());
  $assert_session
    ->elementTextContains('css', $translation_selector_prefix . '.form-item-source-label', $untranslated_label);
  $label_input
    ->setValue($new_label);
  foreach ($unexpected_element_selectors as $unexpected_element_selector) {
    $assert_session
      ->elementNotExists('css', $unexpected_element_selector);
  }
  $page
    ->pressButton('Translate');
  $this
    ->assertNoElementAfterWait('#drupal-off-canvas');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', "h2:contains(\"{$new_label}\")"));
}