Commit 2e6538c3 authored by webchick's avatar webchick

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
......@@ -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());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment