function ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php \Drupal\KernelTests\Core\Entity\ContentEntityCloneTest::testEnforceIsNewOnClonedEntityTranslation()
- 10 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 79
Class
- ContentEntityCloneTest
- Tests proper cloning of content entities.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testEnforceIsNewOnClonedEntityTranslation() : void {
// 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.