From ebf0598e21e4aeea469df072192f31a8b9a3a9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 27 Jul 2016 16:20:18 +0200 Subject: [PATCH 1/3] MDL-55360 workshop: Allow creating workshops with empty grades to pass As a regression of MDL-55360, it was not possible to create new workshops if the field "Submission grade to pass" or "Assessment grade to pass" was left empty. The validation failed with "You must enter a number here". The fields submissiongradepass and gradinggradepass are always present as we explicitly define them in the mod form. So the isset() condition in the validation was useless and it did not allow to submit the form with these fields empty. Additionally, the unformat_float() returns null only if it receives empty value on the input. Which can't happen in our case so I am removing this condition to improve the readability of the code. --- mod/workshop/mod_form.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index 0a87b5b0df1..db864e04476 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -396,9 +396,9 @@ class mod_workshop_mod_form extends moodleform_mod { } // Check that the submission grade pass is a valid number. - if (isset($data['submissiongradepass'])) { + if (!empty($data['submissiongradepass'])) { $submissiongradefloat = unformat_float($data['submissiongradepass'], true); - if ($submissiongradefloat === false || $submissiongradefloat === null) { + if ($submissiongradefloat === false) { $errors['submissiongradepass'] = get_string('err_numeric', 'form'); } else { if ($submissiongradefloat > $data['grade']) { @@ -408,9 +408,9 @@ class mod_workshop_mod_form extends moodleform_mod { } // Check that the grade pass is a valid number. - if (isset($data['gradinggradepass'])) { + if (!empty($data['gradinggradepass'])) { $gradepassfloat = unformat_float($data['gradinggradepass'], true); - if ($gradepassfloat === false || $gradepassfloat === null) { + if ($gradepassfloat === false) { $errors['gradinggradepass'] = get_string('err_numeric', 'form'); } else { if ($gradepassfloat > $data['gradinggrade']) { From 3c4cc10effd166d4aad5bf1e46923d4a4cf5c16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 27 Jul 2016 16:22:12 +0200 Subject: [PATCH 2/3] MDL-55360 workshop: Emptying grades to pass should set them to zero When editing existing workshop with a grade to pass defined, when the field is emptied, it should be interpreted as setting it to zero. This was not happening because unformat_float replaces the field with null, therefore effectively unsetting it. By casting to float, we interpret all empty values (including null) as zeros. This behaviour is consistent with how gradebook setup UI works. --- mod/workshop/lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index c9f40482f1d..07664a8f45b 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -82,11 +82,11 @@ function workshop_add_instance(stdclass $workshop) { $workshop->evaluation = 'best'; if (isset($workshop->gradinggradepass)) { - $workshop->gradinggradepass = unformat_float($workshop->gradinggradepass); + $workshop->gradinggradepass = (float)unformat_float($workshop->gradinggradepass); } if (isset($workshop->submissiongradepass)) { - $workshop->submissiongradepass = unformat_float($workshop->submissiongradepass); + $workshop->submissiongradepass = (float)unformat_float($workshop->submissiongradepass); } if (isset($workshop->submissionfiletypes)) { @@ -158,11 +158,11 @@ function workshop_update_instance(stdclass $workshop) { $workshop->phaseswitchassessment = (int)!empty($workshop->phaseswitchassessment); if (isset($workshop->gradinggradepass)) { - $workshop->gradinggradepass = unformat_float($workshop->gradinggradepass); + $workshop->gradinggradepass = (float)unformat_float($workshop->gradinggradepass); } if (isset($workshop->submissiongradepass)) { - $workshop->submissiongradepass = unformat_float($workshop->submissiongradepass); + $workshop->submissiongradepass = (float)unformat_float($workshop->submissiongradepass); } if (isset($workshop->submissionfiletypes)) { From aea8c5541ee355993ce05805a3dc31d51d305148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 27 Jul 2016 17:11:39 +0200 Subject: [PATCH 3/3] MDL-55360 workshop: Add tests for setting grades to pass via mod form These scenarios should cover common cases of defining the grades to pass pass via the workshop settings form. Note that behaviour of the fields in terms of locale-specific decimals input (MDL-51806) is not covered with these tests as I want to avoid installation of additional language pack. Instead, I assume that functionality of unformat_float() is tested separately in the core. --- .../tests/behat/grade_to_pass.feature | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 mod/workshop/tests/behat/grade_to_pass.feature diff --git a/mod/workshop/tests/behat/grade_to_pass.feature b/mod/workshop/tests/behat/grade_to_pass.feature new file mode 100644 index 00000000000..da72a7a3ece --- /dev/null +++ b/mod/workshop/tests/behat/grade_to_pass.feature @@ -0,0 +1,91 @@ +@mod @mod_workshop +Feature: Setting grades to pass via workshop editing form + In order to define grades to pass + As a teacher + I can set them in the workshop settings form, without the need to go to the gradebook + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Terry1 | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course1 | c1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | c1 | editingteacher | + + Scenario: Adding a new workshop with grade to pass field set + Given I log in as "teacher1" + And I follow "Course1" + And I turn editing mode on + When I add a "Workshop" to section "1" and I fill the form with: + | Workshop name | Awesome workshop | + | Description | Grades to pass are set here | + | Submission grade to pass | 45 | + | Assessment grade to pass | 10.5 | + Then I should not see "Adding a new Workshop" + And I follow "Awesome workshop" + And I navigate to "Edit settings" node in "Workshop administration" + And the field "Submission grade to pass" matches value "45.00" + And the field "Assessment grade to pass" matches value "10.50" + + Scenario: Adding a new workshop with grade to pass fields left empty + Given I log in as "teacher1" + And I follow "Course1" + And I turn editing mode on + When I add a "Workshop" to section "1" and I fill the form with: + | Workshop name | Another awesome workshop | + | Description | No grades to pass are set here | + | Submission grade to pass | | + | Assessment grade to pass | | + Then I should not see "Adding a new Workshop" + And I follow "Another awesome workshop" + And I navigate to "Edit settings" node in "Workshop administration" + And the field "Submission grade to pass" matches value "0.00" + And the field "Assessment grade to pass" matches value "0.00" + + Scenario: Adding a new workshop with non-numeric value of a grade to pass + Given I log in as "teacher1" + And I follow "Course1" + And I turn editing mode on + When I add a "Workshop" to section "1" and I fill the form with: + | Workshop name | Almost awesome workshop | + | Description | Invalid grade to pass is set here | + | Assessment grade to pass | You shall not pass! | + Then I should see "Adding a new Workshop" + And I should see "You must enter a number here" + + Scenario: Adding a new workshop with invalid value of a grade to pass + Given I log in as "teacher1" + And I follow "Course1" + And I turn editing mode on + When I add a "Workshop" to section "1" and I fill the form with: + | Workshop name | Almost awesome workshop | + | Description | Invalid grade to pass is set here | + | Assessment grade to pass | 10000000 | + Then I should see "Adding a new Workshop" + And I should see "The grade to pass can not be greater than the maximum possible grade" + + Scenario: Emptying grades to pass fields sets them to zero + Given I log in as "teacher1" + And I follow "Course1" + And I turn editing mode on + And I add a "Workshop" to section "1" and I fill the form with: + | Workshop name | Super awesome workshop | + | Description | Grade to pass are set and then unset here | + | Submission grade to pass | 59.99 | + | Assessment grade to pass | 0.000 | + And I should not see "Adding a new Workshop" + And I follow "Super awesome workshop" + And I navigate to "Edit settings" node in "Workshop administration" + And the field "Submission grade to pass" matches value "59.99" + And the field "Assessment grade to pass" matches value "0.00" + When I set the field "Submission grade to pass" to "" + And I set the field "Assessment grade to pass" to "" + And I press "Save and display" + Then I should not see "Adding a new Workshop" + And I follow "Super awesome workshop" + And I navigate to "Edit settings" node in "Workshop administration" + And the field "Submission grade to pass" matches value "0.00" + And the field "Assessment grade to pass" matches value "0.00"