You are here

public function ContentEntityCloneTest::testDefaultRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testDefaultRevision()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testDefaultRevision()

Tests changing the default revision flag.

File

core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php, line 256

Class

ContentEntityCloneTest
Tests proper cloning of content entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testDefaultRevision() {

  // Create a test entity with a translation, which will internally trigger
  // entity cloning for the new translation and create references for some of
  // the entity properties.
  $entity = EntityTestMulRev::create([
    'name' => 'original',
    'language' => 'en',
  ]);
  $entity
    ->addTranslation('de');
  $entity
    ->save();

  // Assert that the entity is in the default revision.
  $this
    ->assertTrue($entity
    ->isDefaultRevision());

  // Clone the entity and modify its default revision flag.
  $clone = clone $entity;
  $clone
    ->isDefaultRevision(FALSE);

  // Assert that the clone is not in default revision, but the original entity
  // is still in the default revision.
  $this
    ->assertFalse($clone
    ->isDefaultRevision());
  $this
    ->assertTrue($entity
    ->isDefaultRevision());
}