You are here

public function UserCancelTest::testUserCancelChangePermission in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/UserCancelTest.php \Drupal\user\Tests\UserCancelTest::testUserCancelChangePermission()

Test ability to change the permission for canceling users.

File

core/modules/user/src/Tests/UserCancelTest.php, line 77
Contains \Drupal\user\Tests\UserCancelTest.

Class

UserCancelTest
Ensure that account cancellation methods work as expected.

Namespace

Drupal\user\Tests

Code

public function testUserCancelChangePermission() {
  \Drupal::service('module_installer')
    ->install(array(
    '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(array());
  $admin_user = $this
    ->drupalCreateUser(array(
    'cancel other accounts',
  ));
  $this
    ->drupalLogin($admin_user);

  // Delete regular user.
  $this
    ->drupalPostForm('user_form_test_cancel/' . $account
    ->id(), array(), t('Cancel account'));

  // Confirm deletion.
  $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.');
}