You are here

class TranslatableFieldTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php \Drupal\Tests\layout_builder\Kernel\TranslatableFieldTest
  2. 9 core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php \Drupal\Tests\layout_builder\Kernel\TranslatableFieldTest

Tests Layout Builder with a translatable layout field.

@group layout_builder

Hierarchy

Expanded class hierarchy of TranslatableFieldTest

File

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

Namespace

Drupal\Tests\layout_builder\Kernel
View source
class TranslatableFieldTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'layout_discovery',
    'layout_builder',
    'entity_test',
    'field',
    'system',
    'user',
    'language',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->installEntitySchema('entity_test');

    // Create a translation.
    ConfigurableLanguage::createFromLangcode('es')
      ->save();
    LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
      'status' => TRUE,
    ])
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    FieldStorageConfig::loadByName('entity_test', OverridesSectionStorage::FIELD_NAME)
      ->setTranslatable(TRUE)
      ->save();
    FieldConfig::loadByName('entity_test', 'entity_test', OverridesSectionStorage::FIELD_NAME)
      ->setTranslatable(TRUE)
      ->save();
  }

  /**
   * Tests that sections on cleared when creating a new translation.
   */
  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());
  }

}

Members