| 7 user.test | UserRolesAssignmentTestCase::testAssignAndRemoveRole() |
| 8 user.test | UserRolesAssignmentTestCase::testAssignAndRemoveRole() |
Tests that a user can be assigned a role and that the role can be removed again.
File
- modules/
user/ user.test, line 2072 - Tests for user.module.
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, t('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, t('Role is removed from user.'));
$this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
}
Login or register to post comments