From 973641fe1343be1c4f61d46d0fc8c2d9c04605f3 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 20 May 2016 23:45:36 +0200 Subject: [PATCH 1/2] MDL-54666 tests: Verify that any activity keeps the settings This was affecting both to rateable (forum...) and not rateable (assignment...) activities. So tests have been completed to verify that now saving is performed and the correct scale values stored. --- .../tests/behat/modgrade_validation.feature | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/form/tests/behat/modgrade_validation.feature b/lib/form/tests/behat/modgrade_validation.feature index 3aa71e40841..f30f2edf8ec 100644 --- a/lib/form/tests/behat/modgrade_validation.feature +++ b/lib/form/tests/behat/modgrade_validation.feature @@ -65,7 +65,60 @@ Feature: Using the activity grade form element And I should not see "You must choose whether to rescale existing grades or not" @javascript - Scenario: Attempting to change the scale when grades already exist + Scenario: Attempting to change the scale when grades already exist in rating activity + Given I log in as "admin" + And I navigate to "Scales" node in "Site administration > Grades" + And I press "Add a new scale" + And I set the following fields to these values: + | Name | ABCDEF | + | Scale | F,E,D,C,B,A | + And I press "Save changes" + And I press "Add a new scale" + And I set the following fields to these values: + | Name | Letter scale | + | Scale | Disappointing, Good, Very good, Excellent | + And I press "Save changes" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Forum" to section "1" and I fill the form with: + | Forum name | Test forum name | + | Forum type | Standard forum for general use | + | Description | Test forum description | + | Aggregate type | Average of ratings | + | scale[modgrade_type] | Scale | + | scale[modgrade_scale] | ABCDEF | + | Group mode | No groups | + And I log out + And I log in as "student1" + And I follow "Course 1" + And I follow "Test forum name" + And I press "Add a new discussion topic" + And I set the following fields to these values: + | Subject | Discussion subject | + | Message | Discussion message | + And I press "Post to forum" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test forum name" + And I follow "Discussion subject" + And I set the field "rating" to "D" + And I click on "Edit settings" "link" in the "Administration" "block" + When I expand all fieldsets + Then I should see "Some grades have already been awarded, so the grade type and scale cannot be changed" + # Try saving the form and visiting it back to verify that everything is working ok. + And I press "Save and display" + And I should not see "When selecting a ratings aggregate type you must also select" + And I click on "Edit settings" "link" + And I expand all fieldsets + And the field "Aggregate type" matches value "Average of ratings" + And the field "scale[modgrade_type]" matches value "Scale" + And the field "scale[modgrade_scale]" matches value "ABCDEF" + + @javascript + Scenario: Attempting to change the scale when grades already exist in non-rating activity Given I log in as "admin" And I navigate to "Scales" node in "Site administration > Grades" And I press "Add a new scale" @@ -97,6 +150,12 @@ Feature: Using the activity grade form element And I click on "Edit settings" "link" When I expand all fieldsets Then I should see "Some grades have already been awarded, so the grade type and scale cannot be changed" + # Try saving the form and visiting it back to verify everything is working ok. + And I press "Save and display" + And I click on "Edit settings" "link" + And I expand all fieldsets + And the field "grade[modgrade_type]" matches value "Scale" + And the field "grade[modgrade_scale]" matches value "ABCDEF" Scenario: Attempting to change the maximum grade when ratings exist Given I log in as "teacher1" From 4ca17b63a13d06ddb3673ef2ccbe61425eb99ff0 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sat, 21 May 2016 12:37:30 +0800 Subject: [PATCH 2/2] MDL-54666 modedit: use default values when modgrade element is frozen --- lib/form/modgrade.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/form/modgrade.php b/lib/form/modgrade.php index e6cdc731270..b33f4370cee 100644 --- a/lib/form/modgrade.php +++ b/lib/form/modgrade.php @@ -465,10 +465,12 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group { '[modgrade_rescalegrades]', 'eq', ''); // A constant value should be given as an int. - // The default value should be an int and should really be $CFG->gradepointdefault. + // The default value should be an int and be either $CFG->gradepointdefault or whatever was set in set_data(). $value = $this->_findValue($caller->_constantValues); if (null === $value) { - if ($caller->isSubmitted()) { + if ($caller->isSubmitted() && $this->_findValue($caller->_submitValues) !== null) { + // Submitted values are array, one value for each individual element in this group. + // When there is submitted data let parent::onQuickFormEvent() process it. break; } $value = $this->_findValue($caller->_defaultValues);