UserCancelTest.php 24.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Definition of Drupal\user\Tests\UserCancelTest.
 */

namespace Drupal\user\Tests;

10
use Drupal\comment\Tests\CommentTestTrait;
11
use Drupal\simpletest\WebTestBase;
12
use Drupal\comment\CommentInterface;
13
use Drupal\comment\Entity\Comment;
14
use Drupal\user\Entity\User;
15 16

/**
17 18 19
 * Ensure that account cancellation methods work as expected.
 *
 * @group user
20 21
 */
class UserCancelTest extends WebTestBase {
22

23 24
  use CommentTestTrait;

25 26 27 28 29
  /**
   * Modules to enable.
   *
   * @var array
   */
30
  public static $modules = array('node', 'comment');
31

32
  protected function setUp() {
33 34 35 36 37
    parent::setUp();

    $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
  }

38 39 40 41
  /**
   * Attempt to cancel account without permission.
   */
  function testUserCancelWithoutPermission() {
42
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
43
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
44 45 46 47 48

    // Create a user.
    $account = $this->drupalCreateUser(array());
    $this->drupalLogin($account);
    // Load real user object.
49
    $account = user_load($account->id(), TRUE);
50 51

    // Create a node.
52
    $node = $this->drupalCreateNode(array('uid' => $account->id()));
53 54

    // Attempt to cancel account.
55
    $this->drupalGet('user/' . $account->id() . '/edit');
56
    $this->assertNoRaw(t('Cancel account'), 'No cancel account button displayed.');
57 58

    // Attempt bogus account cancellation request confirmation.
59
    $timestamp = $account->getLastLoginTime();
60
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()));
61
    $this->assertResponse(403, 'Bogus cancelling request rejected.');
62
    $account = user_load($account->id());
63
    $this->assertTrue($account->isActive(), 'User account was not canceled.');
64 65

    // Confirm user's content has not been altered.
66 67
    $node_storage->resetCache(array($node->id()));
    $test_node = $node_storage->load($node->id());
68
    $this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
69 70
  }

71 72 73 74 75
  /**
   * Test ability to change the permission for canceling users.
   */
  public function testUserCancelChangePermission() {
    \Drupal::service('module_installer')->install(array('user_form_test'));
76
    \Drupal::service('router.builder')->rebuild();
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();

    // Create a regular user.
    $account = $this->drupalCreateUser(array());

    $admin_user = $this->drupalCreateUser(array('cancel other accounts'));
    $this->drupalLogin($admin_user);

    // Delete regular user.
    $this->drupalPostForm('user_form_test_cancel/' . $account->id(), array(), t('Cancel account'));

    // Confirm deletion.
    $this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
    $this->assertFalse(user_load($account->id()), 'User is not found in the database.');
  }

93 94 95 96 97 98 99
  /**
   * Tests that user account for uid 1 cannot be cancelled.
   *
   * This should never be possible, or the site owner would become unable to
   * administer the site.
   */
  function testUserCancelUid1() {
100
    \Drupal::service('module_installer')->install(array('views'));
101
    \Drupal::service('router.builder')->rebuild();
102 103 104 105
    // Update uid 1's name and password to we know it.
    $password = user_password();
    $account = array(
      'name' => 'user1',
106
      'pass' => $this->container->get('password')->hash(trim($password)),
107 108 109
    );
    // We cannot use $account->save() here, because this would result in the
    // password being hashed again.
110
    db_update('users_field_data')
111 112 113 114 115 116 117 118 119
      ->fields($account)
      ->condition('uid', 1)
      ->execute();

    // Reload and log in uid 1.
    $user1 = user_load(1, TRUE);
    $user1->pass_raw = $password;

    // Try to cancel uid 1's account with a different user.
120 121
    $admin_user = $this->drupalCreateUser(array('administer users'));
    $this->drupalLogin($admin_user);
122
    $edit = array(
123 124
      'action' => 'user_cancel_user_action',
      'user_bulk_form[0]' => TRUE,
125
    );
126
    $this->drupalPostForm('admin/people', $edit, t('Apply'));
127 128 129

    // Verify that uid 1's account was not cancelled.
    $user1 = user_load(1, TRUE);
130
    $this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
131 132 133 134 135 136
  }

  /**
   * Attempt invalid account cancellations.
   */
  function testUserCancelInvalid() {
137
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
138
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
139 140 141 142 143

    // Create a user.
    $account = $this->drupalCreateUser(array('cancel account'));
    $this->drupalLogin($account);
    // Load real user object.
144
    $account = user_load($account->id(), TRUE);
145 146

    // Create a node.
147
    $node = $this->drupalCreateNode(array('uid' => $account->id()));
148 149

    // Attempt to cancel account.
150
    $this->drupalPostForm('user/' . $account->id() . '/edit', NULL, t('Cancel account'));
151 152 153

    // Confirm account cancellation.
    $timestamp = time();
154
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
155
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
156 157 158

    // Attempt bogus account cancellation request confirmation.
    $bogus_timestamp = $timestamp + 60;
159
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->getPassword(), $bogus_timestamp, $account->getLastLoginTime(), $account->id()));
160
    $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Bogus cancelling request rejected.');
