Skip to content
Snippets Groups Projects
Commit 12b49aa1 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

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

parent 4c2e6b41
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
<?php
/**
* @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() {
parent::setUp(array('entity_test'));
}
/**
* 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.
$custom_entity->save();
// Verify that a new UUID is generated upon creating an entity.
$entity = entity_create('entity_test', array('name' => $this->randomName()));
$uuid = $entity->get('uuid');
$this->assertTrue($uuid);
// Verify that the new UUID is different.
$this->assertNotEqual($custom_entity->get('uuid'), $uuid);
// Verify that the UUID is retained upon saving.
$entity->save();
$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);
}
}
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