Skip to content

Commit

Permalink
MDL-68989 user: Apply none filterset join correctly on keyword filter
Browse files Browse the repository at this point in the history
Also improved behat coverage for filterset joins and keyword filtering.
  • Loading branch information
mickhawkins committed Jun 9, 2020
1 parent bbb7dfc commit f2972e1
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
6 changes: 6 additions & 0 deletions user/classes/table/participants_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ protected function get_keywords_search_sql(): array {
$params = [];
$keywordsfilter = $this->filterset->get_filter('keywords');
$jointype = $keywordsfilter->get_join_type();
// None join types in both filter row and filterset require additional 'not null' handling for accurate keywords matches.
$notjoin = false;

// Determine how to match values in the query.
Expand All @@ -891,6 +892,11 @@ protected function get_keywords_search_sql(): array {
break;
}

// Handle filterset None join type.
if ($this->filterset->get_join_type() === $this->filterset::JOINTYPE_NONE) {
$notjoin = true;
}

if ($this->filterset->has_filter('keywords')) {
$keywords = $keywordsfilter->get_filter_values();
}
Expand Down
108 changes: 107 additions & 1 deletion user/tests/behat/filter_participants.feature
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Feature: Course participants can be filtered
And I should not see "Teacher 1" in the "participants" "table"

@javascript
Scenario: Multiple filters applied
Scenario: Multiple filters applied (All filterset match type)
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
Expand Down Expand Up @@ -312,6 +312,105 @@ Feature: Course participants can be filtered
And I click on "Apply filters" "button"
And I should see "Nothing to display"

@javascript
Scenario: Multiple filters applied (Any filterset match type)
Given I log in as "teacher1"
#Avoid 'Teacher' list item collisions with profile dropdown.
And I open my profile in edit mode
And I set the field "First name" to "Patricia"
And I press "Update profile"
And I am on "Course 1" course homepage
And I navigate to course participants
And I set the field "Match" in the "Filter 1" "fieldset" to "All"
And I set the field "type" in the "Filter 1" "fieldset" to "Roles"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 1" "fieldset"
And I click on "Teacher" "list_item"
And I click on "Add condition" "button"
# Set filterset to match any.
And I set the field "Match" to "Any"
And I set the field "Match" in the "Filter 2" "fieldset" to "Any"
And I set the field "type" in the "Filter 2" "fieldset" to "Status"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 2" "fieldset"
And I click on "Active" "list_item"
When I click on "Apply filters" "button"
Then I should see "Student 1" in the "participants" "table"
And I should see "Patricia 1" in the "participants" "table"
And I should see "Student 3" in the "participants" "table"
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I set the field "Match" in the "Filter 2" "fieldset" to "None"
And I click on "Apply filters" "button"
And I should see "Student 2" in the "participants" "table"
And I should see "Student 4" in the "participants" "table"
And I should see "Patricia 1" in the "participants" "table"
And I should not see "Student 1" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"
# Add a keyword filter.
And I click on "Add condition" "button"
And I set the field "Match" in the "Filter 3" "fieldset" to "Any"
And I set the field "type" in the "Filter 3" "fieldset" to "Keyword"
And I set the field "Type..." to "teacher1"
And I press key "13" in the field "Type..."
And I click on "Apply filters" "button"
And I should see "Student 2" in the "participants" "table"
And I should see "Student 4" in the "participants" "table"
And I should see "Patricia 1" in the "participants" "table"
And I should not see "Student 1" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"

@javascript
Scenario: Multiple filters applied (None filterset match type)
Given I log in as "teacher1"
#Avoid 'Teacher' list item collisions with profile dropdown.
And I open my profile in edit mode
And I set the field "First name" to "Patricia"
And I press "Update profile"
And I am on "Course 1" course homepage
And I navigate to course participants
And I set the field "Match" in the "Filter 1" "fieldset" to "All"
And I set the field "type" in the "Filter 1" "fieldset" to "Roles"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 1" "fieldset"
And I click on "Teacher" "list_item"
And I click on "Add condition" "button"
# Set filterset to match none.
And I set the field "Match" to "None"
And I set the field "Match" in the "Filter 2" "fieldset" to "Any"
And I set the field "type" in the "Filter 2" "fieldset" to "Status"
And I click on ".form-autocomplete-downarrow" "css_element" in the "Filter 2" "fieldset"
And I click on "Active" "list_item"
When I click on "Apply filters" "button"
Then I should see "Student 2" in the "participants" "table"
And I should see "Student 4" in the "participants" "table"
And I should not see "Student 1" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"
And I should not see "Patricia 1" in the "participants" "table"
And I set the field "Match" in the "Filter 2" "fieldset" to "None"
And I click on "Apply filters" "button"
And I should see "Student 1" in the "participants" "table"
And I should see "Student 3" in the "participants" "table"
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I should not see "Patricia 1" in the "participants" "table"
# Add a keyword filter.
And I click on "Add condition" "button"
And I set the field "Match" in the "Filter 3" "fieldset" to "Any"
And I set the field "type" in the "Filter 3" "fieldset" to "Keyword"
And I set the field "Type..." to "3@"
And I press key "13" in the field "Type..."
And I click on "Apply filters" "button"
And I should see "Student 1" in the "participants" "table"
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I should not see "Patricia 1" in the "participants" "table"
And I set the field "Match" in the "Filter 3" "fieldset" to "None"
And I click on "Apply filters" "button"
And I should see "Student 3" in the "participants" "table"
And I should not see "Student 1" in the "participants" "table"
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I should not see "Patricia 1" in the "participants" "table"

@javascript
Scenario: Filter match by one or more keywords and modified match types
Given I log in as "teacher1"
Expand All @@ -327,6 +426,13 @@ Feature: Course participants can be filtered
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I set the field "Match" in the "Filter 1" "fieldset" to "None"
And I click on "Apply filters" "button"
And I should see "Student 2" in the "participants" "table"
And I should see "Student 3" in the "participants" "table"
And I should see "Student 4" in the "participants" "table"
And I should not see "Student 1" in the "participants" "table"
And I should not see "Teacher 1" in the "participants" "table"
And I set the field "Match" in the "Filter 1" "fieldset" to "All"
And I click on "Apply filters" "button"
And I should see "Student 1" in the "participants" "table"
Expand Down

0 comments on commit f2972e1

Please sign in to comment.