161
    $account = user_load($account->id());
162
    $this->assertTrue($account->isActive(), 'User account was not canceled.');
163 164 165

    // Attempt expired account cancellation request confirmation.
    $bogus_timestamp = $timestamp - 86400 - 60;
166
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->getPassword(), $bogus_timestamp, $account->getLastLoginTime(), $account->id()));
167
    $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Expired cancel account request rejected.');
168
    $account = user_load($account->id(), TRUE);
169
    $this->assertTrue($account->isActive(), 'User account was not canceled.');
170 171

    // Confirm user's content has not been altered.
172 173
    $node_storage->resetCache(array($node->id()));
    $test_node = $node_storage->load($node->id());
174
    $this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
175 176 177 178 179 180
  }

  /**
   * Disable account and keep all content.
   */
  function testUserBlock() {
181
    $this->config('user.settings')->set('cancel_method', 'user_cancel_block')->save();
182 183 184 185 186 187

    // Create a user.
    $web_user = $this->drupalCreateUser(array('cancel account'));
    $this->drupalLogin($web_user);

    // Load real user object.
188
    $account = user_load($web_user->id(), TRUE);
189 190

    // Attempt to cancel account.
191
    $this->drupalGet('user/' . $account->id() . '/edit');
192
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
193
    $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
194
    $this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your username.'), 'Informs that all content will be remain as is.');
195
    $this->assertNoText(t('Select the method to cancel the account above.'), 'Does not allow user to select account cancellation method.');
196 197 198 199

    // Confirm account cancellation.
    $timestamp = time();

200
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
201
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
202 203

    // Confirm account cancellation request.
204
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()));
205
    $account = user_load($account->id(), TRUE);
206
    $this->assertTrue($account->isBlocked(), 'User has been blocked.');
207

208
    // Confirm that the confirmation message made it through to the end user.
209
    $this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
210 211 212 213 214 215
  }

  /**
   * Disable account and unpublish all content.
   */
  function testUserBlockUnpublish() {
216
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
217
    $this->config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save();
218
    // Create comment field on page.
219
    $this->addDefaultCommentField('node', 'page');
220 221 222 223 224

    // Create a user.
    $account = $this->drupalCreateUser(array('cancel account'));
    $this->drupalLogin($account);
    // Load real user object.
225
    $account = user_load($account->id(), TRUE);
226 227

    // Create a node with two revisions.
228
    $node = $this->drupalCreateNode(array('uid' => $account->id()));
229 230 231 232
    $settings = get_object_vars($node);
    $settings['revision'] = 1;
    $node = $this->drupalCreateNode($settings);

233
    // Add a comment to the page.
234 235
    $comment_subject = $this->randomMachineName(8);
    $comment_body = $this->randomMachineName(8);
236 237 238 239 240 241 242 243 244 245 246
    $comment = entity_create('comment', array(
      'subject' => $comment_subject,
      'comment_body' => $comment_body,
      'entity_id' => $node->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'status' => CommentInterface::PUBLISHED,
      'uid' => $account->id(),
    ));
    $comment->save();

247
    // Attempt to cancel account.
248
    $this->drupalGet('user/' . $account->id() . '/edit');
249
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
250 251
    $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
    $this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), 'Informs that all content will be unpublished.');
252 253 254

    // Confirm account cancellation.
    $timestamp = time();
255
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
256
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
257 258

    // Confirm account cancellation request.
259
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()));
260
    $account = user_load($account->id(), TRUE);
261
    $this->assertTrue($account->isBlocked(), 'User has been blocked.');
262 263

    // Confirm user's content has been unpublished.
264 265
    $node_storage->resetCache(array($node->id()));
    $test_node = $node_storage->load($node->id());
266 267 268
    $this->assertFalse($test_node->isPublished(), 'Node of the user has been unpublished.');
    $test_node = node_revision_load($node->getRevisionId());
    $this->assertFalse($test_node->isPublished(), 'Node revision of the user has been unpublished.');
269

270 271 272 273 274
    $storage = \Drupal::entityManager()->getStorage('comment');
    $storage->resetCache(array($comment->id()));
    $comment = $storage->load($comment->id());
    $this->assertFalse($comment->isPublished(), 'Comment of the user has been unpublished.');

275
    // Confirm that the confirmation message made it through to the end user.
276
    $this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
