You are here

function ServicesResourceUsertests::testUpdateUserRolesWithRegularAccount in Services 7.3

Same name and namespace in other branches
  1. 6.3 tests/functional/ServicesResourceUserTests.test \ServicesResourceUsertests::testUpdateUserRolesWithRegularAccount()

Test update method.

Check to see if a regular user can change another user's role.

File

tests/functional/ServicesResourceUserTests.test, line 215
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 testUpdateUserRolesWithRegularAccount() {

  // Create user.
  $account = $this
    ->drupalCreateUser();
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->regular_user);

  // Update the roles of the user.
  $updated_account = array(
    'mail' => $this
      ->randomName() . '@example.com',
    'pass' => $this
      ->randomString(),
    'roles' => array(
      3 => 'adminstrator',
    ),
  );
  $response = $this
    ->servicesPut($this->endpoint->path . '/user/' . $account->uid, $updated_account);
  $user_load = user_load($account->uid);

  //verify they are not allowed.
  $this
    ->assertEqual($response['body'], 'Access denied for user ' . $this->regular_user->name, 'Regular user CANNOT update roles', 'UserResource: Update');
}