public function RoleDelegationBulkOperationsTest::testVboRoleDelegation in Role Delegation 8
Test if a user is able to edit the allowed roles in VBO.
File
- tests/
src/ Functional/ Views/ RoleDelegationBulkOperationsTest.php, line 29
Class
- RoleDelegationBulkOperationsTest
- Functional tests for assigning roles in vbo.
Namespace
Drupal\Tests\role_delegation\Functional\ViewsCode
public function testVboRoleDelegation() {
$rid1 = $this
->drupalCreateRole([]);
$rid2 = $this
->drupalCreateRole([]);
$rid3 = $this
->drupalCreateRole([]);
// User that can assign all roles.
$account = $this
->createUser([
'administer users',
'assign all roles',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/people');
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid1));
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid2));
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid3));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid1));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid2));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid3));
// User that can assign only role 1.
$account = $this
->createUser([
'administer users',
sprintf('assign %s role', $rid1),
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/people');
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid1));
$this
->assertSession()
->optionNotExists('action', sprintf('user_add_role_action.%s', $rid2));
$this
->assertSession()
->optionNotExists('action', sprintf('user_add_role_action.%s', $rid3));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid1));
$this
->assertSession()
->optionNotExists('action', sprintf('user_remove_role_action.%s', $rid2));
$this
->assertSession()
->optionNotExists('action', sprintf('user_remove_role_action.%s', $rid3));
// User that can assign role 2 and role 3.
$account = $this
->createUser([
'administer users',
sprintf('assign %s role', $rid2),
sprintf('assign %s role', $rid3),
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/people');
$this
->assertSession()
->optionNotExists('action', sprintf('user_add_role_action.%s', $rid1));
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid2));
$this
->assertSession()
->optionExists('action', sprintf('user_add_role_action.%s', $rid3));
$this
->assertSession()
->optionNotExists('action', sprintf('user_remove_role_action.%s', $rid1));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid2));
$this
->assertSession()
->optionExists('action', sprintf('user_remove_role_action.%s', $rid3));
}