You are here

public function ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation in Drupal 9

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

Tests that the flag for enforcing a new entity is not shared.

File

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

Class

ContentEntityCloneTest
Tests proper cloning of content entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEnforceIsNewOnClonedEntityTranslation() {

  // Create a test entity.
  $entity = EntityTestMul::create([
    'name' => $this
      ->randomString(),
    'language' => 'en',
  ]);
  $entity
    ->save();
  $entity_translation = $entity
    ->addTranslation('de');
  $entity
    ->save();

  // The entity is not new anymore.
  $this
    ->assertFalse($entity_translation
    ->isNew());

  // The clone should not be new either.
  $clone = clone $entity_translation;
  $this
    ->assertFalse($clone
    ->isNew());

  // After forcing the clone to be new only it should be flagged as new, but
  // the original entity should not.
  $clone
    ->enforceIsNew();
  $this
    ->assertTrue($clone
    ->isNew());
  $this
    ->assertFalse($entity_translation
    ->isNew());
}