function UserRolesAssignmentTest::testAssignAndRemoveRole in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/Tests/UserRolesAssignmentTest.php \Drupal\user\Tests\UserRolesAssignmentTest::testAssignAndRemoveRole()
Tests that a user can be assigned a role and that the role can be removed again.
File
- core/
modules/ user/ src/ Tests/ UserRolesAssignmentTest.php, line 29 - Contains \Drupal\user\Tests\UserRolesAssignmentTest.
Class
- UserRolesAssignmentTest
- Tests that users can be assigned and unassigned roles.
Namespace
Drupal\user\TestsCode
function testAssignAndRemoveRole() {
$rid = $this
->drupalCreateRole(array(
'administer users',
));
$account = $this
->drupalCreateUser();
// Assign the role to the user.
$this
->drupalPostForm('user/' . $account
->id() . '/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
->drupalPostForm('user/' . $account
->id() . '/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);
}