function UserCancelTest::testUserCancelChangePermission

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

Test ability to change the permission for canceling users.

File

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

Class

UserCancelTest
Ensure that account cancellation methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserCancelChangePermission() {
    \Drupal::service('module_installer')->install([
        'user_form_test',
    ]);
    \Drupal::service('router.builder')->rebuild();
    $this->config('user.settings')
        ->set('cancel_method', 'user_cancel_reassign')
        ->save();
    // Create a regular user.
    $account = $this->drupalCreateUser([]);
    $admin_user = $this->drupalCreateUser([
        'cancel other accounts',
    ]);
    $this->drupalLogin($admin_user);
    // Delete regular user.
    $this->drupalPostForm('user_form_test_cancel/' . $account->id(), [], t('Cancel account'));
    // Confirm deletion.
    $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.