comparison core/modules/user/tests/src/Functional/UserAdminTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
3 namespace Drupal\Tests\user\Functional; 3 namespace Drupal\Tests\user\Functional;
4 4
5 use Drupal\Core\Test\AssertMailTrait; 5 use Drupal\Core\Test\AssertMailTrait;
6 use Drupal\Tests\BrowserTestBase; 6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\user\RoleInterface; 7 use Drupal\user\RoleInterface;
8 use Drupal\user\UserInterface;
8 9
9 /** 10 /**
10 * Tests user administration page functionality. 11 * Tests user administration page functionality.
11 * 12 *
12 * @group user 13 * @group user
48 // by name. 49 // by name.
49 $admin_user->name = 'Admin user'; 50 $admin_user->name = 'Admin user';
50 $admin_user->save(); 51 $admin_user->save();
51 $this->drupalLogin($admin_user); 52 $this->drupalLogin($admin_user);
52 $this->drupalGet('admin/people'); 53 $this->drupalGet('admin/people');
53 $this->assertText($user_a->getUsername(), 'Found user A on admin users page'); 54 $this->assertText($user_a->getAccountName(), 'Found user A on admin users page');
54 $this->assertText($user_b->getUsername(), 'Found user B on admin users page'); 55 $this->assertText($user_b->getAccountName(), 'Found user B on admin users page');
55 $this->assertText($user_c->getUsername(), 'Found user C on admin users page'); 56 $this->assertText($user_c->getAccountName(), 'Found user C on admin users page');
56 $this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page'); 57 $this->assertText($admin_user->getAccountName(), 'Found Admin user on admin users page');
57 58
58 // Test for existence of edit link in table. 59 // Test for existence of edit link in table.
59 $link = $user_a->link(t('Edit'), 'edit-form', ['query' => ['destination' => $user_a->url('collection')]]); 60 $link = $user_a->toLink(t('Edit'), 'edit-form', ['query' => ['destination' => $user_a->toUrl('collection')->toString()]])->toString();
60 $this->assertRaw($link, 'Found user A edit link on admin users page'); 61 $this->assertRaw($link, 'Found user A edit link on admin users page');
61 62
62 // Test exposed filter elements. 63 // Test exposed filter elements.
63 foreach (['user', 'role', 'permission', 'status'] as $field) { 64 foreach (['user', 'role', 'permission', 'status'] as $field) {
64 $this->assertField("edit-$field", "$field exposed filter found."); 65 $this->assertField("edit-$field", "$field exposed filter found.");
66 // Make sure the reduce duplicates element from the ManyToOneHelper is not 67 // Make sure the reduce duplicates element from the ManyToOneHelper is not
67 // displayed. 68 // displayed.
68 $this->assertNoField('edit-reduce-duplicates', 'Reduce duplicates form element not found in exposed filters.'); 69 $this->assertNoField('edit-reduce-duplicates', 'Reduce duplicates form element not found in exposed filters.');
69 70
70 // Filter the users by name/email. 71 // Filter the users by name/email.
71 $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getUsername()]]); 72 $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getAccountName()]]);
72 $result = $this->xpath('//table/tbody/tr'); 73 $result = $this->xpath('//table/tbody/tr');
73 $this->assertEqual(1, count($result), 'Filter by username returned the right amount.'); 74 $this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
74 $this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); 75 $this->assertEqual($user_a->getAccountName(), $result[0]->find('xpath', '/td[2]/a')->getText(), 'Filter by username returned the right user.');
75 76
76 $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]); 77 $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]);
77 $result = $this->xpath('//table/tbody/tr'); 78 $result = $this->xpath('//table/tbody/tr');
78 $this->assertEqual(1, count($result), 'Filter by username returned the right amount.'); 79 $this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
79 $this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.'); 80 $this->assertEqual($user_a->getAccountName(), $result[0]->find('xpath', '/td[2]/a')->getText(), 'Filter by username returned the right user.');
80 81
81 // Filter the users by permission 'administer taxonomy'. 82 // Filter the users by permission 'administer taxonomy'.
82 $this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]); 83 $this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]);
83 84
84 // Check if the correct users show up. 85 // Check if the correct users show up.
85 $this->assertNoText($user_a->getUsername(), 'User A not on filtered by perm admin users page'); 86 $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by perm admin users page');
86 $this->assertText($user_b->getUsername(), 'Found user B on filtered by perm admin users page'); 87 $this->assertText($user_b->getAccountName(), 'Found user B on filtered by perm admin users page');
87 $this->assertText($user_c->getUsername(), 'Found user C on filtered by perm admin users page'); 88 $this->assertText($user_c->getAccountName(), 'Found user C on filtered by perm admin users page');
88 89
89 // Filter the users by role. Grab the system-generated role name for User C. 90 // Filter the users by role. Grab the system-generated role name for User C.
90 $roles = $user_c->getRoles(); 91 $roles = $user_c->getRoles();
91 unset($roles[array_search(RoleInterface::AUTHENTICATED_ID, $roles)]); 92 unset($roles[array_search(RoleInterface::AUTHENTICATED_ID, $roles)]);
92 $this->drupalGet('admin/people', ['query' => ['role' => reset($roles)]]); 93 $this->drupalGet('admin/people', ['query' => ['role' => reset($roles)]]);
93 94
94 // Check if the correct users show up when filtered by role. 95 // Check if the correct users show up when filtered by role.
95 $this->assertNoText($user_a->getUsername(), 'User A not on filtered by role on admin users page'); 96 $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by role on admin users page');
96 $this->assertNoText($user_b->getUsername(), 'User B not on filtered by role on admin users page'); 97 $this->assertNoText($user_b->getAccountName(), 'User B not on filtered by role on admin users page');
97 $this->assertText($user_c->getUsername(), 'User C on filtered by role on admin users page'); 98 $this->assertText($user_c->getAccountName(), 'User C on filtered by role on admin users page');
98 99
99 // Test blocking of a user. 100 // Test blocking of a user.
100 $account = $user_storage->load($user_c->id()); 101 $account = $user_storage->load($user_c->id());
101 $this->assertTrue($account->isActive(), 'User C not blocked'); 102 $this->assertTrue($account->isActive(), 'User C not blocked');
102 $edit = []; 103 $edit = [];
116 $account = $user_storage->load($user_c->id()); 117 $account = $user_storage->load($user_c->id());
117 $this->assertTrue($account->isBlocked(), 'User C blocked'); 118 $this->assertTrue($account->isBlocked(), 'User C blocked');
118 119
119 // Test filtering on admin page for blocked users 120 // Test filtering on admin page for blocked users
120 $this->drupalGet('admin/people', ['query' => ['status' => 2]]); 121 $this->drupalGet('admin/people', ['query' => ['status' => 2]]);
121 $this->assertNoText($user_a->getUsername(), 'User A not on filtered by status on admin users page'); 122 $this->assertNoText($user_a->getAccountName(), 'User A not on filtered by status on admin users page');
122 $this->assertNoText($user_b->getUsername(), 'User B not on filtered by status on admin users page'); 123 $this->assertNoText($user_b->getAccountName(), 'User B not on filtered by status on admin users page');
123 $this->assertText($user_c->getUsername(), 'User C on filtered by status on admin users page'); 124 $this->assertText($user_c->getAccountName(), 'User C on filtered by status on admin users page');
124 125
125 // Test unblocking of a user from /admin/people page and sending of activation mail 126 // Test unblocking of a user from /admin/people page and sending of activation mail
126 $editunblock = []; 127 $editunblock = [];
127 $editunblock['action'] = 'user_unblock_user_action'; 128 $editunblock['action'] = 'user_unblock_user_action';
128 $editunblock['user_bulk_form[4]'] = TRUE; 129 $editunblock['user_bulk_form[4]'] = TRUE;
165 // Test custom user registration approval email address(es). 166 // Test custom user registration approval email address(es).
166 $config = $this->config('user.settings'); 167 $config = $this->config('user.settings');
167 // Allow users to register with admin approval. 168 // Allow users to register with admin approval.
168 $config 169 $config
169 ->set('verify_mail', TRUE) 170 ->set('verify_mail', TRUE)
170 ->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) 171 ->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
171 ->save(); 172 ->save();
172 // Set the site and notification email addresses. 173 // Set the site and notification email addresses.
173 $system = $this->config('system.site'); 174 $system = $this->config('system.site');
174 $server_address = $this->randomMachineName() . '@example.com'; 175 $server_address = $this->randomMachineName() . '@example.com';
175 $notify_address = $this->randomMachineName() . '@example.com'; 176 $notify_address = $this->randomMachineName() . '@example.com';