Commit 12b49aa1 authored by Dries's avatar Dries
Browse files

- Patch #1637370 by danielnolde, sun, djdevin, Berdir: Added UUID support to core entity types.

parent 4c2e6b41
* @file
* Definition of Drupal\entity\Tests\EntityUUIDTest.
namespace Drupal\entity\Tests;
use Drupal\Component\Uuid\Uuid;
use Drupal\simpletest\WebTestBase;
* Tests creation, saving, and loading of entity UUIDs.
class EntityUUIDTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Entity UUIDs',
'description' => 'Tests creation, saving, and loading of entity UUIDs.',
'group' => 'Entity API',
function setUp() {
* Tests UUID generation in entity CRUD operations.
function testCRUD() {
// Verify that no UUID is auto-generated when passing one for creation.
$uuid_service = new Uuid();
$uuid = $uuid_service->generate();
$custom_entity = entity_create('entity_test', array(
'name' => $this->randomName(),
'uuid' => $uuid,
$this->assertIdentical($custom_entity->get('uuid'), $uuid);
// Save this entity, so we have more than one later.
// Verify that a new UUID is generated upon creating an entity.
$entity = entity_create('entity_test', array('name' => $this->randomName()));
$uuid = $entity->get('uuid');
// Verify that the new UUID is different.
$this->assertNotEqual($custom_entity->get('uuid'), $uuid);
// Verify that the UUID is retained upon saving.
$this->assertIdentical($entity->get('uuid'), $uuid);
// Verify that the UUID is retained upon loading.
$entity_loaded = entity_test_load($entity->id(), TRUE);
$this->assertIdentical($entity_loaded->get('uuid'), $uuid);
// Verify that entity_load_by_uuid() loads the same entity.
$entity_loaded_by_uuid = entity_load_by_uuid('entity_test', $uuid, TRUE);
$this->assertIdentical($entity_loaded_by_uuid->get('uuid'), $uuid);
$this->assertEqual($entity_loaded_by_uuid, $entity_loaded);
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