From f2972e1dcbdb7e15618bcabb50b1dbc285d1f647 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Tue, 9 Jun 2020 14:15:24 +0800 Subject: [PATCH] MDL-68989 user: Apply none filterset join correctly on keyword filter Also improved behat coverage for filterset joins and keyword filtering. --- user/classes/table/participants_search.php | 6 ++ user/tests/behat/filter_participants.feature | 108 ++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/user/classes/table/participants_search.php b/user/classes/table/participants_search.php index 0d944832325..eb0a76c7956 100644 --- a/user/classes/table/participants_search.php +++ b/user/classes/table/participants_search.php @@ -874,6 +874,7 @@ class participants_search { $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. @@ -891,6 +892,11 @@ class participants_search { 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(); } diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 5e243dd879e..8e44061ba7b 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -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 @@ -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" @@ -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"