Skip to content
Snippets Groups Projects
Commit 2e6538c3 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1717678 by andypost, Berdir, attiks: Fixed Entity::createDuplicate()...

Issue #1717678 by andypost, Berdir, attiks: Fixed Entity::createDuplicate() does not account for uuid property.
parent 3fce22c5
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -302,7 +302,7 @@ public function delete() {
public function createDuplicate() {
$duplicate = clone $this;
$entity_info = $this->entityInfo();
$this->{$entity_info['entity keys']['id']} = NULL;
$duplicate->{$entity_info['entity keys']['id']} = NULL;
// Check if the entity type supports UUIDs and generate a new one if so.
if (!empty($entity_info['entity keys']['uuid'])) {
......
......@@ -398,7 +398,7 @@ public function __unset($name) {
public function createDuplicate() {
$duplicate = clone $this;
$entity_info = $this->entityInfo();
$this->{$entity_info['entity keys']['id']}->value = NULL;
$duplicate->{$entity_info['entity keys']['id']}->value = NULL;
// Check if the entity type supports UUIDs and generate a new one if so.
if (!empty($entity_info['entity keys']['uuid'])) {
......
......@@ -68,8 +68,22 @@ function testCRUD() {
// Creating a duplicate needs to result in a new UUID.
$entity_duplicate = $entity->createDuplicate();
$this->assertNotEqual($entity_duplicate->uuid(), $entity->uuid());
$this->assertNotNull($entity_duplicate->uuid());
foreach ($entity->getProperties() as $property => $value) {
switch($property) {
case 'uuid':
$this->assertNotNull($entity_duplicate->uuid());
$this->assertNotNull($entity->uuid());
$this->assertNotEqual($entity_duplicate->uuid(), $entity->uuid());
break;
case 'id':
$this->assertNull($entity_duplicate->id());
$this->assertNotNull($entity->id());
$this->assertNotEqual($entity_duplicate->id(), $entity->id());
break;
default:
$this->assertEqual($entity_duplicate->{$property}->value, $entity->{$property}->value);
}
}
$entity_duplicate->save();
$this->assertNotEqual($entity->id(), $entity_duplicate->id());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment