function UserRolesAssignmentTestCase::testAssignAndRemoveRole in Drupal 7
Tests that a user can be assigned a role and that the role can be removed again.
File
- modules/
user/ user.test, line 2651 - Tests for user.module.
Class
- UserRolesAssignmentTestCase
- Test role assignment.
Code
function testAssignAndRemoveRole() {
$rid = $this
->drupalCreateRole(array(
'administer content types',
));
$account = $this
->drupalCreateUser();
// Assign the role to the user.
$this
->drupalPost('user/' . $account->uid . '/edit', array(
"roles[{$rid}]" => $rid,
), t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $rid);
// Remove the role from the user.
$this
->drupalPost('user/' . $account->uid . '/edit', array(
"roles[{$rid}]" => FALSE,
), t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
$this
->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
}