protected function UserProtectViewsBulkOperationsWebTest::testRolesProtection in User protect 7
Tests if roles of users that are role protected can not be changed in bulk.
File
- tests/
UserProtectViewsBulkOperationsWebTest.test, line 82 - Contains UserProtectViewsBulkOperationsWebTest.
Class
- UserProtectViewsBulkOperationsWebTest
- Tests if user bulk operations provided by Views Bulk Operations are protected.
Code
protected function testRolesProtection() {
// Create an user with role protection and an user without protection.
$protected_account = $this
->createProtectedUser(array(
'up_roles' => 1,
));
$account2 = $this
->drupalCreateUser(array());
// Add a role to the accounts. We try to remove this role in the bulk
// operation later.
$rid1 = $this
->drupalCreateRole(array());
$protected_account->roles[$rid1] = $rid1;
user_save($protected_account);
$account2->roles[$rid1] = $rid1;
user_save($account2);
// Add another role. We try to add this role in the bulk operation later.
$rid2 = $this
->drupalCreateRole(array());
// Re-load the accounts and check their roles.
// Assert the protected account's roles.
$protected_account = user_load($protected_account->uid, TRUE);
$this
->assertTrue(isset($protected_account->roles[$rid1]));
$this
->assertFalse(isset($protected_account->roles[$rid2]));
// Assert the other account's roles.
$account2 = user_load($account2->uid, TRUE);
$this
->assertTrue(isset($account2->roles[$rid1]));
$this
->assertFalse(isset($account2->roles[$rid2]));
// Try to change the roles of the accounts.
$edit = array(
'views_bulk_operations[' . ($protected_account->uid - 1) . ']' => TRUE,
'views_bulk_operations[' . ($account2->uid - 1) . ']' => TRUE,
'operation' => 'action::views_bulk_operations_user_roles_action',
);
$this
->drupalPost('test-user-bulk-form', $edit, t('Execute'));
$edit = array(
'add_roles[]' => array(
$rid2,
),
'remove_roles[]' => array(
$rid1,
),
);
$this
->drupalPost(NULL, $edit, t('Next'));
// Re-load the protected account and assert the roles it has are still the same.
$protected_account = user_load($protected_account->uid, TRUE);
$this
->assertTrue(isset($protected_account->roles[$rid1]));
$this
->assertFalse(isset($protected_account->roles[$rid2]));
// Re-load the other account and assert the roles are changed.
$account2 = user_load($account2->uid, TRUE);
$this
->assertFalse(isset($account2->roles[$rid1]));
$this
->assertTrue(isset($account2->roles[$rid2]));
}