function ServicesResourceUsertests::testRegisterUser in Services 7.3
Same name and namespace in other branches
- 6.3 tests/functional/ServicesResourceUserTests.test \ServicesResourceUsertests::testRegisterUser()
Test register method.
Register user, load user, attempt to login.
File
- tests/
functional/ ServicesResourceUserTests.test, line 116 - Call the endpoint tests when no authentication is being used.
Class
- ServicesResourceUsertests
- Run test cases for the endpoint with no authentication turned on.
Code
function testRegisterUser() {
// Verify logged out state can create users
$this
->drupalLogout();
$username = $this
->randomName();
$password = user_password();
$user = array();
$user['name'] = $username;
$user['pass'] = $password;
$user['mail'] = $user['name'] . '@example.com';
$user['status'] = 1;
variable_set('user_email_verification', FALSE);
variable_set('user_register', TRUE);
$response = $this
->servicesPost($this->endpoint->path . '/user/register', $user);
$account = $response['body'];
$this
->assertTrue(!empty($account['uid']), 'User has been create successfully.', 'UserResource: Create');
// Load user.
$user_load = user_load($account['uid']);
$this
->assertTrue(!empty($user_load), 'Newly created user has been loaded successfully.', 'UserResource: Create');
$response = $this
->servicesPost($this->endpoint->path . '/user/login', array(
'username' => $username,
'password' => $password,
));
$response = $response['body'];
$proper_answer = isset($response->sessid) && isset($response->user) && $response->user->name == $username;
$this
->assertTrue($proper_answer, 'User successfully logged in.', 'UserResource: Login');
}