You are here

protected function LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp()
  2. 3.4.x tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp()
  3. 3.5.x tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp()
  4. 3.6.x tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp()
  5. 3.8.x tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeLayoutBuilderSymmetricTranslationTest::setUp()

Overrides LingotekTestBase::setUp

File

tests/src/Functional/LingotekNodeLayoutBuilderSymmetricTranslationTest.php, line 36

Class

LingotekNodeLayoutBuilderSymmetricTranslationTest
Tests translating a node with multiple locales including paragraphs.

Namespace

Drupal\Tests\lingotek\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create Article node types.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $bundle = BlockContentType::create([
    'id' => 'custom_content_block',
    'label' => 'Custom content block',
    'revision' => FALSE,
  ]);
  $bundle
    ->save();
  block_content_add_body_field('custom_content_block');

  // Place the actions and title block.
  $this
    ->drupalPlaceBlock('page_title_block', [
    'region' => 'content',
    'weight' => -5,
  ]);
  $this
    ->drupalPlaceBlock('local_tasks_block', [
    'region' => 'content',
    'weight' => -10,
  ]);

  // Add locales.
  ConfigurableLanguage::createFromLangcode('es')
    ->setThirdPartySetting('lingotek', 'locale', 'es_ES')
    ->save();
  ConfigurableLanguage::createFromLangcode('es-ar')
    ->setThirdPartySetting('lingotek', 'locale', 'es_AR')
    ->save();
  $this
    ->configureLayoutBuilder([
    'article',
  ]);

  // Enable translation for the current entity type and ensure the change is
  // picked up.
  ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('node', 'article', TRUE);
  ContentLanguageSettings::loadByEntityTypeBundle('block_content', 'custom_content_block')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('block_content', 'custom_content_block', TRUE);
  drupal_static_reset();
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  $this
    ->applyEntityUpdates();

  // Rebuild the container so that the new languages are picked up by services
  // that hold a list of languages.
  $this
    ->rebuildContainer();
  $this
    ->saveLingotekContentTranslationSettings([
    'node' => [
      'article' => [
        'profiles' => 'manual',
        'fields' => [
          'title' => 1,
          'body' => 1,
          'layout_builder__translation' => 1,
        ],
      ],
    ],
    'block_content' => [
      'custom_content_block' => [
        'profiles' => 'manual',
        'fields' => [
          'body' => 1,
        ],
      ],
    ],
  ]);
}