Merge branch 'MDL-68745-master-2' of git://github.com/mickhawkins/moodle

This commit is contained in:
Sara Arjona 2020-06-05 21:30:07 +02:00
commit 6ddab9d6d3
3 changed files with 64 additions and 8 deletions

View File

@ -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');

View File

@ -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);
}

View File

@ -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@moodle.com | SID4 | AT | SCITY4 | 0 |
| student5 | Trendy | Learnson | trendy@learnson.com | SID5 | AU | SCITY5 | 0 |
| teacher1 | Teacher | 1 | teacher1@example.org | 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 | |
@ -610,3 +612,56 @@ Feature: Course participants can be filtered
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 "Teacher 1" in the "participants" "table"
@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"