Skip to content

Commit

Permalink
Merge branch 'MDL-74435-master' of https://github.com/lameze/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Sep 8, 2022
2 parents d0f5778 + 9efb61d commit 0f9916e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions user/filters/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public function check_data($formdata) {
$fieldvalue = null;
if (isset($formdata->$field)) {
$fieldvalue = $formdata->$field;

// If we aren't doing a whitespace comparison, an exact match, trim will give us a better result set.
$trimmed = trim($fieldvalue);
if ($trimmed !== '' && $formdata->$operator != 2) {
$fieldvalue = $trimmed;
}
}
return array('operator' => (int)$formdata->$operator, 'value' => $fieldvalue);
}
Expand Down
37 changes: 37 additions & 0 deletions user/tests/behat/filter_trim.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@core @core_user
Feature: Trim entered user filters
As a system administrator
I need to be able to filter users ignoring whitespace
So that I can find users even when entered data has surrounding whitespace.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher@example.com |
| student1 | Student | 1 | student@example.com |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration

@javascript
Scenario: Filtering username - with case "contains"
When I set the field "id_realname_op" to "contains"
And I set the field "id_realname" to " Teacher "
And I press "Add filter"
# We should see the teacher user, with the trimmed string present.
Then I should see "User full name contains \"Teacher\""
And I should see "Teacher" in the "users" "table"
And I should not see "Student" in the "users" "table"

@javascript
Scenario: Filtering username - with case "contains" and a whitespace string
When I set the field "id_realname_op" to "contains"
And I set the field "id_realname" to " "
And I press "Add filter"
Then I should see "User full name contains \" \""

@javascript
Scenario: Filtering username - with case "is equal to"
When I set the field "id_realname_op" to "is equal to"
And I set the field "id_realname" to " Teacher"
And I press "Add filter"
Then I should see "User full name is equal to \" Teacher\""

0 comments on commit 0f9916e

Please sign in to comment.