277 278 279 280 281 282
  }

  /**
   * Delete account and anonymize all content.
   */
  function testUserAnonymize() {
283
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
284
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
285 286
    // Create comment field on page.
    $this->addDefaultCommentField('node', 'page');
287 288 289 290 291

    // Create a user.
    $account = $this->drupalCreateUser(array('cancel account'));
    $this->drupalLogin($account);
    // Load real user object.
292
    $account = user_load($account->id(), TRUE);
293 294

    // Create a simple node.
295
    $node = $this->drupalCreateNode(array('uid' => $account->id()));
296

297 298 299 300 301 302 303 304 305 306 307 308 309 310
    // Add a comment to the page.
    $comment_subject = $this->randomMachineName(8);
    $comment_body = $this->randomMachineName(8);
    $comment = entity_create('comment', array(
      'subject' => $comment_subject,
      'comment_body' => $comment_body,
      'entity_id' => $node->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'status' => CommentInterface::PUBLISHED,
      'uid' => $account->id(),
    ));
    $comment->save();

311 312
    // Create a node with two revisions, the initial one belonging to the
    // cancelling user.
313
    $revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
314
    $revision = $revision_node->getRevisionId();
315 316 317 318 319 320
    $settings = get_object_vars($revision_node);
    $settings['revision'] = 1;
    $settings['uid'] = 1; // Set new/current revision to someone else.
    $revision_node = $this->drupalCreateNode($settings);

    // Attempt to cancel account.
321
    $this->drupalGet('user/' . $account->id() . '/edit');
322
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
323
    $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
324
    $this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
325 326 327

    // Confirm account cancellation.
    $timestamp = time();
328
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
329
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
330 331

    // Confirm account cancellation request.
332
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()));
333
    $this->assertFalse(user_load($account->id(), TRUE), 'User is not found in the database.');
334 335

    // Confirm that user's content has been attributed to anonymous user.
336
    $anonymous_user = User::getAnonymousUser();
337 338
    $node_storage->resetCache(array($node->id()));
    $test_node = $node_storage->load($node->id());
339
    $this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.');
340
    $test_node = node_revision_load($revision, TRUE);
341
    $this->assertTrue(($test_node->getRevisionAuthor()->id() == 0 && $test_node->isPublished()), 'Node revision of the user has been attributed to anonymous user.');
342 343
    $node_storage->resetCache(array($revision_node->id()));
    $test_node = $node_storage->load($revision_node->id());
344
    $this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user.");
345

346 347 348 349 350 351
    $storage = \Drupal::entityManager()->getStorage('comment');
    $storage->resetCache(array($comment->id()));
    $test_comment = $storage->load($comment->id());
    $this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.');
    $this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getUsername(), 'Comment of the user has been attributed to anonymous user name.');

352
    // Confirm that the confirmation message made it through to the end user.
353
    $this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
354 355 356 357 358 359
  }

  /**
   * Delete account and remove all content.
   */
  function testUserDelete() {
360
    $node_storage = $this->container->get('entity.manager')->getStorage('node');
361
    $this->config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
362
    \Drupal::service('module_installer')->install(array('comment'));
363
    $this->resetAll();
364
    $this->addDefaultCommentField('node', 'page');
365 366 367 368 369

    // Create a user.
    $account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
    $this->drupalLogin($account);
    // Load real user object.
370
    $account = user_load($account->id(), TRUE);
371 372

    // Create a simple node.
373
    $node = $this->drupalCreateNode(array('uid' => $account->id()));
374 375 376

    // Create comment.
    $edit = array();
377 378
    $edit['subject[0][value]'] = $this->randomMachineName(8);
    $edit['comment_body[0][value]'] = $this->randomMachineName(16);
379

380
    $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Preview'));
381
    $this->drupalPostForm(NULL, array(), t('Save'));
382
    $this->assertText(t('Your comment has been posted.'));
383
    $comments = entity_load_multiple_by_properties('comment', array('subject' => $edit['subject[0][value]']));
384
    $comment = reset($comments);
385
    $this->assertTrue($comment->id(), 'Comment found.');
386 387 388

    // Create a node with two revisions, the initial one belonging to the
    // cancelling user.
389
    $revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
390
    $revision = $revision_node->getRevisionId();
391 392 393 394 395 396
    $settings = get_object_vars($revision_node);
    $settings['revision'] = 1;
    $settings['uid'] = 1; // Set new/current revision to someone else.
    $revision_node = $this->drupalCreateNode($settings);

    // Attempt to cancel account.
397
    $this->drupalGet('user/' . $account->id() . '/edit');
398
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
399 400
    $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
    $this->assertText(t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), 'Informs that all content will be deleted.');
401 402 403

    // Confirm account cancellation.
    $timestamp = time();
