From 3c51d8a87b1ef6658488928748ed53e5b5f92a73 Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Mon, 21 Mar 2022 12:22:45 +0800 Subject: [PATCH] MDL-74274 lesson: Set maxattempts reached when retries allowed --- mod/lesson/locallib.php | 3 + .../tests/behat/lesson_navigation.feature | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 56c0a07da29..dd4b44b396b 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -4240,6 +4240,9 @@ abstract class lesson_page extends lesson_base { $result->newpageid = LESSON_NEXTPAGE; } else if ($this->lesson->maxattempts > 1) { // don't bother with message if only one attempt $result->attemptsremaining = $this->lesson->maxattempts - $nattempts; + if ($result->attemptsremaining == 0) { + $result->maxattemptsreached = true; + } } } } diff --git a/mod/lesson/tests/behat/lesson_navigation.feature b/mod/lesson/tests/behat/lesson_navigation.feature index 1e6fab136c6..7de0b715166 100644 --- a/mod/lesson/tests/behat/lesson_navigation.feature +++ b/mod/lesson/tests/behat/lesson_navigation.feature @@ -133,6 +133,64 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I press "Continue" And I should see "Congratulations - end of lesson reached" + Scenario: Student reattempts a question until out of attempts with specific jumps + Given the following "activities" exist: + | activity | name | intro | course | idnumber | + | lesson | Test lesson name | Test lesson description | C1 | lesson1 | + And I am on the "Test lesson name" "lesson activity" page + And I navigate to "Settings" in current page administration + And I set the following fields to these values: + | id_review | Yes | + | id_maxattempts | 3 | + And I press "Save and return to course" + And I follow "Test lesson name" + And I follow "Add a question page" + And I set the following fields to these values: + | id_qtype | True/false | + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Test question | + | Page contents | Test content 1 | + | id_answer_editor_0 | right | + | id_answer_editor_1 | wrong | + And I press "Save page" + And I select "Add a question page" from the "qtype" singleselect + And I set the field "Select a question type" to "True/false" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Test question 2 | + | Page contents | Test content 2 | + | id_answer_editor_0 | right | + | id_jumpto_0 | Test question | + | id_answer_editor_1 | wrong | + | id_jumpto_1 | Test question | + And I press "Save page" + And I log out + When I am on the "Test lesson name" "lesson activity" page logged in as student1 + Then I should see "Test content 1" + And I set the following fields to these values: + | right | 1 | + And I press "Submit" + And I should see "Test content 2" + And I set the following fields to these values: + | wrong | 1 | + And I press "Submit" + And I should see "You have 2 attempt(s) remaining" + And I press "Yes, I'd like to try again" + And I should see "Test content 2" + And I set the following fields to these values: + | wrong | 1 | + And I press "Submit" + And I should see "You have 1 attempt(s) remaining" + And I press "Yes, I'd like to try again" + And I should see "Test content 2" + And I set the following fields to these values: + | wrong | 1 | + And I press "Submit" + And I should not see "Yes, I'd like to try again" + And I press "Continue" + And I should see "Test content 1" + Scenario: Student should not see remaining attempts notification if maximum number of attempts is set to unlimited Given the following "activities" exist: | activity | name | intro | course | idnumber |