LayoutBuilderAtReplicateTest.php in Layout Builder Asymmetric Translation 8.2
File
tests/src/Functional/LayoutBuilderAtReplicateTest.php
View source
<?php
namespace Drupal\Tests\layout_builder_at\Functional;
use Drupal\Core\Url;
class LayoutBuilderAtReplicateTest extends LayoutBuilderAtBase {
public static $modules = [
'content_translation',
'contextual',
'entity_test',
'layout_builder',
'layout_builder_at',
'block',
'block_content',
];
protected $entity;
protected function setUp() {
parent::setUp();
$this
->setUpViewDisplay();
$this
->setUpFormDisplay();
$this
->setUpEntities();
$this
->setupBlockType('Text');
}
public function testAsymmetricTranslationWithReplicate() {
$assert_session = $this
->assertSession();
$this
->drupalGet('entity_test_mul/structure/entity_test_mul/display/default/layout');
$this
->drupalGet('admin/config/regional/content-language');
$edit = [
'settings[entity_test_mul][entity_test_mul][fields][layout_builder__layout]' => TRUE,
];
$assert_session
->pageTextNotContains('Layout Builder does not support translating layouts.');
$this
->drupalPostForm(NULL, $edit, 'Save configuration');
$user = $this->loggedInUser;
$this
->drupalLogin($this->fullAdmin);
$url = Url::fromRoute("entity.{$this->entityTypeId}.add_form", [
'type' => 'entity_test_mul',
])
->toString();
$this
->drupalGet($url);
$this
->assertNoText('Copy blocks into translation');
$this
->drupalLogin($user);
$this
->createDefaultTranslationEntity();
$this
->addLayoutOverride(TRUE);
$this
->addEntityTranslation(TRUE);
$entity_url = $this->entity
->toUrl()
->toString();
$language = \Drupal::languageManager()
->getLanguage($this->langcodes[2]);
$translated_entity_url = $this->entity
->toUrl('canonical', [
'language' => $language,
])
->toString();
$this
->drupalGet($entity_url);
$assert_session
->pageTextNotContains(self::translatedTextFieldText);
$assert_session
->pageTextContains(self::defaultTextFieldText);
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$assert_session
->linkExists('Layout');
$assert_session
->pageTextContains('Powered by Drupal');
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextNotContains(self::defaultTextFieldText);
$assert_session
->pageTextContains(self::translatedTextFieldText);
$assert_session
->linkExists('Layout');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$this
->updateLayoutOverride($translated_entity_url, TRUE);
$total = \Drupal::entityTypeManager()
->getStorage('block_content')
->loadMultiple();
self::assertEqual(count($total), 2);
$this
->drupalGet($entity_url);
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextContains(self::translatedContentBlockBody);
$this
->updateNode($this->langcodes[1]);
$this
->drupalGet($entity_url);
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$assert_session
->pageTextContains('Powered by Drupal');
$this
->updateNode($this->langcodes[2]);
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextContains(self::translatedContentBlockBody);
$assert_session
->pageTextContains('Powered by Drupal');
$this
->updateFormDisplay();
$this->entity
->delete();
$this
->createDefaultTranslationEntity();
$this
->addLayoutOverride(TRUE);
$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();
$this
->drupalGet($entity_url);
$assert_session
->pageTextNotContains(self::translatedTextFieldText);
$assert_session
->pageTextContains(self::defaultTextFieldText);
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$assert_session
->linkExists('Layout');
$assert_session
->pageTextContains('Powered by Drupal');
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextNotContains(self::defaultTextFieldText);
$this
->updateLayoutOverride($translated_entity_url, TRUE);
$total = \Drupal::entityTypeManager()
->getStorage('block_content')
->loadMultiple();
self::assertEqual(count($total), 4);
$this
->drupalGet($entity_url);
$assert_session
->pageTextContains(self::defaultContentBlockBody);
$this
->drupalGet($translated_entity_url);
$assert_session
->pageTextContains(self::translatedContentBlockBody);
}
}