function ContentTranslationSyncUnitTest::setUp

Same name in other branches
  1. 8.9.x core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationSyncUnitTest::setUp()
  2. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationSyncUnitTest::setUp()
  3. 11.x 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 62

Class

ContentTranslationSyncUnitTest
Tests the field synchronization logic.

Namespace

Drupal\Tests\content_translation\Kernel

Code

protected function setUp() : void {
    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;
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.