From f7155953f4c3d3101a090677063fe48194ff6f37 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 16 Jun 2021 17:57:48 +0800 Subject: [PATCH] MDL-71796 mod_scorm: fix custom completion logic AMOS BEGIN MOV [completiondetail:completionstatuscompletedandpassed,mod_scorm],[completiondetail:completionstatuscompletedorpassed,mod_scorm] AMOS END --- .../classes/completion/custom_completion.php | 12 ++++-------- mod/scorm/lang/en/scorm.php | 2 +- .../behat/scorm_activity_completion.feature | 6 +++--- mod/scorm/tests/custom_completion_test.php | 16 +++++++++++----- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mod/scorm/classes/completion/custom_completion.php b/mod/scorm/classes/completion/custom_completion.php index 6c2f7077059..9a551915a1a 100644 --- a/mod/scorm/classes/completion/custom_completion.php +++ b/mod/scorm/classes/completion/custom_completion.php @@ -67,18 +67,14 @@ class custom_completion extends activity_custom_completion { // Get available status list. $statuses = array_flip(\scorm_status_options()); - $statusbits = 0; $requiredcompletionstatusid = $this->cm->customdata['customcompletionrules']['completionstatusrequired'] ?? 0; + $isanystatus = ($requiredcompletionstatusid == array_sum($statuses)); // Check at least one track meets the required completion status value(s). foreach ($tracks as $track) { - if (array_key_exists($track->value, $statuses)) { - $statusbits |= $statuses[$track->value]; - } - - // All completion status requirements met. - if ($statusbits == $requiredcompletionstatusid) { + if (array_key_exists($track->value, $statuses) + && ($isanystatus || $statuses[$track->value] == $requiredcompletionstatusid)) { $status = COMPLETION_COMPLETE; break; } @@ -193,7 +189,7 @@ class custom_completion extends activity_custom_completion { $statusrequired = $statusstrings[$completionstatusid]; } else { // All statuses required. - $statusrequired = 'completedandpassed'; + $statusrequired = 'completedorpassed'; } return [ diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index f5dd2d22809..a1265ae0f12 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -83,7 +83,7 @@ $string['compatibilitysettings'] = 'Compatibility settings'; $string['completed'] = 'Completed'; $string['completiondetail:completionstatuspassed'] = 'Pass the activity'; $string['completiondetail:completionstatuscompleted'] = 'Complete the activity'; -$string['completiondetail:completionstatuscompletedandpassed'] = 'Complete and pass the activity'; +$string['completiondetail:completionstatuscompletedorpassed'] = 'Complete or pass the activity'; $string['completiondetail:completionscore'] = 'Receive a score of {$a} or more'; $string['completiondetail:allscos'] = 'Do all parts of this activity'; $string['completionscorerequired'] = 'Require minimum score'; diff --git a/mod/scorm/tests/behat/scorm_activity_completion.feature b/mod/scorm/tests/behat/scorm_activity_completion.feature index 0e690f1c87f..77e562e59f4 100644 --- a/mod/scorm/tests/behat/scorm_activity_completion.feature +++ b/mod/scorm/tests/behat/scorm_activity_completion.feature @@ -50,7 +50,7 @@ Feature: View activity completion in the SCORM activity And "Music history" should have the "Receive a score of 3 or more" completion condition And "Music history" should have the "Do all parts of this activity" completion condition And "Music history" should have the "Receive a grade" completion condition - And "Music history" should have the "Complete and pass the activity" completion condition + And "Music history" should have the "Complete or pass the activity" completion condition @javascript Scenario: View automatic completion items as a student @@ -61,7 +61,7 @@ Feature: View activity completion in the SCORM activity And the "Receive a score of 3 or more" completion condition of "Music history" is displayed as "todo" And the "Do all parts of this activity" completion condition of "Music history" is displayed as "todo" And the "Receive a grade" completion condition of "Music history" is displayed as "todo" - And the "Complete and pass the activity" completion condition of "Music history" is displayed as "todo" + And the "Complete or pass the activity" completion condition of "Music history" is displayed as "todo" And I press "Enter" And I switch to the main frame And I click on "Par?" "list_item" @@ -93,7 +93,7 @@ Feature: View activity completion in the SCORM activity And the "Receive a score of 3 or more" completion condition of "Music history" is displayed as "failed" And the "Do all parts of this activity" completion condition of "Music history" is displayed as "done" And the "Receive a grade" completion condition of "Music history" is displayed as "done" - And the "Complete and pass the activity" completion condition of "Music history" is displayed as "failed" + And the "Complete or pass the activity" completion condition of "Music history" is displayed as "done" @javascript Scenario: Use manual completion diff --git a/mod/scorm/tests/custom_completion_test.php b/mod/scorm/tests/custom_completion_test.php index 4f3b4a18a03..cf267af1c76 100644 --- a/mod/scorm/tests/custom_completion_test.php +++ b/mod/scorm/tests/custom_completion_test.php @@ -104,20 +104,26 @@ class custom_completion_test extends advanced_testcase { 'Completion status Completed required, user has completed' => [ 'completionstatusrequired', 4, [$completioncompleted], 1, COMPLETION_COMPLETE, null ], - 'Completion status Passed and Completed required, user has only completed, can make another attempt' => [ - 'completionstatusrequired', 6, [$completioncompleted], 0, COMPLETION_INCOMPLETE, null + 'Completion status Passed or Completed required, user has only completed, can make another attempt' => [ + 'completionstatusrequired', 6, [$completioncompleted], 0, COMPLETION_COMPLETE, null ], - 'Completion status Passed and Completed required, user has completed and passed' => [ + 'Completion status Passed or Completed required, user has completed and passed' => [ 'completionstatusrequired', 6, [$completionpassed, $completioncompleted], 0, COMPLETION_COMPLETE, null ], + 'Completion status Passed or Completed required, user has not passed or completed, but has another attempt' => [ + 'completionstatusrequired', 6, [$completionincomplete], 2, COMPLETION_INCOMPLETE, null + ], + 'Completion status Passed or Completed required, user has used all attempts, but not passed or completed' => [ + 'completionstatusrequired', 6, [$completionincomplete], 1, COMPLETION_COMPLETE_FAIL, null + ], 'Completion status Passed required, user has used all attempts and completed, but not passed' => [ 'completionstatusrequired', 2, [$completioncompleted], 1, COMPLETION_COMPLETE_FAIL, null ], 'Completion status Completed required, user has used all attempts, but not completed' => [ 'completionstatusrequired', 4, [$completionincomplete], 1, COMPLETION_COMPLETE_FAIL, null ], - 'Completion status Passed and Completed required, user has used all attempts, but not passed' => [ - 'completionstatusrequired', 6, [$completionincomplete, $completioncompleted], 2, COMPLETION_COMPLETE_FAIL, null + 'Completion status Passed or Completed required, user has used all attempts, but not passed' => [ + 'completionstatusrequired', 6, [$completionincomplete, $completioncompleted], 2, COMPLETION_COMPLETE, null ], 'Completion score required, user has no score' => [ 'completionscorerequired', 80, [], 0, COMPLETION_INCOMPLETE, null