You are here

public function EntityRevisionTranslationTest::testNewRevisionAfterTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityRevisionTranslationTest.php \Drupal\system\Tests\Entity\EntityRevisionTranslationTest::testNewRevisionAfterTranslation()

Tests if the translation object has the right revision id after new revision.

File

core/modules/system/src/Tests/Entity/EntityRevisionTranslationTest.php, line 40
Contains \Drupal\system\Tests\Entity\EntityRevisionTranslationTest.

Class

EntityRevisionTranslationTest
Tests proper revision propagation of entities.

Namespace

Drupal\system\Tests\Entity

Code

public function testNewRevisionAfterTranslation() {
  $user = $this
    ->createUser();

  // Create a test entity.
  $entity = EntityTestMulRev::create([
    'name' => $this
      ->randomString(),
    'user_id' => $user
      ->id(),
    'language' => 'en',
  ]);
  $entity
    ->save();
  $old_rev_id = $entity
    ->getRevisionId();
  $translation = $entity
    ->addTranslation('de');
  $translation
    ->setNewRevision();
  $translation
    ->save();
  $this
    ->assertTrue($translation
    ->getRevisionId() > $old_rev_id, 'The saved translation in new revision has a newer revision id.');
  $this
    ->assertTrue($this
    ->reloadEntity($entity)
    ->getRevisionId() > $old_rev_id, 'The entity from the storage has a newer revision id.');
}