You are here

public function TranslationTest::testLabelTranslation in Layout Builder Symmetric Translations 8

Tests that block labels can be translated.

@dataProvider providerLabelTranslation

File

tests/src/FunctionalJavascript/TranslationTest.php, line 59

Class

TranslationTest
Tests that block settings can be translated.

Namespace

Drupal\Tests\layout_builder_st\FunctionalJavascript

Code

public function testLabelTranslation($install_before) {
  if ($install_before) {
    $this->container
      ->get('module_installer')
      ->install([
      'layout_builder_st',
    ]);
    $this
      ->layoutBuilderSetup();
  }
  else {
    $this
      ->layoutBuilderSetup();
    $this->container
      ->get('module_installer')
      ->install([
      'layout_builder_st',
    ]);
  }
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access contextual links',
    'configure any layout',
  ]));

  // Add a new inline block to the original node.
  $this
    ->drupalGet('node/1/layout');
  $this
    ->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody', 'Configure');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', '#drupal-off-canvas'));
  $page
    ->fillField('settings[label]', 'field label untranslated');
  $page
    ->checkField('settings[label_display]');
  $page
    ->pressButton('Update');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertNoElementAfterWait('#drupal-off-canvas');
  $this
    ->addBlock('Powered by Drupal', '.block-system-powered-by-block', TRUE, 'untranslated label');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->buttonExists('Save layout');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('node/1');

  // Update the translations block label.
  $this
    ->drupalGet('it/node/1/layout');
  $this
    ->assertNonTranslationActionsRemoved();
  $this
    ->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label in translation');
  $assert_session
    ->buttonExists('Save layout');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('it/node/1');
  $assert_session
    ->pageTextContains('label in translation');
  $assert_session
    ->pageTextNotContains('untranslated label');

  // Confirm that untranslated label is still used on default translation.
  $this
    ->drupalGet('node/1');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');

  // Update the translations block label.
  $this
    ->drupalGet('it/node/1/layout');
  $this
    ->assertNonTranslationActionsRemoved();
  $this
    ->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label updated in translation', 'label in translation');
  $assert_session
    ->buttonExists('Save layout');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('it/node/1');
  $assert_session
    ->pageTextContains('label updated in translation');
  $assert_session
    ->pageTextNotContains('label in translation');
}