You are here

public function UserProtectViewsBulkOperationsWebTest::testCancelProtection in User protect 7

Tests if users that may not be canceled, can not be canceled in bulk.

File

tests/UserProtectViewsBulkOperationsWebTest.test, line 134
Contains UserProtectViewsBulkOperationsWebTest.

Class

UserProtectViewsBulkOperationsWebTest
Tests if user bulk operations provided by Views Bulk Operations are protected.

Code

public function testCancelProtection() {

  // Create an user with cancel protection and an user without protection.
  $protected_account = $this
    ->createProtectedUser(array(
    'up_cancel' => 1,
  ));
  $account2 = $this
    ->drupalCreateUser(array());

  // Try to cancel 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_cancel_action',
  );
  $this
    ->drupalPost('test-user-bulk-form', $edit, t('Execute'));
  $edit = array(
    'user_cancel_method' => 'user_cancel_delete',
  );
  $this
    ->drupalPost(NULL, $edit, t('Next'));

  // Ensure the protected account still exists.
  $protected_account = user_load($protected_account->uid, TRUE);
  $this
    ->assertTrue(!empty($protected_account->uid), 'The protected user is not deleted.');

  // Ensure the other account no longer exists.
  $account2 = user_load($account2->uid, TRUE);
  $this
    ->assertFalse(!empty($account2->uid), 'The non-protected user is deleted.');
}