diff --git a/mod/lesson/continue.php b/mod/lesson/continue.php index 9106cfb7f7a..8ea44cbfdc4 100644 --- a/mod/lesson/continue.php +++ b/mod/lesson/continue.php @@ -161,11 +161,11 @@ if ($canmanage) { } } // Report attempts remaining -if ($result->attemptsremaining != 0 && !$lesson->review && !$reviewmode) { +if ($result->attemptsremaining != 0 && $lesson->review && !$reviewmode) { $lesson->add_message(get_string('attemptsremaining', 'lesson', $result->attemptsremaining)); } // Report if max attempts reached -if ($result->maxattemptsreached != 0 && !$lesson->review && !$reviewmode) { +if ($result->maxattemptsreached != 0 && $lesson->review && !$reviewmode) { $lesson->add_message('('.get_string("maximumnumberofattemptsreached", "lesson").')'); } @@ -183,7 +183,9 @@ if ($lesson->displayleft) { if ($lesson->ongoing && !$reviewmode) { echo $lessonoutput->ongoing_score($lesson); } -echo $result->feedback; +if (!$result->maxattemptsreached && !$reviewmode) { + echo $result->feedback; +} // User is modifying attempts - save button and some instructions if (isset($USER->modattempts[$lesson->id])) { @@ -198,7 +200,7 @@ if (isset($USER->modattempts[$lesson->id])) { } // Review button back -if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review) { +if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review && !$result->maxattemptsreached) { $url = $CFG->wwwroot.'/mod/lesson/view.php'; $content = html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$cm->id)); $content .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'pageid', 'value'=>$page->id)); @@ -207,7 +209,7 @@ if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion & } $url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid)); -if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion) { +if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$result->maxattemptsreached) { // Review button continue echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson')); } else { diff --git a/mod/lesson/tests/behat/lesson_navigation.feature b/mod/lesson/tests/behat/lesson_navigation.feature index 5cbad7cdc5e..7a2a34f89ae 100644 --- a/mod/lesson/tests/behat/lesson_navigation.feature +++ b/mod/lesson/tests/behat/lesson_navigation.feature @@ -4,8 +4,7 @@ Feature: In a lesson activity, students can navigate through a series of pages i As a teacher I need to add pages and questions with links between them - @javascript - Scenario: Student navigation with pages and questions + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -20,7 +19,10 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I log in as "teacher1" And I follow "Course 1" And I turn editing mode on - And I add a "Lesson" to section "1" and I fill the form with: + + @javascript + Scenario: Student navigation with pages and questions + Given I add a "Lesson" to section "1" and I fill the form with: | Name | Test lesson name | | Description | Test lesson description | And I follow "Test lesson name" @@ -87,3 +89,45 @@ 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" And I should see "Your score is 0 (out of 1)." + + @javascript + Scenario: Student reattempts a question until out of attempts + Given I add a "Lesson" to section "1" and I fill the form with: + | Name | Test lesson name | + | Description | Test lesson description | + | id_review | Yes | + | id_maxattempts | 3 | + 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 | + | id_answer_editor_0 | right | + | id_answer_editor_1 | wrong | + And I press "Save page" + And I log out + And I log in as "student1" + And I follow "Course 1" + When I follow "Test lesson name" + Then I should see "Test content" + 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" + 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" + And I set the following fields to these values: + | wrong | 1 | + And I press "Submit" + And I should see "(Maximum number of attempts reached - Moving to next page)" + And I press "Continue" + And I should see "Congratulations - end of lesson reached"