From 93289564e0eb3e862903c9bf168d6d73ef5f712e Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Fri, 22 Nov 2024 10:54:21 +0700 Subject: [PATCH] MDL-83778 quiz: prevent page caching for quiz view page --- mod/quiz/tests/behat/attempt_begin.feature | 17 +++++++++++++++++ mod/quiz/view.php | 2 ++ 2 files changed, 19 insertions(+) diff --git a/mod/quiz/tests/behat/attempt_begin.feature b/mod/quiz/tests/behat/attempt_begin.feature index 1b7508ae1a1..c1e53857d23 100644 --- a/mod/quiz/tests/behat/attempt_begin.feature +++ b/mod/quiz/tests/behat/attempt_begin.feature @@ -104,3 +104,20 @@ Feature: The various checks that may happen when an attept is started And I press "Cancel" Then I should see "Quiz 1 description" And "Attempt quiz" "button" should be visible + + @javascript + Scenario: Quiz attempt page reloads upon navigating back using the browser's back button + Given the following "activities" exist: + | activity | name | intro | course | idnumber | timelimit | + | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 3600 | + And quiz "Quiz 1" contains the following questions: + | question | page | + | TF1 | 1 | + When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" + And I press "Attempt quiz" + And I should see "Your attempt will have a time limit of 1 hour. When you " in the "Start attempt" "dialogue" + And I start watching to see if a new page loads + And I click on "Start attempt" "button" in the "Start attempt" "dialogue" + And I press the "back" button in the browser + Then a new page should have loaded since I started watching + And I should see "Continue your attempt" diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 7da171c8d3d..8bf1d0107b3 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -68,6 +68,8 @@ quiz_view($quiz, $course, $cm, $context); // Initialize $PAGE, compute blocks. $PAGE->set_url('/mod/quiz/view.php', ['id' => $cm->id]); +// On the quiz view page, the browser back/forwards buttons should force a reload. +$PAGE->set_cacheable(false); // Create view object which collects all the information the renderer will need. $viewobj = new view_page();