You are here

protected function ContentTranslationFieldSyncRevisionTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationFieldSyncRevisionTest::setUp()

Overrides EntityKernelTestBase::setUp

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php, line 61

Class

ContentTranslationFieldSyncRevisionTest
Tests the field synchronization logic when revisions are involved.

Namespace

Drupal\Tests\content_translation\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $entity_type_id = 'entity_test_mulrev';
  $this
    ->installEntitySchema($entity_type_id);
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  ConfigurableLanguage::createFromLangcode('it')
    ->save();
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();

  /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
  $field_storage_config = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'type' => 'image',
    'entity_type' => $entity_type_id,
    'cardinality' => 1,
    'translatable' => 1,
  ]);
  $field_storage_config
    ->save();
  $field_config = FieldConfig::create([
    'entity_type' => $entity_type_id,
    'field_name' => $this->fieldName,
    'bundle' => $entity_type_id,
    'label' => 'Synchronized field',
    'translatable' => 1,
  ]);
  $field_config
    ->save();
  $property_settings = [
    'alt' => 'alt',
    'title' => 'title',
    'file' => 0,
  ];
  $field_config
    ->setThirdPartySetting('content_translation', 'translation_sync', $property_settings);
  $field_config
    ->save();
  $this->contentTranslationManager = $this->container
    ->get('content_translation.manager');
  $this->contentTranslationManager
    ->setEnabled($entity_type_id, $entity_type_id, TRUE);
  $this->storage = $this->entityTypeManager
    ->getStorage($entity_type_id);
  foreach ($this
    ->getTestFiles('image') as $file) {
    $entity = File::create((array) $file + [
      'status' => 1,
    ]);
    $entity
      ->save();
  }
  $this->state
    ->set('content_translation.entity_access.file', [
    'view' => TRUE,
  ]);
  $account = User::create([
    'name' => $this
      ->randomMachineName(),
    'status' => 1,
  ]);
  $account
    ->save();
}