public function UserProtectViewsBulkOperationsWebTest::testEditProtection in User protect 7
Tests if users that may not be edited, can not be edited in bulk.
Furthermore, test if all protections are respected for each property that can be edited with the "Modify entity values" action.
File
- tests/
UserProtectViewsBulkOperationsWebTest.test, line 184 - Contains UserProtectViewsBulkOperationsWebTest.
Class
- UserProtectViewsBulkOperationsWebTest
- Tests if user bulk operations provided by Views Bulk Operations are protected.
Code
public function testEditProtection() {
// Turn off error reporting as VBO 7.x-3.2 contains a bug in the
// "Modify entity values" action causing a mb_strlen() warning to
// display. Without supressing that warning, this test would never pass.
// See also https://www.drupal.org/node/2305227.
error_reporting(0);
variable_set('error_reporting', 0);
// Create two protected accounts. One with that is protected for all
// edits, and one that has some properties protected.
$account1 = $this
->createProtectedUser(array(
'up_edit' => 1,
));
$account2 = $this
->createProtectedUser(array(
'up_name' => 1,
'up_mail' => 1,
'up_status' => 1,
'up_roles' => 1,
));
// Create a role. We try to add this role in the bulk operation later.
$rid = $this
->drupalCreateRole(array());
// Remember current values of accounts.
$account1_expected_name = $account1->name;
$account1_expected_mail = $account1->mail;
$account2_expected_name = $account2->name;
$account2_expected_mail = $account2->mail;
// Ensure that the accounts are not blocked.
$this
->assertEqual(1, $account1->status, 'Account 1 is not blocked.');
$this
->assertEqual(1, $account2->status, 'Account 2 is not blocked.');
// Try to modify values of these accounts.
$edit = array(
'views_bulk_operations[' . ($account1->uid - 1) . ']' => TRUE,
'views_bulk_operations[' . ($account2->uid - 1) . ']' => TRUE,
'operation' => 'action::views_bulk_operations_modify_action',
);
$this
->drupalPost('test-user-bulk-form', $edit, t('Execute'));
$edit = array(
'properties[show_value][name]' => 1,
'properties[show_value][mail]' => 1,
'properties[show_value][roles]' => 1,
'properties[show_value][status]' => 1,
'properties[name]' => self::randomName(),
'properties[mail]' => self::randomName() . '@example.com',
'properties[roles][' . $rid . ']' => $rid,
'properties[status]' => 0,
);
$this
->drupalPost(NULL, $edit, t('Next'));
// Reload accounts and assert that they did not change.
$account1 = user_load($account1->uid, TRUE);
$this
->assertEqual($account1_expected_name, $account1->name);
$this
->assertEqual($account1_expected_mail, $account1->mail);
$this
->assertFalse(isset($account1->roles[$rid]));
$this
->assertEqual(1, $account1->status, 'Account 1 is not blocked.');
$account2 = user_load($account2->uid, TRUE);
$this
->assertEqual($account2_expected_name, $account2->name);
$this
->assertEqual($account2_expected_mail, $account2->mail);
$this
->assertFalse(isset($account2->roles[$rid]));
$this
->assertEqual(1, $account2->status, 'Account 2 is not blocked.');
}