function UserSaveTestCase::testUserImport

7.x user.test UserSaveTestCase::testUserImport()

Test creating a user with arbitrary uid.

File

drupal-7.x/modules/user/user.test, line 1703
Tests for user.module.

Class

UserSaveTestCase
Tests saving a user account.

Code

function testUserImport() {
  // User ID must be a number that is not in the database.
  $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
  $test_uid = $max_uid + mt_rand(1000, 1000000);
  $test_name = $this->randomName();

  // Create the base user, based on drupalCreateUser().
  $user = array(
    'name' => $test_name,
    'uid' => $test_uid,
    'mail' => $test_name . '@example.com',
    'is_new' => TRUE,
    'pass' => user_password(),
    'status' => 1,
  );
  $user_by_return = user_save(drupal_anonymous_user(), $user);
  $this->assertTrue($user_by_return, 'Loading user by return of user_save().');

  // Test if created user exists.
  $user_by_uid = user_load($test_uid);
  $this->assertTrue($user_by_uid, 'Loading user by uid.');

  $user_by_name = user_load_by_name($test_name);
  $this->assertTrue($user_by_name, 'Loading user by name.');
}