You are here

protected function LingotekNodeWithBlockfieldTranslationTest::setUp in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  2. 4.0.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  3. 3.0.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  4. 3.1.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  5. 3.3.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  6. 3.4.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  7. 3.5.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  8. 3.6.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  9. 3.7.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()
  10. 3.8.x tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWithBlockfieldTranslationTest::setUp()

Overrides LingotekTestBase::setUp

File

tests/src/Functional/LingotekNodeWithBlockfieldTranslationTest.php, line 37

Class

LingotekNodeWithBlockfieldTranslationTest
Tests translating a node that contains a block field.

Namespace

Drupal\Tests\lingotek\Functional

Code

protected function setUp() : void {
  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',
  ]);
  $bundle = BlockContentType::create([
    'id' => 'custom_content_block',
    'label' => 'Custom content block',
    'revision' => FALSE,
  ]);
  $bundle
    ->save();
  block_content_add_body_field('custom_content_block');
  $fieldStorage = \Drupal::entityTypeManager()
    ->getStorage('field_storage_config')
    ->create([
    'field_name' => 'field_block',
    'entity_type' => 'node',
    'type' => 'block_field',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ]);
  $fieldStorage
    ->save();
  $field = \Drupal::entityTypeManager()
    ->getStorage('field_config')
    ->create([
    'field_storage' => $fieldStorage,
    'bundle' => 'article',
  ]);
  $field
    ->save();
  EntityFormDisplay::load('node.article.default')
    ->setComponent('field_block', [
    'type' => 'block_field_default',
    'settings' => [
      'configuration_form' => 'full',
    ],
  ])
    ->save();
  EntityViewDisplay::load('node.article.default')
    ->setComponent('field_block', [
    'type' => 'block_field',
  ])
    ->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);
  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' => 'automatic',
        'fields' => [
          'title' => 1,
          'body' => 1,
          'field_block' => 1,
        ],
      ],
    ],
    'block_content' => [
      'custom_content_block' => [
        'profiles' => 'manual',
        'fields' => [
          'body' => 1,
        ],
      ],
    ],
  ]);
}