You are here

public function EntityRevisionTranslationTest::testSetNewRevision in Drupal 8

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

@covers \Drupal\Core\Entity\ContentEntityBase::setNewRevision

File

core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php, line 166

Class

EntityRevisionTranslationTest
Tests proper revision propagation of entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

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

  // All revisionable entity variations have to have the same results.
  foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) {
    $this
      ->installEntitySchema($entity_type);
    $storage = \Drupal::entityTypeManager()
      ->getStorage($entity_type);
    $entity = $storage
      ->create([
      'name' => 'foo',
      'user_id' => $user
        ->id(),
    ]);
    $entity
      ->save();
    $entity_id = $entity
      ->id();
    $entity_rev_id = $entity
      ->getRevisionId();
    $entity = $storage
      ->loadUnchanged($entity_id);
    $entity
      ->setNewRevision(TRUE);
    $entity
      ->setNewRevision(FALSE);
    $entity
      ->save();
    $entity = $storage
      ->loadUnchanged($entity_id);
    $this
      ->assertEquals($entity_rev_id, $entity
      ->getRevisionId(), 'A new entity revision was not created.');
  }
}