You are here

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

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

Overrides LingotekTestBase::setUp

File

tests/src/Functional/LingotekNodeWithTablefieldTranslationTest.php, line 32

Class

LingotekNodeWithTablefieldTranslationTest
Tests translating a node that contains a block field.

Namespace

Drupal\Tests\lingotek\Functional

Code

protected function setUp() : void {
  $this
    ->markTestSkipped('Requires tablefield and that has not a D9 compatible version.');
  parent::setUp();

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

  // Create Article node types.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $fieldStorage = \Drupal::entityTypeManager()
    ->getStorage('field_storage_config')
    ->create([
    'field_name' => 'field_table',
    'entity_type' => 'node',
    'type' => 'tablefield',
    'settings' => [],
    'cardinality' => 1,
  ]);
  $fieldStorage
    ->save();
  $field_config = \Drupal::entityTypeManager()
    ->getStorage('field_config')
    ->create([
    'field_name' => 'field_table',
    'label' => 'Table',
    'entity_type' => 'node',
    'bundle' => 'article',
    'required' => FALSE,
    'settings' => [],
  ]);
  $field_config
    ->save();
  EntityFormDisplay::load('node.article.default')
    ->setComponent('field_table', [
    'type' => 'tablefield',
    'settings' => [],
  ])
    ->save();
  EntityViewDisplay::load('node.article.default')
    ->setComponent('field_table', [
    'type' => 'tablefield',
  ])
    ->save();

  // Add locales.
  ConfigurableLanguage::createFromLangcode('es')
    ->setThirdPartySetting('lingotek', 'locale', 'es_ES')
    ->save();
  ConfigurableLanguage::createFromLangcode('es-ar')
    ->setThirdPartySetting('lingotek', 'locale', 'es_AR')
    ->save();

  // 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);
  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' => 'automatic',
        'fields' => [
          'title' => 1,
          'body' => 1,
          'field_table' => 1,
        ],
      ],
    ],
  ]);
}