From 98513288b777e751e596edcbada0402fcbbaf1b1 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Mon, 5 May 2025 18:36:50 +0200 Subject: [PATCH] MDL-82069 core_completion: Improve errors for multiple grading items --- ..._grading_items_activity_completion.feature | 74 +++++++++++++++++++ course/moodleform_mod.php | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 completion/tests/behat/multiple_grading_items_activity_completion.feature diff --git a/completion/tests/behat/multiple_grading_items_activity_completion.feature b/completion/tests/behat/multiple_grading_items_activity_completion.feature new file mode 100644 index 00000000000..112d8ae891c --- /dev/null +++ b/completion/tests/behat/multiple_grading_items_activity_completion.feature @@ -0,0 +1,74 @@ +@core @core_completion @javascript +Feature: Check activity grading settings when requiring grading completion + In order to confirm the activity completion values are fine + As a teacher + I need to be able to be informed about the wrong settings. + + Background: + Given the following "courses" exist: + | fullname | shortname | category | enablecompletion | numsections | + | Course 1 | C1 | 0 | 1 | 1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | First | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "activity" exists: + | activity | forum | + | course | C1 | + | name | Test forum | + | completion | 0 | + + Scenario: Require any grade for multiple grading items activities + Given I am on the "Test forum" "forum activity editing" page logged in as teacher1 + And I expand all fieldsets + And I set the field "Add requirements" to "1" + And I set the field "Receive a grade" to "1" + When I click on "Save and display" "button" + Then I should see "Require grade can't be enabled for Rating because grading by Rating is not enabled." + And I set the following fields to these values: + | Ratings > Aggregate type | Average of ratings | + | id_scale_modgrade_type | Point | + | Ratings > scale[modgrade_point] | 60 | + And I click on "Save and display" "button" + And I should not see "Require grade can't be enabled for Rating because grading by Rating is not enabled." + And I should see "Receive a grade" + And I am on the "Test forum" "forum activity editing" page + And I set the following fields to these values: + | completiongradeitemnumber | Whole forum | + And I click on "Save and display" "button" + And I should see "Require grade can't be enabled for Whole forum because grading by Whole forum is not enabled." + And I set the following fields to these values: + | Whole forum grading > Type | Point | + And I click on "Save and display" "button" + And I should not see "Require grade can't be enabled for Whole forum because grading by Whole forum is not enabled." + And I should see "Receive a grade" + + Scenario: Require passing grade for multiple grading items activities + Given I am on the "Test forum" "forum activity editing" page logged in as teacher1 + And I set the following fields to these values: + | Ratings > Aggregate type | Average of ratings | + | id_scale_modgrade_type | Point | + | Ratings > scale[modgrade_point] | 60 | + | Whole forum grading > Type | Point | + And I expand all fieldsets + And I set the field "Add requirements" to "1" + And I set the field "Receive a grade" to "1" + And I set the field "Passing grade" to "1" + When I click on "Save and display" "button" + Then I should see "This activity does not have a valid grade to pass set" + And I set the following fields to these values: + | gradepass | 50 | + And I click on "Save and display" "button" + And I should see "Receive a passing grade" + And I am on the "Test forum" "forum activity editing" page + And I set the following fields to these values: + | completiongradeitemnumber | Whole forum | + And I click on "Save and display" "button" + And I should see "This activity does not have a valid grade to pass set" + And I expand all fieldsets + And I set the field "Grade to pass" to "50" + And I click on "Save and display" "button" + And I should not see "This activity does not have a valid grade to pass set" + And I should see "Receive a passing grade" diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index 3357140484a..1e885937d64 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -413,7 +413,7 @@ abstract class moodleform_mod extends moodleform { if (empty($data[$assessedfieldname]) && empty($data[$gradefieldname])) { // There are no grades set therefore completion is not allowed. if (isset($data['completiongradeitemnumber']) && $data['completiongradeitemnumber'] == (string) $itemnumber) { - $errors['completiongradeitemnumber'] = get_string( + $errors['completionpassgrade'] = get_string( 'badcompletiongradeitemnumber', 'completion', get_string("grade_{$itemname}_name", $component)