function ServicesResourceUsertests::testUpdateUserOwnUserRoles in Services 6.3
Same name and namespace in other branches
- 7.3 tests/functional/ServicesResourceUserTests.test \ServicesResourceUsertests::testUpdateUserOwnUserRoles()
Test update own roles method.
Check to see if a regular user can change their own role.
File
- tests/
functional/ ServicesResourceUserTests.test, line 220
Class
- ServicesResourceUsertests
- Run test cases for the endpoint with no authentication turned on.
Code
function testUpdateUserOwnUserRoles() {
// Create user with minimal permission
$account = $this
->drupalCreateUser();
$this
->drupalLogout();
// Login
$this
->drupalLogin($account);
// Not strictly necessary but illustrates the problem
$role_name = $this
->randomName();
$role_rid = $this
->drupalCreateRole(array(
'administer users',
), $role_name);
$user_load_before = user_load($account->uid);
// Update the roles of the user.
$updated_account = array(
'uid' => $account->uid,
'name' => $account->name,
'mail' => $account->mail,
'roles' => array(
$role_rid => $role_name,
),
);
$response = $this
->servicesPut($this->endpoint->path . '/user/' . $account->uid, $updated_account);
$user_load_after = user_load($account->uid, TRUE);
$this
->assertEqual($response['code'], 200, 'Update will should appear to succeed as the roles will be ignored', 'UserResource');
// The roles must remain unchanged
$this
->assertEqual($response['body']['roles'], $user_load_before->roles, 'Response shows roles unchanged', 'UserResource');
$this
->assertEqual($user_load_before->roles, $user_load_after->roles, 'User roles have not been changed', 'UserResource');
}