public function UserCancelTest::testUserCancelUid1 in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserCancelTest.php \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelUid1()
- 9 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 106
Class
- UserCancelTest
- Ensure that account cancellation methods work as expected.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUserCancelUid1() {
$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.');
}