diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 618a091..0a147b5 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -92,11 +92,10 @@ function comment_schema() { 'description' => 'Primary Key: Unique comment ID.', ), 'uuid' => array( - 'description' => 'The universally unique identifier for the comment.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ), 'pid' => array( 'type' => 'int', @@ -188,9 +187,11 @@ function comment_schema() { 'comment_uid' => array('uid'), 'comment_nid_langcode' => array('nid', 'langcode'), 'comment_created' => array('created'), - 'uuid' => array('uuid'), ), 'primary key' => array('cid'), + 'unique keys' => array( + 'uuid' => array('uuid'), + ), 'foreign keys' => array( 'comment_node' => array( 'table' => 'node', @@ -296,14 +297,13 @@ function comment_update_8000() { */ function comment_update_8001() { $spec = array( - 'description' => 'The universally unique identifier for the comment.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ); $keys = array( - 'indexes' => array( + 'unique keys' => array( 'uuid' => array('uuid'), ), ); diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php new file mode 100644 index 0000000..c2f42c5 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php @@ -0,0 +1,65 @@ + '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); + } +} diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityUuidTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityUuidTest.php deleted file mode 100644 index f416e05..0000000 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityUuidTest.php +++ /dev/null @@ -1,74 +0,0 @@ - 'Entity UUID', - 'description' => 'Ensures that UUIDs are saved and loaded successfully on UUID-capable entities.', - 'group' => 'Entity API', - ); - } - - function setUp() { - parent::setUp('entity_test'); - } - - /** - * Test UUID generation on entities. - */ - function testEntityUuidCreation() { - $entity = entity_create('entity_test', array('name' => 'test')); - $entity->save(); - $this->assertTrue(strlen($entity->get('uuid')) == 36, 'Check that UUID length is 36'); - } - - /** - * Test saving and loading nodes with UUIDs. - */ - function testEntityUuidNode() { - // Create two nodes. - $node1 = $this->drupalCreateNode(); - $node2 = $this->drupalCreateNode(); - - // Make sure node saves are generating unique UUIDs. - $this->assertNotEqual($node1->get('uuid'), $node2->get('uuid'), 'Check that UUIDs are different'); - - // Check to make sure UUID did not get truncated when saving to {node}. - $this->assertTrue(strlen($node1->get('uuid')) == 36, 'Check that UUID length is 36'); - - // Check for UUID preservation on an entity resave. - $node1_reloaded = node_load($node1->nid); - node_save($node1_reloaded); - $this->assertEqual($node1->get('uuid'), $node1_reloaded->get('uuid'), 'Check that UUID did not change on node save.'); - } - - /** - * Test loading entities by UUIDs. - */ - function testEntityLoadByUuid() { - $entity1 = entity_create('entity_test', array('name' => 'test1')); - $entity1->save(); - - $entity_loaded = entity_load_by_uuid('entity_test', $entity1->get('uuid')); - - $this->assertEqual($entity1->id(), $entity_loaded->id(), 'Check that load by UUID loaded the same entity successfully.'); - - $entity1->save(); - - $this->assertEqual($entity1->get('uuid'), $entity_loaded->get('uuid'), 'Check that UUID did not change on entity save.'); - } - -} diff --git a/core/modules/entity/tests/modules/entity_test/entity_test.install b/core/modules/entity/tests/modules/entity_test/entity_test.install index fb0711d..1bef390 100644 --- a/core/modules/entity/tests/modules/entity_test/entity_test.install +++ b/core/modules/entity/tests/modules/entity_test/entity_test.install @@ -44,11 +44,10 @@ function entity_test_schema() { 'description' => 'Primary Key: Unique entity-test item ID.', ), 'uuid' => array( - 'description' => 'The universally unique identifier for the entity.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ), 'name' => array( 'description' => 'The name of the test entity.', @@ -74,12 +73,14 @@ function entity_test_schema() { ), 'indexes' => array( 'uid' => array('uid'), - 'uuid' => array('uuid'), ), 'foreign keys' => array( 'uid' => array('users' => 'uid'), ), 'primary key' => array('id'), + 'unique keys' => array( + 'uuid' => array('uuid'), + ), ); return $schema; } diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 9c0d4ca..054991d 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -18,6 +18,12 @@ function node_schema() { 'unsigned' => TRUE, 'not null' => TRUE, ), + 'uuid' => array( + 'description' => 'Unique Key: Universally unique identifier for this entity.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => FALSE, + ), // Defaults to NULL in order to avoid a brief period of potential // deadlocks on the index. 'vid' => array( @@ -27,13 +33,6 @@ function node_schema() { 'not null' => FALSE, 'default' => NULL, ), - 'uuid' => array( - 'description' => 'The universally unique identifier for the node.', - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - ), 'type' => array( 'description' => 'The {node_type}.type of this node.', 'type' => 'varchar', @@ -121,10 +120,10 @@ function node_schema() { 'uid' => array('uid'), 'tnid' => array('tnid'), 'translate' => array('translate'), - 'uuid' => array('uuid'), ), 'unique keys' => array( 'vid' => array('vid'), + 'uuid' => array('uuid'), ), 'foreign keys' => array( 'node_revision' => array( @@ -582,14 +581,13 @@ function node_update_8003() { */ function node_update_8004() { $spec = array( - 'description' => 'The universally unique identifier for the node.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ); $keys = array( - 'indexes' => array( + 'unique keys' => array( 'uuid' => array('uuid'), ), ); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 5706b54..08d97c8 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -867,11 +867,10 @@ function system_schema() { 'not null' => TRUE, ), 'uuid' => array( - 'description' => 'The universally unique identifier for the file.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ), 'uid' => array( 'description' => 'The {users}.uid of the user who is associated with the file.', @@ -936,9 +935,9 @@ function system_schema() { 'uid' => array('uid'), 'status' => array('status'), 'timestamp' => array('timestamp'), - 'uuid' => array('uuid'), ), 'unique keys' => array( + 'uuid' => array('uuid'), 'uri' => array('uri'), ), 'primary key' => array('fid'), @@ -1952,14 +1951,13 @@ function system_update_8011() { */ function system_update_8012() { $spec = array( - 'description' => 'The universally unique identifier for the file.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ); $keys = array( - 'indexes' => array( + 'unique keys' => array( 'uuid' => array('uuid'), ), ); diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index d296036..361dc6a 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -33,11 +33,10 @@ function taxonomy_schema() { 'description' => 'Primary Key: Unique term ID.', ), 'uuid' => array( - 'description' => 'The universally unique identifier for the term.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ), 'vid' => array( 'type' => 'int', @@ -82,6 +81,9 @@ function taxonomy_schema() { ), ), 'primary key' => array('tid'), + 'unique keys' => array( + 'uuid' => array('uuid'), + ), 'foreign keys' => array( 'vocabulary' => array( 'table' => 'taxonomy_vocabulary', @@ -92,7 +94,6 @@ function taxonomy_schema() { 'taxonomy_tree' => array('vid', 'weight', 'name'), 'vid_name' => array('vid', 'name'), 'name' => array('name'), - 'uuid' => array('uuid'), ), ); @@ -316,14 +317,13 @@ function taxonomy_update_8001() { */ function taxonomy_update_8002() { $spec = array( - 'description' => 'The universally unique identifier for the term.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ); $keys = array( - 'indexes' => array( + 'unique keys' => array( 'uuid' => array('uuid'), ), ); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 2de1b24..abb985b 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -133,11 +133,10 @@ function user_schema() { 'default' => 0, ), 'uuid' => array( - 'description' => 'The universally unique identifier for the user.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ), 'name' => array( 'type' => 'varchar', @@ -251,9 +250,9 @@ function user_schema() { 'created' => array('created'), 'mail' => array('mail'), 'picture' => array('picture'), - 'uuid' => array('uuid'), ), 'unique keys' => array( + 'uuid' => array('uuid'), 'name' => array('name'), ), 'primary key' => array('uid'), @@ -456,14 +455,13 @@ function user_update_8002() { */ function user_update_8003() { $spec = array( - 'description' => 'The universally unique identifier for the user.', + 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, - 'default' => '', + 'not null' => FALSE, ); $keys = array( - 'indexes' => array( + 'unique keys' => array( 'uuid' => array('uuid'), ), );