From c3d4d3f7c15275e4f2712017ea18812fbf48b8be Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 11 Aug 2016 14:39:34 +0800 Subject: [PATCH 1/2] MDL-55520 forms: Mod grade is changing values back to default When a field is disabled in the page - no value is sent and modgrade is reverting to the default. This change prevents the max grade from changing accidentally. --- lib/form/modgrade.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/form/modgrade.php b/lib/form/modgrade.php index b33f4370cee..9fe780618e3 100644 --- a/lib/form/modgrade.php +++ b/lib/form/modgrade.php @@ -266,7 +266,8 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group { $point = (isset($vals['modgrade_point'])) ? $vals['modgrade_point'] : null; $scale = (isset($vals['modgrade_scale'])) ? $vals['modgrade_scale'] : null; $rescalegrades = (isset($vals['modgrade_rescalegrades'])) ? $vals['modgrade_rescalegrades'] : null; - $return = $this->process_value($type, $scale, $point); + + $return = $this->process_value($type, $scale, $point, $rescalegrades); return array($this->getName() => $return, $this->getName() . '_rescalegrades' => $rescalegrades); } @@ -276,11 +277,17 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group { * @param string $type The value of the grade type select box. Can be 'none', 'scale', or 'point' * @param string|int $scale The value of the scale select box. * @param string|int $point The value of the point grade textbox. + * @param string $rescalegrades The value of the rescalegrades select. * @return int The resulting value */ - protected function process_value($type='none', $scale=null, $point=null) { + protected function process_value($type='none', $scale=null, $point=null, $rescalegrades=null) { global $COURSE; $val = 0; + if ($this->isupdate && $this->hasgrades && $this->canrescale && $this->currentgradetype == 'point' && empty($rescalegrades)) { + // If the maxgrade field is disabled with javascript, no value is sent with the form and mform assumes the default. + // If the user was forced to choose a rescale option - and they haven't - prevent any changes to the max grade. + return $this->currentgrade; + } switch ($type) { case 'point': if ($this->validate_point($point) === true) { From a95014f5b41f081432bbb8083ce40adf1fa2618e Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 11 Aug 2016 15:13:31 +0800 Subject: [PATCH 2/2] MDL-55520 assign: Behat test for rescaling max grades bug Verify the max grade is not silently changed back to 100 when you visit and save the assignment settings form. --- mod/assign/tests/behat/rescale_grades.feature | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mod/assign/tests/behat/rescale_grades.feature b/mod/assign/tests/behat/rescale_grades.feature index 8b589ac4113..4d861e5d7c5 100644 --- a/mod/assign/tests/behat/rescale_grades.feature +++ b/mod/assign/tests/behat/rescale_grades.feature @@ -45,6 +45,22 @@ Feature: Check that the assignment grade can be rescaled when the max grade is c And I follow "View all submissions" Then "Student 1" row "Grade" column of "generaltable" table should contain "40.00" + Scenario: Update an assignment without touching the max grades + Given I follow "Edit settings" + And I expand all fieldsets + And I set the field "Rescale existing grades" to "No" + And I set the field "Maximum grade" to "80" + And I press "Save and display" + And I follow "Edit settings" + And I press "Save and display" + And I follow "Edit settings" + And I expand all fieldsets + And I set the field "Rescale existing grades" to "Yes" + And I set the field "Maximum grade" to "80" + When I press "Save and display" + And I follow "View all submissions" + Then "Student 1" row "Grade" column of "generaltable" table should contain "40.00" + Scenario: Update the max grade for an assignment rescaling existing grades Given I follow "Edit settings" And I expand all fieldsets