function RoleAssignWebTestCase::testRoleAssignIssue1954332 in RoleAssign 7
Check for loss of unassignable/restricted roles.
File
- ./
roleassign.test, line 55 - Tests for the RoleAssign module.
Class
- RoleAssignWebTestCase
- Test case for RoleAssign module.
Code
function testRoleAssignIssue1954332() {
$assignableRid = $this
->drupalCreateRole(array(), 'AssignableRole');
$restrictedRid = $this
->drupalCreateRole(array(), 'RestrictedRole');
$deputy = $this
->drupalCreateUser(array(
'administer users',
'assign roles',
));
$account = $this
->drupalCreateUser(array());
// As user 1, assign the RestrictedRole.
$this
->drupalLogin($this->user1);
$this
->drupalGet('user/' . $account->uid . '/edit');
$this
->assertText('AssignableRole', 'AssignableRole text found.');
$this
->assertText('RestrictedRole', 'RestrictedRole text found.');
$this
->assertNoFieldChecked('edit-roles-' . $assignableRid, 'AssignableRole is not assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $assignableRid, FALSE);
$this
->assertNoFieldChecked('edit-roles-' . $restrictedRid, 'RestrictedRole is not assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $restrictedRid, FALSE);
$this
->drupalPost('user/' . $account->uid . '/edit', array(
"roles[{$restrictedRid}]" => $restrictedRid,
), t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertFieldChecked('edit-roles-' . $restrictedRid, 'RestrictedRole is now assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $restrictedRid);
// Allow assigning AssignableRole.
$this
->drupalPost('admin/people/permissions/roleassign', array(
"roleassign_roles[{$assignableRid}]" => $assignableRid,
), t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
$this
->assertFieldChecked('edit-roleassign-roles-' . $assignableRid, 'AssignableRole is now available for assignment.');
// Check that deputy can assign AssignableRole but not RestrictedRole.
$this
->drupalLogin($deputy);
$this
->drupalGet('user/' . $account->uid . '/edit');
$this
->assertText(t('Assignable roles'), 'The "Assignable roles" widget is present.');
$this
->assertField('edit-roleassign-roles-' . $assignableRid, 'AssignableRole checkbox exists.');
$this
->assertNoFieldChecked('edit-roleassign-roles-' . $assignableRid, 'AssignableRole is not assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $assignableRid, FALSE);
$this
->assertNoField('edit-roleassign-roles-' . $restrictedRid, 'There is no RestrictedRole checkbox.');
$this
->userLoadAndCheckRoleAssigned($account, $restrictedRid);
$this
->assertText(t('The user receives the combined permissions of all roles selected here and the following roles: @authuser, RestrictedRole.', array(
'@authuser' => t('authenticated user'),
)), 'Roles as expected, RestrictedRole is assigned.');
// As deputy, assign the AssignableRole.
$this
->drupalPost('user/' . $account->uid . '/edit', array(
"roleassign_roles[{$assignableRid}]" => $assignableRid,
), t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertFieldChecked('edit-roleassign-roles-' . $assignableRid, 'AssignableRole is now assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $assignableRid);
// Check that the RestrictedRole is still assigned.
$this
->assertText(t('The user receives the combined permissions of all roles selected here and the following roles: @authuser, RestrictedRole.', array(
'@authuser' => t('authenticated user'),
)), 'Roles as expected, RestrictedRole is still assigned.');
$this
->userLoadAndCheckRoleAssigned($account, $restrictedRid);
}