diff options
Diffstat (limited to 'modules/user/user.test')
-rw-r--r-- | modules/user/user.test | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/user/user.test b/modules/user/user.test index 055f7c261..0baa1cfb6 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -973,3 +973,46 @@ class UserBlocksUnitTests extends DrupalWebTestCase { $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(':uid' => $fields['uid'], ':sid' => $fields['sid'], ':timestamp' => $fields['timestamp']))->fetchField(), 1, t('Session record inserted.')); } } + +/** + * Test case to test user_save() behaviour. + */ +class UserSaveTestCase extends DrupalWebTestCase { + + function getInfo() { + return array( + 'name' => t('User save test'), + 'description' => t('Test user_save() for arbitrary new uid.'), + 'group' => t('User'), + ); + } + + /** + * Test creating a user with arbitrary uid. + */ + function testUserImport() { + // User ID must be a number that is not in the database. + $max_uid = db_result(db_query('SELECT MAX(uid) FROM {users}')); + $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('', $user); + $this->assertTrue($user_by_return, t('Loading user by return of user_save().')); + + // Test if created user exists. + $user_by_uid = user_load($test_uid); + $this->assertTrue($user_by_uid, t('Loading user by uid.')); + + $user_by_name = user_load_by_name($test_name); + $this->assertTrue($user_by_name, t('Loading user by name.')); + } +} |