You are here

public function ContentTranslationSyncUnitTest::testDifferingSyncedColumns 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::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");
      }
    }
  }
}