From f32f25b89d9131ce2403294d7d6fab235dc46213 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Thu, 4 Jun 2020 12:48:03 +0800 Subject: [PATCH 1/2] MDL-68745 lib: Updated table filters to support non-English characters Added support for non-English first/last name filtering. --- lib/table/classes/external/dynamic/get.php | 9 ++-- user/tests/behat/filter_participants.feature | 54 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/lib/table/classes/external/dynamic/get.php b/lib/table/classes/external/dynamic/get.php index f21e463a3d7..51ad2e4c7c1 100644 --- a/lib/table/classes/external/dynamic/get.php +++ b/lib/table/classes/external/dynamic/get.php @@ -98,13 +98,13 @@ class get extends external_api { ), 'jointype' => new external_value(PARAM_INT, 'Type of join to join all filters together', VALUE_REQUIRED), 'firstinitial' => new external_value( - PARAM_ALPHANUMEXT, + PARAM_RAW, 'The first initial to sort filter on', VALUE_REQUIRED, null ), 'lastinitial' => new external_value( - PARAM_ALPHANUMEXT, + PARAM_RAW, 'The last initial to sort filter on', VALUE_REQUIRED, null @@ -230,12 +230,13 @@ class get extends external_api { self::validate_context($instance->get_context()); $instance->set_sortdata($sortdata); + $alphabet = get_string('alphabet', 'langconfig'); - if ($firstinitial !== null) { + if ($firstinitial !== null && ($firstinitial === '' || strpos($alphabet, $firstinitial) !== false)) { $instance->set_first_initial($firstinitial); } - if ($lastinitial !== null) { + if ($lastinitial !== null && ($lastinitial === '' || strpos($alphabet, $lastinitial) !== false)) { $instance->set_last_initial($lastinitial); } diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index c716a18a47c..5219119efae 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -16,6 +16,7 @@ Feature: Course participants can be filtered | student2 | Student | 2 | student2@example.com | SID2 | GB | SCITY2 | 1 | | student3 | Student | 3 | student3@example.com | SID3 | AU | SCITY3 | 0 | | student4 | Student | 4 | student4@example.com | SID4 | AT | SCITY4 | 0 | + | student5 | Trendy | Learnson | trendy@learnson.com | SID5 | AU | SCITY5 | 0 | | teacher1 | Teacher | 1 | teacher1@example.com | TID1 | US | TCITY1 | 0 | And the following "course enrolments" exist: | user | course | role | status | timeend | @@ -26,6 +27,7 @@ Feature: Course participants can be filtered | student1 | C2 | student | 0 | | | student2 | C2 | student | 0 | | | student3 | C2 | student | 0 | | + | student5 | C2 | student | 0 | | | student1 | C3 | student | 0 | | | student2 | C3 | student | 0 | | | student3 | C3 | student | 0 | | @@ -279,3 +281,55 @@ Feature: Course participants can be filtered And I set the field "Filters" to "NOTHING" And I press key "13" in the field "Filters" And I should see "Nothing to display" + + @javascript + Scenario: Filter users by first initial + Given I log in as "teacher1" + And I am on "Course 2" course homepage + And I navigate to course participants + And I should see "Student 1" in the "participants" "table" + And I should see "Student 2" in the "participants" "table" + And I should see "Student 3" in the "participants" "table" + And I should see "Trendy Learnson" in the "participants" "table" + And I should see "Teacher 1" in the "participants" "table" + When I click on "T" "link" in the ".firstinitial" "css_element" + Then I should see "Trendy Learnson" in the "participants" "table" + And I should see "Teacher 1" 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 3" in the "participants" "table" + + @javascript + Scenario: Filter users by last initial + Given I log in as "teacher1" + And I am on "Course 2" course homepage + And I navigate to course participants + And I should see "Student 1" in the "participants" "table" + And I should see "Student 2" in the "participants" "table" + And I should see "Student 3" in the "participants" "table" + And I should see "Trendy Learnson" in the "participants" "table" + And I should see "Teacher 1" in the "participants" "table" + When I click on "L" "link" in the ".lastinitial" "css_element" + Then I should see "Trendy Learnson" 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 3" in the "participants" "table" + And I should not see "Teacher 1" in the "participants" "table" + + @javascript + Scenario: Filter users by first and last initials + Given I log in as "teacher1" + And I am on "Course 2" course homepage + And I navigate to course participants + And I should see "Student 1" in the "participants" "table" + And I should see "Student 2" in the "participants" "table" + And I should see "Student 3" in the "participants" "table" + And I should see "Trendy Learnson" in the "participants" "table" + And I should see "Teacher 1" in the "participants" "table" + When I click on "T" "link" in the ".firstinitial" "css_element" + And I click on "L" "link" in the ".lastinitial" "css_element" + Then I should see "Trendy Learnson" 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 3" in the "participants" "table" + And I should not see "Teacher 1" in the "participants" "table" From e1e5766940315f23d8bfafcff52dc8572f1b01ad Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Fri, 5 Jun 2020 17:50:54 +0800 Subject: [PATCH 2/2] MDL-68745 lib: Improved docblock descriptions for alpha PARAM types --- lib/moodlelib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index c718524e5af..1eb7f317a4d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -72,23 +72,23 @@ define('HOURMINS', 60); // or clean_param() should have a specified type of parameter. /** - * PARAM_ALPHA - contains only english ascii letters a-zA-Z. + * PARAM_ALPHA - contains only English ascii letters [a-zA-Z]. */ define('PARAM_ALPHA', 'alpha'); /** - * PARAM_ALPHAEXT the same contents as PARAM_ALPHA plus the chars in quotes: "_-" allowed + * PARAM_ALPHAEXT the same contents as PARAM_ALPHA (English ascii letters [a-zA-Z]) plus the chars in quotes: "_-" allowed * NOTE: originally this allowed "/" too, please use PARAM_SAFEPATH if "/" needed */ define('PARAM_ALPHAEXT', 'alphaext'); /** - * PARAM_ALPHANUM - expected numbers and letters only. + * PARAM_ALPHANUM - expected numbers 0-9 and English ascii letters [a-zA-Z] only. */ define('PARAM_ALPHANUM', 'alphanum'); /** - * PARAM_ALPHANUMEXT - expected numbers, letters only and _-. + * PARAM_ALPHANUMEXT - expected numbers 0-9, letters (English ascii letters [a-zA-Z]) and _- only. */ define('PARAM_ALPHANUMEXT', 'alphanumext');