404
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
405
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
406 407

    // Confirm account cancellation request.
408
    $this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()));
409
    $this->assertFalse(user_load($account->id(), TRUE), 'User is not found in the database.');
410 411

    // Confirm that user's content has been deleted.
412 413
    $node_storage->resetCache(array($node->id()));
    $this->assertFalse($node_storage->load($node->id()), 'Node of the user has been deleted.');
414
    $this->assertFalse(node_revision_load($revision), 'Node revision of the user has been deleted.');
415 416
    $node_storage->resetCache(array($revision_node->id()));
    $this->assertTrue($node_storage->load($revision_node->id()), "Current revision of the user's node was not deleted.");
417 418
    \Drupal::entityManager()->getStorage('comment')->resetCache(array($comment->id()));
    $this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.');
419

420
    // Confirm that the confirmation message made it through to the end user.
421
    $this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
422 423 424 425 426 427
  }

  /**
   * Create an administrative user and delete another user.
   */
  function testUserCancelByAdmin() {
428
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
429 430 431 432 433 434 435 436 437

    // Create a regular user.
    $account = $this->drupalCreateUser(array());

    // Create administrative user.
    $admin_user = $this->drupalCreateUser(array('administer users'));
    $this->drupalLogin($admin_user);

    // Delete regular user.
438
    $this->drupalGet('user/' . $account->id() . '/edit');
439
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
440
    $this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
441
    $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
442 443

    // Confirm deletion.
444
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
445
    $this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
446
    $this->assertFalse(user_load($account->id()), 'User is not found in the database.');
447 448 449
  }

  /**
450
   * Tests deletion of a user account without an email address.
451 452
   */
  function testUserWithoutEmailCancelByAdmin() {
453
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
454 455 456

    // Create a regular user.
    $account = $this->drupalCreateUser(array());
457
    // This user has no email address.
458 459 460 461 462 463 464
    $account->mail = '';
    $account->save();

    // Create administrative user.
    $admin_user = $this->drupalCreateUser(array('administer users'));
    $this->drupalLogin($admin_user);

465
    // Delete regular user without email address.
466
    $this->drupalGet('user/' . $account->id() . '/edit');
467
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
468
    $this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
469
    $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
470 471

    // Confirm deletion.
472
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
473
    $this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
474
    $this->assertFalse(user_load($account->id()), 'User is not found in the database.');
475 476 477 478 479 480
  }

  /**
   * Create an administrative user and mass-delete other users.
   */
  function testMassUserCancelByAdmin() {
481
    \Drupal::service('module_installer')->install(array('views'));
482
    \Drupal::service('router.builder')->rebuild();
483
    $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
484
    // Enable account cancellation notification.
485
    $this->config('user.settings')->set('notify.status_canceled', TRUE)->save();
486 487 488 489 490 491 492 493 494

    // Create administrative user.
    $admin_user = $this->drupalCreateUser(array('administer users'));
    $this->drupalLogin($admin_user);

    // Create some users.
    $users = array();
    for ($i = 0; $i < 3; $i++) {
      $account = $this->drupalCreateUser(array());
495
      $users[$account->id()] = $account;
496 497 498 499
    }

    // Cancel user accounts, including own one.
    $edit = array();
500 501 502
    $edit['action'] = 'user_cancel_user_action';
    for ($i = 0; $i <= 4; $i++) {
      $edit['user_bulk_form[' . $i . ']'] = TRUE;
503
    }
504
    $this->drupalPostForm('admin/people', $edit, t('Apply'));
505 506
    $this->assertText(t('Are you sure you want to cancel these user accounts?'), 'Confirmation form to cancel accounts displayed.');
    $this->assertText(t('When cancelling these accounts'), 'Allows to select account cancellation method.');
507 508
    $this->assertText(t('Require email confirmation to cancel account'), 'Allows to send confirmation mail.');
    $this->assertText(t('Notify user when account is canceled'), 'Allows to send notification mail.');
509 510

    // Confirm deletion.
511
    $this->drupalPostForm(NULL, NULL, t('Cancel accounts'));
512 513
    $status = TRUE;
    foreach ($users as $account) {
514
      $status = $status && (strpos($this->content, t('%name has been deleted.', array('%name' => $account->getUsername()))) !== FALSE);
515
      $status = $status && !user_load($account->id(), TRUE);
516
    }
517
    $this->assertTrue($status, 'Users deleted and not found in the database.');
518 519

    // Ensure that admin account was not cancelled.
520
    $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
521
    $admin_user = user_load($admin_user->id());
522
    $this->assertTrue($admin_user->isActive(), 'Administrative user is found in the database and enabled.');
523 524 525

    // Verify that uid 1's account was not cancelled.
    $user1 = user_load(1, TRUE);
526
    $this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
527 528
  }
}