You are here

public function UUIDUserTestCase::testUserCrud in Universally Unique IDentifier 7

Test CRUD on users with UUID functions.

File

./uuid.test, line 241
Test suite for UUID module.

Class

UUIDUserTestCase
Tests the User implementation.

Code

public function testUserCrud() {
  $user = $this
    ->drupalCreateUser();
  $this
    ->assertUuid($user->uuid, 'User UUID was generated.');

  // Test updating user.
  $user_test = clone $user;
  user_save($user_test, array(
    'name' => 'new name',
  ));
  $user_test = user_load($user->uid, TRUE);
  $this
    ->assertEqual($user_test->uuid, $user->uuid, 'User UUID was intact after update.');

  // Test entity_uuid_load().
  $users = entity_uuid_load('user', array(
    $user->uuid,
  ), array(), TRUE);
  $user_test = reset($users);
  $this
    ->assertEqual($user_test->uid, $user->uid, 'User was correctly loaded with UUID.');

  // The following tests depends on the optional Entity API module.
  if (module_exists('entity')) {

    // Test entity_uuid_save() for users.
    $user_test = clone $user;
    $user_test->uid = rand();
    $user_test->name = 'new name';
    entity_uuid_save('user', $user_test);
    $user_test = user_load($user->uid, TRUE);
    $this
      ->assertEqual($user_test->name, 'new name', 'Saving user with UUID mapped to correct user.');
    $this
      ->assertEqual($user_test->uuid, $user->uuid, 'User UUID was intact after saving with UUID.');

    // Test entity_uuid_delete() for users.
    entity_uuid_delete('user', $user->uuid);
    $user_test = user_load($user->uid);
    $this
      ->assertFalse($user_test, 'Deleting user with UUID worked.');
  }
}