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

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
36 $edit = ['keys' => $keys]; 36 $edit = ['keys' => $keys];
37 $this->drupalPostForm('search/user', $edit, t('Search')); 37 $this->drupalPostForm('search/user', $edit, t('Search'));
38 $this->assertText('no results', 'Non-matching search gave appropriate message'); 38 $this->assertText('no results', 'Non-matching search gave appropriate message');
39 39
40 // Verify that a user with search permission can search for users by name. 40 // Verify that a user with search permission can search for users by name.
41 $keys = $user1->getUsername(); 41 $keys = $user1->getAccountName();
42 $edit = ['keys' => $keys]; 42 $edit = ['keys' => $keys];
43 $this->drupalPostForm('search/user', $edit, t('Search')); 43 $this->drupalPostForm('search/user', $edit, t('Search'));
44 $this->assertLink($keys, 0, 'Search by username worked for non-admin user'); 44 $this->assertLink($keys, 0, 'Search by username worked for non-admin user');
45 45
46 // Verify that searching by sub-string works too. 46 // Verify that searching by sub-string works too.
61 $this->drupalLogin($user2); 61 $this->drupalLogin($user2);
62 $keys = $user2->getEmail(); 62 $keys = $user2->getEmail();
63 $edit = ['keys' => $keys]; 63 $edit = ['keys' => $keys];
64 $this->drupalPostForm('search/user', $edit, t('Search')); 64 $this->drupalPostForm('search/user', $edit, t('Search'));
65 $this->assertText($keys, 'Search by email works for administrative user'); 65 $this->assertText($keys, 'Search by email works for administrative user');
66 $this->assertText($user2->getUsername(), 'Search by email resulted in username on page for administrative user'); 66 $this->assertText($user2->getAccountName(), 'Search by email resulted in username on page for administrative user');
67 67
68 // Verify that a substring works too for email. 68 // Verify that a substring works too for email.
69 $subkey = substr($keys, 1, 5); 69 $subkey = substr($keys, 1, 5);
70 $edit = ['keys' => $subkey]; 70 $edit = ['keys' => $subkey];
71 $this->drupalPostForm('search/user', $edit, t('Search')); 71 $this->drupalPostForm('search/user', $edit, t('Search'));
72 $this->assertText($keys, 'Search by email substring works for administrative user'); 72 $this->assertText($keys, 'Search by email substring works for administrative user');
73 $this->assertText($user2->getUsername(), 'Search by email substring resulted in username on page for administrative user'); 73 $this->assertText($user2->getAccountName(), 'Search by email substring resulted in username on page for administrative user');
74 74
75 // Verify that wildcard search works for email 75 // Verify that wildcard search works for email
76 $subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2); 76 $subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
77 $edit = ['keys' => $subkey]; 77 $edit = ['keys' => $subkey];
78 $this->drupalPostForm('search/user', $edit, t('Search')); 78 $this->drupalPostForm('search/user', $edit, t('Search'));
79 $this->assertText($user2->getUsername(), 'Search for email wildcard resulted in username on page for administrative user'); 79 $this->assertText($user2->getAccountName(), 'Search for email wildcard resulted in username on page for administrative user');
80 80
81 // Verify that if they search by user name, they see email address too. 81 // Verify that if they search by user name, they see email address too.
82 $keys = $user1->getUsername(); 82 $keys = $user1->getAccountName();
83 $edit = ['keys' => $keys]; 83 $edit = ['keys' => $keys];
84 $this->drupalPostForm('search/user', $edit, t('Search')); 84 $this->drupalPostForm('search/user', $edit, t('Search'));
85 $this->assertText($keys, 'Search by username works for admin user'); 85 $this->assertText($keys, 'Search by username works for admin user');
86 $this->assertText($user1->getEmail(), 'Search by username for admin shows email address too'); 86 $this->assertText($user1->getEmail(), 'Search by username for admin shows email address too');
87 87
90 $blocked_user->block(); 90 $blocked_user->block();
91 $blocked_user->save(); 91 $blocked_user->save();
92 92
93 // Verify that users with "administer users" permissions can see blocked 93 // Verify that users with "administer users" permissions can see blocked
94 // accounts in search results. 94 // accounts in search results.
95 $edit = ['keys' => $blocked_user->getUsername()]; 95 $edit = ['keys' => $blocked_user->getAccountName()];
96 $this->drupalPostForm('search/user', $edit, t('Search')); 96 $this->drupalPostForm('search/user', $edit, t('Search'));
97 $this->assertText($blocked_user->getUsername(), 'Blocked users are listed on the user search results for users with the "administer users" permission.'); 97 $this->assertText($blocked_user->getAccountName(), 'Blocked users are listed on the user search results for users with the "administer users" permission.');
98 98
99 // Verify that users without "administer users" permissions do not see 99 // Verify that users without "administer users" permissions do not see
100 // blocked accounts in search results. 100 // blocked accounts in search results.
101 $this->drupalLogin($user1); 101 $this->drupalLogin($user1);
102 $edit = ['keys' => $blocked_user->getUsername()]; 102 $edit = ['keys' => $blocked_user->getAccountName()];
103 $this->drupalPostForm('search/user', $edit, t('Search')); 103 $this->drupalPostForm('search/user', $edit, t('Search'));
104 $this->assertText(t('Your search yielded no results.'), 'Blocked users are hidden from the user search results.'); 104 $this->assertText(t('Your search yielded no results.'), 'Blocked users are hidden from the user search results.');
105 105
106 // Create a user without search permission, and one without user page view 106 // Create a user without search permission, and one without user page view
107 // permission. Verify that neither one can access the user search page. 107 // permission. Verify that neither one can access the user search page.