function UserCancelTest::testUserCancelByAdmin in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/user/src/Tests/UserCancelTest.php \Drupal\user\Tests\UserCancelTest::testUserCancelByAdmin()
Create an administrative user and delete another user.
File
- core/
modules/ user/ src/ Tests/ UserCancelTest.php, line 450 - Contains \Drupal\user\Tests\UserCancelTest.
Class
- UserCancelTest
- Ensure that account cancellation methods work as expected.
Namespace
Drupal\user\TestsCode
function testUserCancelByAdmin() {
$this
->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
->id() . '/edit');
$this
->drupalPostForm(NULL, NULL, t('Cancel account'));
$this
->assertRaw(t('Are you sure you want to cancel the account %name?', array(
'%name' => $account
->getUsername(),
)), '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.', array(
'%name' => $account
->getUsername(),
)), 'User deleted.');
$this
->assertFalse(User::load($account
->id()), 'User is not found in the database.');
}