function UserCancelTest::testUserCancelByAdmin

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelByAdmin()
  2. 10 core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelByAdmin()
  3. 11.x core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelByAdmin()

Create an administrative user and delete another user.

File

core/modules/user/tests/src/Functional/UserCancelTest.php, line 490

Class

UserCancelTest
Ensure that account cancellation methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserCancelByAdmin() {
    $this->config('user.settings')
        ->set('cancel_method', 'user_cancel_reassign')
        ->save();
    // Create a regular user.
    $account = $this->drupalCreateUser([]);
    // Create administrative user.
    $admin_user = $this->drupalCreateUser([
        'administer users',
    ]);
    $this->drupalLogin($admin_user);
    // Delete regular user.
    $this->drupalGet('user/' . $account->id() . '/edit');
    $this->drupalPostForm(NULL, NULL, t('Cancel account'));
    $this->assertRaw(t('Are you sure you want to cancel the account %name?', [
        '%name' => $account->getAccountName(),
    ]), '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->drupalPostForm(NULL, NULL, t('Cancel account'));
    $this->assertRaw(t('%name has been deleted.', [
        '%name' => $account->getAccountName(),
    ]), 'User deleted.');
    $this->assertNull(User::load($account->id()), 'User is not found in the database.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.