public function UserCancelTest::testUserCancelByAdmin in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelByAdmin()
- 10 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 547
Class
- UserCancelTest
- Ensure that account cancellation methods work as expected.
Namespace
Drupal\Tests\user\FunctionalCode
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
->submitForm([], 'Cancel account');
$this
->assertSession()
->pageTextContains("Are you sure you want to cancel the account {$account->getAccountName()}?");
$this
->assertSession()
->pageTextContains('Select the method to cancel the account above.');
// Confirm deletion.
$this
->submitForm([], 'Cancel account');
$this
->assertSession()
->pageTextContains("{$account->getAccountName()} has been deleted.");
$this
->assertNull(User::load($account
->id()), 'User is not found in the database.');
}