You are here

public function EntityDecoupledTranslationRevisionsTest::testMultipleTranslationChanges in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityDecoupledTranslationRevisionsTest::testMultipleTranslationChanges()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityDecoupledTranslationRevisionsTest::testMultipleTranslationChanges()

Checks that changes to multiple translations are handled correctly.

@covers ::createRevision @covers \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraintValidator::validate

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php, line 502

Class

EntityDecoupledTranslationRevisionsTest
Test decoupled translation revisions.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testMultipleTranslationChanges() {

  // Configure the untranslatable fields edit mode.
  $this->state
    ->set('entity_test.untranslatable_fields.default_translation_affected', TRUE);
  $this->bundleInfo
    ->clearCachedBundles();
  $entity = EntityTestMulRev::create();
  $entity
    ->get('name')->value = 'Test 1.1 EN';
  $entity
    ->get('non_mul_field')->value = 'Test 1.1';
  $this->storage
    ->save($entity);

  /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
  $revision = $this->storage
    ->createRevision($entity
    ->addTranslation('it'));
  $revision
    ->get('name')->value = 'Test 1.2 IT';
  $this->storage
    ->save($revision);
  $revision = $this->storage
    ->createRevision($revision
    ->getTranslation('en'), FALSE);
  $revision
    ->get('non_mul_field')->value = 'Test 1.3';
  $revision
    ->getTranslation('it')
    ->get('name')->value = 'Test 1.3 IT';
  $violations = $revision
    ->validate();
  $this
    ->assertCount(1, $violations);
  $this
    ->assertEquals('Non-translatable fields can only be changed when updating the original language.', $violations[0]
    ->getMessage());
}