diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index e52b4d56571..d319063a3ce 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -267,6 +267,7 @@ $string['maximumattemptsdesc'] = 'This preference sets the default maximum attem $string['maximumgradedesc'] = 'This preference sets the default maximum grade for an activity'; $string['menubar'] = 'Show the menu bar'; $string['min'] = 'Minimum score'; +$string['minimumscoregreater'] = 'Minimum score must be greater than 0'; $string['missing_attribute'] = 'Missing attribute {$a->attr} in tag {$a->tag}'; $string['missingparam'] = 'A required parameter is missing or wrong'; $string['missing_tag'] = 'Missing tag {$a->tag}'; diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index 758ef900fdf..036544ff057 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -470,6 +470,15 @@ class mod_scorm_mod_form extends moodleform_mod { } } + // Validate 'Require minimum score' value. + $completionscorerequiredel = 'completionscorerequired' . $this->get_suffix(); + if (array_key_exists($completionscorerequiredel, $data) && + strlen($data[$completionscorerequiredel]) && + $data[$completionscorerequiredel] <= 0 + ) { + $errors['completionscoregroup' . $this->get_suffix()] = get_string('minimumscoregreater', 'scorm'); + } + return $errors; } @@ -547,7 +556,8 @@ class mod_scorm_mod_form extends moodleform_mod { public function completion_rule_enabled($data) { $suffix = $this->get_suffix(); $status = !empty($data['completionstatusrequired' . $suffix]); - $score = !empty($data['completionscoreenabled' . $suffix]) && strlen($data['completionscorerequired' . $suffix]); + $score = !empty($data['completionscoreenabled' . $suffix]) && + strlen($data['completionscorerequired' . $suffix] && $data['completionscorerequired' . $suffix] > 0); return $status || $score; } diff --git a/mod/scorm/tests/behat/scorm_activity_completion.feature b/mod/scorm/tests/behat/scorm_activity_completion.feature index a27e28c5fcb..eea6fe9f012 100644 --- a/mod/scorm/tests/behat/scorm_activity_completion.feature +++ b/mod/scorm/tests/behat/scorm_activity_completion.feature @@ -27,10 +27,10 @@ Feature: View activity completion in the SCORM activity | completionstatusrequired | 6 | | completionscorerequired | 3 | | completionstatusrequired | 6 | - | completionstatusallscos | 1 | + | completionstatusallscos | 1 | | maxattempt | 1 | | completionview | 1 | - | completionusegrade | 1 | + | completionusegrade | 1 | @javascript Scenario: View automatic completion items as a teacher @@ -131,3 +131,21 @@ Feature: View activity completion in the SCORM activity Then the manual completion button of "Music history" is displayed as "Mark as done" And I toggle the manual completion state of "Music history" And the manual completion button of "Music history" is displayed as "Done" + + @javascript + Scenario: Required minimum score should be greater than zero + Given I am on the "Music history" "scorm activity" page logged in as teacher1 + And I navigate to "Settings" in current page administration + And I expand all fieldsets + When I set the field "completionscorerequired" to "0" + And I click on "Save and display" "button" + Then I should see "Minimum score must be greater than 0" + And "Enter" "button" should not exist + And I set the field "completionscorerequired" to "-1" + And I click on "Save and display" "button" + And I should see "Minimum score must be greater than 0" + And "Enter" "button" should not exist + And I set the field "completionscorerequired" to "5" + And I click on "Save and display" "button" + And I should not see "Minimum score must be greater than 0" + And "Enter" "button" should exist