You are here

public function TranslatableFieldTest::testSectionsClearedOnCreateTranslation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php \Drupal\Tests\layout_builder\Kernel\TranslatableFieldTest::testSectionsClearedOnCreateTranslation()
  2. 10 core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php \Drupal\Tests\layout_builder\Kernel\TranslatableFieldTest::testSectionsClearedOnCreateTranslation()

Tests that sections on cleared when creating a new translation.

File

core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php, line 68

Class

TranslatableFieldTest
Tests Layout Builder with a translatable layout field.

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testSectionsClearedOnCreateTranslation() {
  $section_data = [
    new Section('layout_onecol', [], [
      'first-uuid' => new SectionComponent('first-uuid', 'content', [
        'id' => 'foo',
      ]),
    ]),
  ];
  $entity = EntityTest::create([
    OverridesSectionStorage::FIELD_NAME => $section_data,
  ]);
  $entity
    ->save();
  $this
    ->assertFalse($entity
    ->get(OverridesSectionStorage::FIELD_NAME)
    ->isEmpty());
  $entity = EntityTest::load($entity
    ->id());

  /** @var \Drupal\entity_test\Entity\EntityTest $translation */
  $translation = $entity
    ->addTranslation('es', $entity
    ->toArray());

  // Per-language layouts are not supported.
  $this
    ->assertTrue($translation
    ->get(OverridesSectionStorage::FIELD_NAME)
    ->isEmpty());
}