function ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation()
  3. 11.x 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.