UserSubAdminTest.php in Drupal 9
File
core/modules/user/tests/src/Functional/UserSubAdminTest.php
View source
<?php
namespace Drupal\Tests\user\Functional;
use Drupal\Tests\BrowserTestBase;
class UserSubAdminTest extends BrowserTestBase {
protected static $modules = [
'user_access_test',
];
protected $defaultTheme = 'stark';
public function testSubAdmin() {
$user = $this
->drupalCreateUser([
'sub-admin',
]);
$this
->drupalLogin($user);
$this
->drupalGet('admin/people/create');
$this
->assertSession()
->fieldExists("edit-name");
$this
->assertSession()
->fieldExists("edit-notify");
$this
->assertSession()
->fieldNotExists("edit-status-0");
$this
->assertSession()
->fieldNotExists("edit-role");
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@example.com',
'pass[pass1]' => $pass = $this
->randomString(),
'pass[pass2]' => $pass,
'notify' => FALSE,
];
$this
->drupalGet('admin/people/create');
$this
->submitForm($edit, 'Create new account');
$this
->assertSession()
->pageTextContains('Created a new user account for ' . $edit['name'] . '. No email has been sent.');
$cancel_user = $this
->createUser();
$this
->drupalGet('user/' . $cancel_user
->id() . '/cancel');
$this
->assertSession()
->responseContains('Are you sure you want to cancel the account ' . $cancel_user
->getAccountName() . '?');
$this
->assertSession()
->responseContains('Disable the account and keep its content. This action cannot be undone.');
$this
->submitForm([], 'Cancel account');
$this
->assertSession()
->pageTextContains($cancel_user
->getAccountName() . ' has been disabled.');
$user
->addRole($this
->drupalCreateRole([
'select account cancellation method',
]));
$user
->save();
$cancel_user = $this
->createUser();
$this
->drupalGet('user/' . $cancel_user
->id() . '/cancel');
$this
->assertSession()
->pageTextContains('Select the method to cancel the account above.');
}
}
Classes
Name |
Description |
UserSubAdminTest |
Test 'sub-admin' account with permission to edit some users but without 'administer users' permission. |