public function RoleAssignPermissionTest::testRoleAssignAdminUser in RoleAssign 8
Tests that an admin user with "administer permissions" can add all roles.
File
- tests/
src/ Functional/ RoleAssignPermissionTest.php, line 139
Class
- RoleAssignPermissionTest
- Tests that users can (un)assign roles based on the RoleAssign settings.
Namespace
Drupal\Tests\roleassign\FunctionalCode
public function testRoleAssignAdminUser() {
// Login as admin user.
$this
->drupalLogin($this->adminUser);
// Load account edit page.
$this
->drupalGet('user/' . $this->testAccount
->id() . '/edit');
// Check that Drupal default roles checkboxes are shown.
$this
->assertText(t('Roles'));
$this
->assertNoFieldChecked('edit-roles-editor');
$this
->assertNoFieldChecked('edit-roles-webmaster');
$this
->assertNoFieldChecked('edit-roles-siteadmin');
// Assign the role "SiteAdmin" to the account.
$this
->drupalPostForm('user/' . $this->testAccount
->id() . '/edit', [
"roles[siteadmin]" => "siteadmin",
], t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertFieldChecked('edit-roles-siteadmin', 'Role siteadmin is assigned.');
$this
->userLoadAndCheckRoleAssigned($this->testAccount, 'siteadmin');
$this
->userLoadAndCheckRoleAssigned($this->testAccount, RoleInterface::AUTHENTICATED_ID);
// Now log in as restricted user again.
$this
->drupalLogin($this->restrictedUser);
// Assign the role "editor" to the account, and test that the assigned
// "siteadmin" role doesn't get lost.
$this
->drupalPostForm('user/' . $this->testAccount
->id() . '/edit', [
"roles[editor]" => "editor",
], t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertFieldChecked('edit-roles-editor', 'Role editor is assigned.');
$this
->assertNoField('edit-roles-siteadmin');
$this
->userLoadAndCheckRoleAssigned($this->testAccount, 'editor');
$this
->userLoadAndCheckRoleAssigned($this->testAccount, RoleInterface::AUTHENTICATED_ID);
$this
->userLoadAndCheckRoleAssigned($this->testAccount, 'siteadmin');
}