You are here

public function ContentTranslationSyncUnitTest::testDifferingSyncedColumns in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php \Drupal\content_translation\Tests\ContentTranslationSyncUnitTest::testDifferingSyncedColumns()

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

File

core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php, line 231
Contains \Drupal\content_translation\Tests\ContentTranslationSyncUnitTest.

Class

ContentTranslationSyncUnitTest
Tests the field synchronization logic.

Namespace

Drupal\content_translation\Tests

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);
  $result = TRUE;
  foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
    for ($delta = 0; $delta < $this->cardinality; $delta++) {
      foreach ($this->columns as $column) {
        $result = $result && $field_values[$langcode][$delta][$column] == $changed_items[$delta][$column];
      }
    }
  }
  $this
    ->assertTrue($result, 'Differing synced columns have been correctly synchronized.');
}