1 user.test UserRolesAssignmentTestCase::testAssignAndRemoveRole()

Tests that a user can be assigned a role and that the role can be removed again.

File

core/modules/user/tests/user.test, line 2310
Tests for user.module.

Class

UserRolesAssignmentTestCase
Test role assignment.

Code

function testAssignAndRemoveRole() {
  $role_name = $this->backdropCreateRole(array('administer content types'));
  $account = $this->backdropCreateUser();

  // Assign the role to the user.
  $this->backdropPost('user/' . $account->uid . '/edit', array("roles[$role_name]" => $role_name), t('Save'));
  $this->assertText(t('The changes have been saved.'));
  $this->backdropGet('user/' . $account->uid . '/edit');
  $this->assertFieldChecked('edit-roles-' . strtolower($role_name), 'Role is assigned.');
  $this->userLoadAndCheckRoleAssigned($account, $role_name);

  // Remove the role from the user.
  $this->backdropPost('user/' . $account->uid . '/edit', array("roles[$role_name]" => FALSE), t('Save'));
  $this->assertText(t('The changes have been saved.'));
  $this->backdropGet('user/' . $account->uid . '/edit');
  $this->assertNoFieldChecked('edit-roles-' . strtolower($role_name), 'Role is removed from user.');
  $this->userLoadAndCheckRoleAssigned($account, $role_name, FALSE);
}