You are here

protected function ContentTranslationSyncUnitTest::setUp in Drupal 8

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

Overrides KernelTestBase::setUp

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php, line 59

Class

ContentTranslationSyncUnitTest
Tests the field synchronization logic.

Namespace

Drupal\Tests\content_translation\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->synchronizer = new FieldTranslationSynchronizer($this->container
    ->get('entity_type.manager'), $this->container
    ->get('plugin.manager.field.field_type'));
  $this->synchronized = [
    'sync1',
    'sync2',
  ];
  $this->columns = array_merge($this->synchronized, [
    'var1',
    'var2',
  ]);
  $this->langcodes = [
    'en',
    'it',
    'fr',
    'de',
    'es',
  ];
  $this->cardinality = 4;
  $this->unchangedFieldValues = [];

  // Set up an initial set of values in the correct state, that is with
  // "synchronized" values being equal.
  foreach ($this->langcodes as $langcode) {
    for ($delta = 0; $delta < $this->cardinality; $delta++) {
      foreach ($this->columns as $column) {
        $sync = in_array($column, $this->synchronized) && $langcode != $this->langcodes[0];
        $value = $sync ? $this->unchangedFieldValues[$this->langcodes[0]][$delta][$column] : $langcode . '-' . $delta . '-' . $column;
        $this->unchangedFieldValues[$langcode][$delta][$column] = $value;
      }
    }
  }
}