Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
24605077
Commit
24605077
authored
Apr 24, 2014
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2183963
by jhodgdon: Add tests for User search.
parent
82f25bf1
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/user/lib/Drupal/user/Tests/UserSearchTest.php
+53
-5
53 additions, 5 deletions
core/modules/user/lib/Drupal/user/Tests/UserSearchTest.php
with
53 additions
and
5 deletions
core/modules/user/lib/Drupal/user/Tests/UserSearchTest.php
+
53
−
5
View file @
24605077
...
@@ -30,20 +30,57 @@ public static function getInfo() {
...
@@ -30,20 +30,57 @@ public static function getInfo() {
}
}
function
testUserSearch
()
{
function
testUserSearch
()
{
$user1
=
$this
->
drupalCreateUser
(
array
(
'access user profiles'
,
'search content'
,
'use advanced search'
));
// Verify that a user without 'administer users' permission cannot search
// for users by email address.
$user1
=
$this
->
drupalCreateUser
(
array
(
'access user profiles'
,
'search content'
));
$this
->
drupalLogin
(
$user1
);
$this
->
drupalLogin
(
$user1
);
$keys
=
$user1
->
getEmail
();
$keys
=
$user1
->
getEmail
();
$edit
=
array
(
'keys'
=>
$keys
);
$edit
=
array
(
'keys'
=>
$keys
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertNoText
(
$keys
);
$this
->
assertNoText
(
$keys
,
'Search by email did not work for non-admin user'
);
$this
->
drupalLogout
();
$this
->
assertText
(
'no results'
,
'Search by email gave no-match message'
);
// Verify that a non-matching query gives an appropriate message.
$keys
=
'nomatch'
;
$edit
=
array
(
'keys'
=>
$keys
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertText
(
'no results'
,
'Non-matching search gave appropriate message'
);
$user2
=
$this
->
drupalCreateUser
(
array
(
'administer users'
,
'access user profiles'
,
'search content'
,
'use advanced search'
));
// Verify that a user with search permission can search for users by name.
$keys
=
$user1
->
getUsername
();
$edit
=
array
(
'keys'
=>
$keys
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertLink
(
$keys
,
0
,
'Search by user name worked for non-admin user'
);
// Verify that searching by sub-string works too.
$subkey
=
substr
(
$keys
,
1
,
5
);
$edit
=
array
(
'keys'
=>
$subkey
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertLink
(
$keys
,
0
,
'Search by user name substring worked for non-admin user'
);
// Verify that a user with 'administer users' permission can search by
// email.
$user2
=
$this
->
drupalCreateUser
(
array
(
'administer users'
,
'access user profiles'
,
'search content'
));
$this
->
drupalLogin
(
$user2
);
$this
->
drupalLogin
(
$user2
);
$keys
=
$user2
->
getEmail
();
$keys
=
$user2
->
getEmail
();
$edit
=
array
(
'keys'
=>
$keys
);
$edit
=
array
(
'keys'
=>
$keys
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertText
(
$keys
);
$this
->
assertText
(
$keys
,
'Search by email works for administrative user'
);
$this
->
assertText
(
$user2
->
getUsername
(),
'Search by email resulted in user name on page for administrative user'
);
// Verify that a substring works too for email.
$subkey
=
substr
(
$keys
,
1
,
5
);
$edit
=
array
(
'keys'
=>
$subkey
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertText
(
$keys
,
'Search by email substring works for administrative user'
);
$this
->
assertText
(
$user2
->
getUsername
(),
'Search by email substring resulted in user name on page for administrative user'
);
// Verify that if they search by user name, they see email address too.
$keys
=
$user1
->
getUsername
();
$edit
=
array
(
'keys'
=>
$keys
);
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertText
(
$keys
,
'Search by user name works for admin user'
);
$this
->
assertText
(
$user1
->
getEmail
(),
'Search by user name for admin shows email address too'
);
// Create a blocked user.
// Create a blocked user.
$blocked_user
=
$this
->
drupalCreateUser
();
$blocked_user
=
$this
->
drupalCreateUser
();
...
@@ -63,6 +100,17 @@ function testUserSearch() {
...
@@ -63,6 +100,17 @@ function testUserSearch() {
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
drupalPostForm
(
'search/user'
,
$edit
,
t
(
'Search'
));
$this
->
assertNoText
(
$blocked_user
->
getUsername
(),
'Blocked users are hidden from the user search results.'
);
$this
->
assertNoText
(
$blocked_user
->
getUsername
(),
'Blocked users are hidden from the user search results.'
);
// Create a user without search permission, and one without user page view
// permission. Verify that neither one can access the user search page.
$user3
=
$this
->
drupalCreateUser
(
array
(
'search content'
));
$this
->
drupalLogin
(
$user3
);
$this
->
drupalGet
(
'search/user'
);
$this
->
assertResponse
(
'403'
,
'User without user profile access cannot search'
);
$user4
=
$this
->
drupalCreateUser
(
array
(
'access user profiles'
));
$this
->
drupalLogin
(
$user4
);
$this
->
drupalGet
(
'search/user'
);
$this
->
assertResponse
(
'403'
,
'User without search permission cannot search'
);
$this
->
drupalLogout
();
$this
->
drupalLogout
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment