function UserCancelTest::testUserWithoutEmailCancelByAdmin

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

Tests deletion of a user account without an email address.

File

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

Class

UserCancelTest
Ensure that account cancellation methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserWithoutEmailCancelByAdmin() : void {
    $this->config('user.settings')
        ->set('cancel_method', 'user_cancel_reassign')
        ->save();
    // Create a regular user.
    $account = $this->drupalCreateUser([]);
    // This user has no email address.
    $account->mail = '';
    $account->save();
    // Create administrative user.
    $admin_user = $this->drupalCreateUser([
        'administer users',
    ]);
    $this->drupalLogin($admin_user);
    // Delete regular user without email address.
    $this->drupalGet('user/' . $account->id() . '/cancel');
    $this->assertSession()
        ->pageTextContains("Are you sure you want to cancel the account {$account->getAccountName()}?");
    $this->assertSession()
        ->pageTextContains('Cancellation method');
    // Confirm deletion.
    $this->submitForm([], 'Confirm');
    $this->assertSession()
        ->pageTextContains("Account {$account->getAccountName()} has been 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.