function ContentTranslationSyncUnitTest::testDifferingSyncedColumns

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationSyncUnitTest::testDifferingSyncedColumns()
  2. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationSyncUnitTest::testDifferingSyncedColumns()
  3. 11.x core/modules/content_translation/tests/src/Kernel/ContentTranslationSyncUnitTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationSyncUnitTest::testDifferingSyncedColumns()

Tests that one change in a synchronized column triggers a change in all columns.

File

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

Class

ContentTranslationSyncUnitTest
Tests the field synchronization logic.

Namespace

Drupal\Tests\content_translation\Kernel

Code

public function testDifferingSyncedColumns() {
    $sync_langcode = $this->langcodes[2];
    $unchanged_items = $this->unchangedFieldValues[$sync_langcode];
    $field_values = $this->unchangedFieldValues;
    for ($delta = 0; $delta < $this->cardinality; $delta++) {
        $index = $delta % 2 + 1;
        $field_values[$sync_langcode][$delta]['sync' . $index] .= '-updated';
    }
    $changed_items = $field_values[$sync_langcode];
    $this->synchronizer
        ->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
    foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
        for ($delta = 0; $delta < $this->cardinality; $delta++) {
            foreach ($this->columns as $column) {
                // If the column is synchronized, the value should have been synced,
                // for unsynchronized columns, the value must not change.
                $expected_value = in_array($column, $this->synchronized) ? $changed_items[$delta][$column] : $this->unchangedFieldValues[$langcode][$delta][$column];
                $this->assertEqual($field_values[$langcode][$delta][$column], $expected_value, "Differing Item {$delta} column {$column} for langcode {$langcode} synced correctly");
            }
        }
    }
}

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