function UserCancelTest::testUserCancelByAdmin

Create an administrative user and delete another user.

File

drupal/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php, line 341
Definition of Drupal\user\Tests\UserCancelTest.

Class

UserCancelTest
Test cancelling a user.

Namespace

Drupal\user\Tests

Code

function testUserCancelByAdmin() {
  config('user.settings')
    ->set('cancel_method', 'user_cancel_reassign')
    ->save();

  // 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.
  $this
    ->drupalGet('user/' . $account->uid . '/edit');
  $this
    ->drupalPost(NULL, NULL, t('Cancel account'));
  $this
    ->assertRaw(t('Are you sure you want to cancel the account %name?', array(
    '%name' => $account->name,
  )), 'Confirmation form to cancel account displayed.');
  $this
    ->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');

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