public function LayoutBuilderTranslationTest::testLayoutPerTranslation in Layout Builder Symmetric Translations 8
Tests that the Layout Builder UI works with translated content.
File
- tests/
src/ Functional/ LayoutBuilderTranslationTest.php, line 49
Class
- LayoutBuilderTranslationTest
- Tests that the Layout Builder UI works with translated content.
Namespace
Drupal\Tests\layout_builder_st\FunctionalCode
public function testLayoutPerTranslation() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$entity_url = $this->entity
->toUrl('canonical')
->toString();
$language = \Drupal::languageManager()
->getLanguage($this->langcodes[2]);
$translated_entity_url = $this->entity
->toUrl('canonical', [
'language' => $language,
])
->toString();
$layout_url = $entity_url . '/layout';
$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');
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextNotContains('The untranslated field value');
$assert_session
->pageTextContains('The translated field value');
$this
->drupalGet($layout_url);
$assert_session
->pageTextNotContains('The translated field value');
$assert_session
->pageTextContains('The untranslated field value');
// If there is not a layout override the layout translation is not
// accessible.
$this
->drupalGet($translated_layout_url);
$assert_session
->pageTextContains('Access denied');
// Ensure that the tempstore varies per-translation.
$this
->drupalGet($layout_url);
$assert_session
->pageTextNotContains('The translated field value');
$assert_session
->pageTextContains('The untranslated field value');
$add_block_text = 'Add block';
if (version_compare(\Drupal::VERSION, '8.8.0', '<')) {
$add_block_text = ucwords($add_block_text);
}
// Adjust the layout of the original entity.
$assert_session
->linkExists($add_block_text);
$this
->clickLink($add_block_text);
$assert_session
->linkExists('Powered by Drupal');
$this
->clickLink('Powered by Drupal');
$page
->pressButton($add_block_text);
$assert_session
->pageTextContains('Powered by Drupal');
// Confirm the tempstore for the translated layout is not affected.
$this
->drupalGet($translated_layout_url);
$assert_session
->pageTextContains('Access denied');
$this
->drupalGet($layout_url);
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->buttonExists('Save layout');
$page
->pressButton('Save layout');
$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');
// Confirm that layout translation page is accessible once the untranslated
// entity has a override.
$this
->drupalGet($translated_layout_url);
$assert_session
->pageTextNotContains('Access denied');
$assert_session
->pageTextNotContains('The untranslated field value');
$assert_session
->pageTextContains('The translated field value');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->buttonExists('Save layout');
$this
->assertNonTranslationActionsRemoved();
}