function ContentEntityCloneTest::testNewRevisionOnCloneEntityTranslation

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testNewRevisionOnCloneEntityTranslation()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testNewRevisionOnCloneEntityTranslation()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testNewRevisionOnCloneEntityTranslation()

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

File

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

Class

ContentEntityCloneTest
Tests proper cloning of content entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testNewRevisionOnCloneEntityTranslation() {
    // Create a test entity.
    $entity = EntityTestMulRev::create([
        'name' => $this->randomString(),
        'language' => 'en',
    ]);
    $entity->save();
    $entity->addTranslation('de');
    $entity->save();
    // Reload the entity as ContentEntityBase::postCreate() forces the entity to
    // be a new revision.
    $entity = EntityTestMulRev::load($entity->id());
    $entity_translation = $entity->getTranslation('de');
    // The entity is not set to be a new revision.
    $this->assertFalse($entity_translation->isNewRevision());
    // The clone should not be set to be a new revision either.
    $clone = clone $entity_translation;
    $this->assertFalse($clone->isNewRevision());
    // After forcing the clone to be a new revision only it should be flagged
    // as a new revision, but the original entity should not.
    $clone->setNewRevision();
    $this->assertTrue($clone->isNewRevision());
    $this->assertFalse($entity_translation->isNewRevision());
}

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