comparison core/modules/user/tests/src/Functional/UserSubAdminTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php
2
3 namespace Drupal\Tests\user\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8 * Test 'sub-admin' account with permission to edit some users but without 'administer users' permission.
9 *
10 * @group user
11 */
12 class UserSubAdminTest extends BrowserTestBase {
13
14 /**
15 * {@inheritdoc}
16 */
17 public static $modules = ['user_access_test'];
18
19 /**
20 * Test create and cancel forms as 'sub-admin'.
21 */
22 public function testSubAdmin() {
23 $user = $this->drupalCreateUser(['sub-admin']);
24 $this->drupalLogin($user);
25
26 // Test that the create user page has admin fields.
27 $this->drupalGet('admin/people/create');
28 $this->assertSession()->fieldExists("edit-name");
29 $this->assertSession()->fieldExists("edit-notify");
30
31 // Not 'status' or 'roles' as they require extra permission.
32 $this->assertSession()->fieldNotExists("edit-status-0");
33 $this->assertSession()->fieldNotExists("edit-role");
34
35 // Test that create user gives an admin style message.
36 $edit = [
37 'name' => $this->randomMachineName(),
38 'mail' => $this->randomMachineName() . '@example.com',
39 'pass[pass1]' => $pass = $this->randomString(),
40 'pass[pass2]' => $pass,
41 'notify' => FALSE,
42 ];
43 $this->drupalPostForm('admin/people/create', $edit, 'Create new account');
44 $this->assertSession()->pageTextContains('Created a new user account for ' . $edit['name'] . '. No email has been sent.');
45
46 // Test that the cancel user page has admin fields.
47 $cancel_user = $this->createUser();
48 $this->drupalGet('user/' . $cancel_user->id() . '/cancel');
49 $this->assertSession()->responseContains('Are you sure you want to cancel the account ' . $cancel_user->getAccountName() . '?');
50 $this->assertSession()->responseContains('Disable the account and keep its content. This action cannot be undone.');
51
52 // Test that cancel confirmation gives an admin style message.
53 $this->drupalPostForm(NULL, NULL, t('Cancel account'));
54 $this->assertSession()->pageTextContains($cancel_user->getAccountName() . ' has been disabled.');
55
56 // Repeat with permission to select account cancellation method.
57 $user->addRole($this->drupalCreateRole(['select account cancellation method']));
58 $user->save();
59 $cancel_user = $this->createUser();
60 $this->drupalGet('user/' . $cancel_user->id() . '/cancel');
61 $this->assertSession()->pageTextContains('Select the method to cancel the account above.');
62 }
63
64 }