MDL-80235 mod_scorm: Required minimum score should be >0

This commit is contained in:
Amaia Anabitarte 2024-03-04 17:54:04 +01:00
parent debed3eace
commit 43099744c3
3 changed files with 32 additions and 3 deletions

View File

@ -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}';

View File

@ -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;
}

View File

@ -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