function UserCancelTest::testUserCancelUid1

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

Tests that user account for uid 1 cannot be cancelled.

This should never be possible, or the site owner would become unable to administer the site.

File

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

Class

UserCancelTest
Ensure that account cancellation methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserCancelUid1() : void {
    $user_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('user');
    \Drupal::service('module_installer')->install([
        'views',
    ]);
    // Try to cancel uid 1's account with a different user.
    $admin_user = $this->drupalCreateUser([
        'administer users',
    ]);
    $this->drupalLogin($admin_user);
    $edit = [
        'action' => 'user_cancel_user_action',
        'user_bulk_form[0]' => TRUE,
    ];
    $this->drupalGet('admin/people');
    $this->submitForm($edit, 'Apply to selected items');
    // Verify that uid 1's account was not cancelled.
    $user_storage->resetCache([
        1,
    ]);
    $user1 = $user_storage->load(1);
    $this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.