You are here

public function LayoutBuilderTranslationTest::testTranslationBeforeLayoutOverride in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTranslationTest::testTranslationBeforeLayoutOverride()

Tests that layout overrides work when created after a translation.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php, line 51

Class

LayoutBuilderTranslationTest
Tests that the Layout Builder works with translated content.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testTranslationBeforeLayoutOverride() {
  $assert_session = $this
    ->assertSession();
  $this
    ->addEntityTranslation();
  $entity_url = $this->entity
    ->toUrl()
    ->toString();
  $language = \Drupal::languageManager()
    ->getLanguage($this->langcodes[2]);
  $translated_entity_url = $this->entity
    ->toUrl('canonical', [
    'language' => $language,
  ])
    ->toString();
  $translated_layout_url = $translated_entity_url . '/layout';
  $this
    ->drupalGet($entity_url);
  $assert_session
    ->pageTextNotContains('The translated field value');
  $assert_session
    ->pageTextContains('The untranslated field value');
  $assert_session
    ->linkExists('Layout');
  $this
    ->drupalGet($translated_entity_url);
  $assert_session
    ->pageTextNotContains('The untranslated field value');
  $assert_session
    ->pageTextContains('The translated field value');
  $assert_session
    ->linkNotExists('Layout');
  $this
    ->drupalGet($translated_layout_url);
  $assert_session
    ->pageTextContains('Access denied');
  $this
    ->addLayoutOverride();
  $this
    ->drupalGet($entity_url);
  $assert_session
    ->pageTextNotContains('The translated field value');
  $assert_session
    ->pageTextContains('The untranslated field value');
  $assert_session
    ->pageTextContains('Powered by Drupal');

  // Ensure that the layout change propagates to the translated entity.
  $this
    ->drupalGet($translated_entity_url);
  $assert_session
    ->pageTextNotContains('The untranslated field value');
  $assert_session
    ->pageTextContains('The translated field value');
  $assert_session
    ->pageTextContains('Powered by Drupal');
}