You are here

public function ModeratedTranslationTest::testModerationTranslatedOverrides in Layout Builder Symmetric Translations 8

Tests a layout overrides that are moderated and translated.

File

tests/src/FunctionalJavascript/ModeratedTranslationTest.php, line 140

Class

ModeratedTranslationTest
Test moderated and translated layout overrides.

Namespace

Drupal\Tests\layout_builder_st\FunctionalJavascript

Code

public function testModerationTranslatedOverrides() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $node = Node::load(1);

  // Create a draft layout override.
  $this
    ->drupalGet($node
    ->toUrl());
  $page
    ->clickLink('Layout');
  $assert_session
    ->checkboxChecked('revision');
  $assert_session
    ->fieldDisabled('revision');
  $this
    ->addBlock('Powered by Drupal', '.block-system-powered-by-block', TRUE, 'untranslated label');
  $page
    ->fillField('moderation_state[0][state]', 'draft');
  $page
    ->pressButton('Save layout');

  // Modify the layout.
  $this
    ->drupalGet('it/node/1');

  // Layout link does not exist for translation because published default
  // translation has no override.
  $assert_session
    ->elementNotExists('css', '[data-drupal-link-system-path="node/1/layout"]');

  // Publish the override.
  $this
    ->drupalGet($node
    ->toUrl());
  $page
    ->clickLink('Layout');
  $page
    ->fillField('moderation_state[0][state]', 'published');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('node/1');
  $assert_session
    ->pageTextContains('untranslated label');
  $this
    ->drupalGet('it/node/1');

  // Layout link exists for the translation after publish default translation
  // has an override.
  $assert_session
    ->elementExists('css', '[data-drupal-link-system-path="node/1/layout"]');
  $page
    ->clickLink('Layout');
  $assert_session
    ->checkboxChecked('revision');
  $assert_session
    ->fieldDisabled('revision');
  $assert_session
    ->pageTextContains('untranslated label');
  $this
    ->assertNonTranslationActionsRemoved();
  $this
    ->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label in translation');
  $page
    ->fillField('moderation_state[0][state]', 'draft');
  $page
    ->pressButton('Save layout');

  // The translate draft label is not show in any publish revision yet.
  $this
    ->drupalGet($node
    ->toUrl());
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');
  $page
    ->clickLink('Layout');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');
  $this
    ->drupalGet('it/node/1');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');
  $page
    ->clickLink('Latest version');
  $assert_session
    ->pageTextContains('label in translation');

  // Add a new block to the default translation override.
  $this
    ->drupalGet($node
    ->toUrl());
  $page
    ->clickLink('Layout');
  $this
    ->addBlock('Test block access', '#layout-builder .block-test-access', TRUE, 'untranslated new label');
  $page
    ->fillField('moderation_state[0][state]', 'draft');
  $page
    ->pressButton('Save layout');
  $this
    ->drupalGet('it/node/1');
  $this
    ->clickLink('Layout');
  $assert_session
    ->pageTextContains('label in translation');
  $assert_session
    ->pageTextNotContains('untranslated new label');

  // Publish draft default translation with new block.
  $this
    ->drupalGet($node
    ->toUrl());
  $page
    ->clickLink('Layout');
  $page
    ->fillField('moderation_state[0][state]', 'published');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('node/1');
  $assert_session
    ->pageTextContains('untranslated new label');
  $this
    ->drupalGet('it/node/1');

  // New block in published default translation exists in published
  // translation.
  $assert_session
    ->pageTextContains('untranslated new label');
  $page
    ->clickLink('Latest version');

  // New block in published default translation does not exist in existing
  // draft.
  $assert_session
    ->pageTextNotContains('untranslated new label');
  $this
    ->clickLink('Layout');
  $assert_session
    ->pageTextContains('label in translation');

  // New block in published default translation does not exist in existing
  // draft.
  $assert_session
    ->pageTextNotContains('untranslated new label');
  $page
    ->fillField('moderation_state[0][state]', 'published');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->addressEquals('it/node/1');
  $assert_session
    ->pageTextContains('label in translation');
  $assert_session
    ->pageTextNotContains('untranslated label');
  $assert_session
    ->pageTextContains('untranslated new label');

  // The default translation still uses the untranslated label.
  $this
    ->drupalGet('node/1');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');
  $page
    ->clickLink('Layout');
  $assert_session
    ->pageTextContains('untranslated label');
  $assert_session
    ->pageTextNotContains('label in translation');
}