From b621be27c7adc31e5ddee2068037a6697ef68428 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 7 Jul 2023 10:40:16 +0800 Subject: [PATCH 1/4] MDL-78673 behat: Allow plugins to define their expansion of > --- lib/tests/behat/behat_navigation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 46c07dcd912..9c37b2f8088 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -620,8 +620,8 @@ class behat_navigation extends behat_base { $dividercount = substr_count($page, ' > '); if ($dividercount === 0) { return ['core', $page]; - } else if ($dividercount === 1) { - list($component, $name) = explode(' > ', $page); + } else if ($dividercount >= 1) { + [$component, $name] = explode(' > ', $page, 2); if ($component === 'core') { throw new coding_exception('Do not specify the component "core > ..." for core pages.'); } From 7fe6a2d902ba72a7ef480d91c4f9ddcb3156a97f Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 7 Jul 2023 10:40:54 +0800 Subject: [PATCH 2/4] MDL-78673 grade: Address random failure due to toast --- grade/tests/behat/behat_grades.php | 81 +++++++++++++++++++++++++ grade/tests/behat/grade_average.feature | 8 +-- 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 grade/tests/behat/behat_grades.php diff --git a/grade/tests/behat/behat_grades.php b/grade/tests/behat/behat_grades.php new file mode 100644 index 00000000000..68ce6ff6ab3 --- /dev/null +++ b/grade/tests/behat/behat_grades.php @@ -0,0 +1,81 @@ +. + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); + +/** + * Behat grade related steps definitions. + * + * @package core_grades + * @copyright 2022 Mathew May + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_grades extends behat_base { + + /** + * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'. + * + * Recognised page names are: + * | pagetype | name meaning | description | + * | [report] view | Course name | The view page for the specified course and report | + * + * @param string $type identifies which type of page this is - for example "Grader > View" + * @param string $identifier identifies the particular page - for example "Course name" + * @return moodle_url the corresponding URL. + */ + protected function resolve_page_instance_url(string $type, string $identifier): moodle_url { + $type = strtolower($type); + if (strpos($type, '>') !== false) { + [$pluginname, $type] = explode('>', $type); + $pluginname = strtolower(trim($pluginname)); + + // Fetch the list of plugins. + $plugins = \core_component::get_plugin_list('gradereport'); + + if (array_key_exists($pluginname, $plugins)) { + $plugin = $pluginname; + } else { + $plugins = array_combine( + array_keys($plugins), + array_keys($plugins), + ); + + // This plugin is not in the list of plugins. Check the pluginname string. + $names = array_map(fn($name) => strtolower(get_string('pluginname', "gradereport_{$name}")), $plugins); + $result = array_search($pluginname, $names); + if ($result === false) { + throw new \coding_exception("Unknown plugin '{$pluginname}'"); + } + $plugin = $result; + } + } + $type = trim($type); + + switch ($type) { + case 'view': + return new moodle_url( + "/grade/report/{$plugin}/index.php", + ['id' => $this->get_course_id($identifier)] + ); + default: + throw new \coding_exception( + "Unknown page type '$type' for page identifier '$identifier'" + ); + } + } +} diff --git a/grade/tests/behat/grade_average.feature b/grade/tests/behat/grade_average.feature index 53f04f129cd..22699dda2e0 100644 --- a/grade/tests/behat/grade_average.feature +++ b/grade/tests/behat/grade_average.feature @@ -50,15 +50,11 @@ Feature: Average grades are displayed in the gradebook Scenario: Grade a grade item and ensure the results display correctly in the gradebook # Check the admin grade table - And I navigate to "View > Grader report" in the course gradebook + Given I am on the "Course 1" "grades > Grader report > View" page logged in as "admin" Then I should see "50.00" in the ".avg.r0.lastrow .c1" "css_element" Then I should see "50.00" in the ".avg.r0.lastrow .c2" "css_element" - And I log out # Check the user grade table - And I log in as "student1" - And I am on "Course 1" course homepage - And I navigate to "User report" in the course gradebook + When I am on the "Course 1" "grades > user > View" page logged in as "student1" Then I should see "50.00" in the ".level2.column-grade" "css_element" Then I should see "50.00" in the ".level2.column-average" "css_element" - And I log out From 64e4988bd66757f745b81f0c4d626e4952016999 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 7 Jul 2023 10:51:51 +0800 Subject: [PATCH 3/4] MDL-78673 grade: Switch to behat navigation steps --- grade/tests/behat/behat_grades.php | 12 ++++++++ grade/tests/behat/grade_average.feature | 39 +++++++++++++------------ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/grade/tests/behat/behat_grades.php b/grade/tests/behat/behat_grades.php index 68ce6ff6ab3..16212fed070 100644 --- a/grade/tests/behat/behat_grades.php +++ b/grade/tests/behat/behat_grades.php @@ -33,6 +33,8 @@ class behat_grades extends behat_base { * Recognised page names are: * | pagetype | name meaning | description | * | [report] view | Course name | The view page for the specified course and report | + * | gradebook setup | Course name | The gradebook setup page for the specified course | + * | course grade settings | Course name | The grade settings page | * * @param string $type identifies which type of page this is - for example "Grader > View" * @param string $identifier identifies the particular page - for example "Course name" @@ -72,6 +74,16 @@ class behat_grades extends behat_base { "/grade/report/{$plugin}/index.php", ['id' => $this->get_course_id($identifier)] ); + case 'gradebook setup': + return new moodle_url( + "/grade/edit/tree/index.php", + ['id' => $this->get_course_id($identifier)] + ); + case 'course grade settings': + return new moodle_url( + "/grade/edit/settings/index.php", + ['id' => $this->get_course_id($identifier)] + ); default: throw new \coding_exception( "Unknown page type '$type' for page identifier '$identifier'" diff --git a/grade/tests/behat/grade_average.feature b/grade/tests/behat/grade_average.feature index 22699dda2e0..d6497a65f98 100644 --- a/grade/tests/behat/grade_average.feature +++ b/grade/tests/behat/grade_average.feature @@ -1,46 +1,47 @@ @core @core_grades Feature: Average grades are displayed in the gradebook - In order to check the expected results are displayed - As an admin - I need to assign grades and check that they display correctly in the gradebook. + In order to check the expected results are displayed + As an admin + I need to assign grades and check that they display correctly in the gradebook. Background: Given the following "courses" exist: | fullname | shortname | format | - | Course 1 | C1 | topics | + | Course 1 | C1 | topics | And the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - | student2 | Student | 2 | student2@example.com | - | student3 | Student | 3 | student3@example.com | + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - | student2 | C1 | student | - | student3 | C1 | student | - And I log in as "admin" - And I am on "Course 1" course homepage + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | # Enable averages - And I navigate to "Setup > Course grade settings" in the course gradebook + And I am on the "Course 1" "grades > course grade settings" page logged in as "admin" And I set the following fields to these values: | Show average | Show | And I press "Save changes" + # Add a manual grade item - And I navigate to "Setup > Gradebook setup" in the course gradebook + And I am on the "Course 1" "grades > gradebook setup" page And I press "Add grade item" And I set the following fields to these values: | Item name | Manual item 1 | And I press "Save changes" + # Give all student the same grade for the manual grade item - And I navigate to "View > Grader report" in the course gradebook + And I am on the "Course 1" "grades > grader > View" page And I turn editing mode on And I give the grade "50.00" to the user "Student 1" for the grade item "Manual item 1" And I give the grade "50.00" to the user "Student 2" for the grade item "Manual item 1" And I give the grade "50.00" to the user "Student 3" for the grade item "Manual item 1" And I press "Save changes" And I turn editing mode off + # Suspend a user And I am on the "Course 1" "enrolled users" page And I click on "Edit enrolment" "link" in the "Student 2" "table_row" From 4136c6b0c9b9d383f74a3b1314cda89b97488c4a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 7 Jul 2023 11:06:49 +0800 Subject: [PATCH 4/4] MDL-78673 grade: Switch test to use generators --- grade/tests/behat/grade_average.feature | 35 ++++++++-------------- lib/behat/classes/behat_core_generator.php | 10 +++++++ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/grade/tests/behat/grade_average.feature b/grade/tests/behat/grade_average.feature index d6497a65f98..92005eca5fa 100644 --- a/grade/tests/behat/grade_average.feature +++ b/grade/tests/behat/grade_average.feature @@ -20,35 +20,24 @@ Feature: Average grades are displayed in the gradebook | student1 | C1 | student | | student2 | C1 | student | | student3 | C1 | student | + And the following "grade item" exists: + | course | C1 | + | itemname | Manual item 1 | + And the following "grade grades" exist: + | gradeitem | user | grade | + | Manual item 1 | student1 | 50.00 | + | Manual item 1 | student2 | 50.00 | + | Manual item 1 | student3 | 50.00 | + And the following "course enrolments" exist: + | user | course | role | status | + | student2 | C1 | student | suspended | + # Enable averages And I am on the "Course 1" "grades > course grade settings" page logged in as "admin" And I set the following fields to these values: | Show average | Show | And I press "Save changes" - # Add a manual grade item - And I am on the "Course 1" "grades > gradebook setup" page - And I press "Add grade item" - And I set the following fields to these values: - | Item name | Manual item 1 | - And I press "Save changes" - - # Give all student the same grade for the manual grade item - And I am on the "Course 1" "grades > grader > View" page - And I turn editing mode on - And I give the grade "50.00" to the user "Student 1" for the grade item "Manual item 1" - And I give the grade "50.00" to the user "Student 2" for the grade item "Manual item 1" - And I give the grade "50.00" to the user "Student 3" for the grade item "Manual item 1" - And I press "Save changes" - And I turn editing mode off - - # Suspend a user - And I am on the "Course 1" "enrolled users" page - And I click on "Edit enrolment" "link" in the "Student 2" "table_row" - And I set the following fields to these values: - | Status | Suspended | - And I press "Save changes" - Scenario: Grade a grade item and ensure the results display correctly in the gradebook # Check the admin grade table Given I am on the "Course 1" "grades > Grader report > View" page logged in as "admin" diff --git a/lib/behat/classes/behat_core_generator.php b/lib/behat/classes/behat_core_generator.php index 49df325f209..7b8a6cac4f0 100644 --- a/lib/behat/classes/behat_core_generator.php +++ b/lib/behat/classes/behat_core_generator.php @@ -607,6 +607,16 @@ class behat_core_generator extends behat_generator_base { if (!isset($data['status'])) { $data['status'] = null; + } else { + $status = strtolower($data['status']); + switch ($status) { + case 'active': + $data['status'] = ENROL_USER_ACTIVE; + break; + case 'suspended': + $data['status'] = ENROL_USER_SUSPENDED; + break; + } } // If the provided course shortname is the site shortname we consider it a system role assign.