diff --git a/public/mod/quiz/attempt.php b/public/mod/quiz/attempt.php index d7f0d25edde..103cb63772c 100644 --- a/public/mod/quiz/attempt.php +++ b/public/mod/quiz/attempt.php @@ -136,18 +136,12 @@ $navbc = $attemptobj->get_navigation_panel($output, navigation_panel_attempt::cl $regions = $PAGE->blocks->get_regions(); $PAGE->blocks->add_fake_block($navbc, reset($regions)); +$attemptobj->setup_attempt_layout(); + $headtags = $attemptobj->get_html_head_contributions($page); $PAGE->set_title($attemptobj->attempt_page_title($page)); -$PAGE->add_body_class('limitedwidth'); $PAGE->set_heading($attemptobj->get_course()->fullname); -if ($PAGE->pagelayout === 'secure') { - // Show the activity header (but only the name) in the secure layout on quiz pages. - $PAGE->activityheader->set_attrs([ - 'description' => '', - ]); -} else { - $PAGE->activityheader->disable(); -} + if ($attemptobj->is_last_page($page)) { $nextpage = -1; } else { diff --git a/public/mod/quiz/classes/quiz_attempt.php b/public/mod/quiz/classes/quiz_attempt.php index 8aee1b09bd4..afc53be1468 100644 --- a/public/mod/quiz/classes/quiz_attempt.php +++ b/public/mod/quiz/classes/quiz_attempt.php @@ -1342,6 +1342,30 @@ class quiz_attempt { } } + /** + * Set up the page layout for an attempt, summary or review page. + */ + public function setup_attempt_layout(): void { + global $PAGE; + + $PAGE->add_body_class('limitedwidth'); + + if (empty($this->get_quiz()->showblocks) && !$this->is_preview_user()) { + $PAGE->blocks->show_only_fake_blocks(); + } + + if ($PAGE->pagelayout === 'secure') { + // Show the activity header (but only the name) in the secure layout on quiz pages. + // Don't show the completion info which would include the activitydates to reduce clutter. + $PAGE->activityheader->set_attrs([ + 'description' => '', + 'hidecompletion' => true, + ]); + } else { + $PAGE->activityheader->disable(); + } + } + /** * Generate the HTML that displays the question in its current state, with * the appropriate display options. diff --git a/public/mod/quiz/review.php b/public/mod/quiz/review.php index 63a84ab474f..efb4409288f 100644 --- a/public/mod/quiz/review.php +++ b/public/mod/quiz/review.php @@ -109,11 +109,12 @@ if ($attemptobj->is_own_preview()) { } } +$attemptobj->setup_attempt_layout(); + // Set up the page header. $headtags = $attemptobj->get_html_head_contributions($page, $showall); $PAGE->set_title($attemptobj->review_page_title($page, $showall)); $PAGE->set_heading($attemptobj->get_course()->fullname); -$PAGE->activityheader->disable(); $summarydata = attempt_summary_information::create_for_attempt($attemptobj, $options, $page, $showall); diff --git a/public/mod/quiz/summary.php b/public/mod/quiz/summary.php index 1e530682bdd..675cef3eb27 100644 --- a/public/mod/quiz/summary.php +++ b/public/mod/quiz/summary.php @@ -94,10 +94,12 @@ $navbc = $attemptobj->get_navigation_panel($output, navigation_panel_attempt::cl $regions = $PAGE->blocks->get_regions(); $PAGE->blocks->add_fake_block($navbc, reset($regions)); +$attemptobj->setup_attempt_layout(); + $PAGE->navbar->add(get_string('summaryofattempt', 'quiz')); $PAGE->set_title($attemptobj->summary_page_title()); $PAGE->set_heading($attemptobj->get_course()->fullname); -$PAGE->activityheader->disable(); + // Display the page. echo $output->summary_page($attemptobj, $displayoptions); diff --git a/public/mod/quiz/tests/behat/attempt_secure_layout.feature b/public/mod/quiz/tests/behat/attempt_secure_layout.feature index 7c7e1c4ca29..066ff5098e4 100644 --- a/public/mod/quiz/tests/behat/attempt_secure_layout.feature +++ b/public/mod/quiz/tests/behat/attempt_secure_layout.feature @@ -15,8 +15,8 @@ Feature: Attempt a quiz in secure layout | user | course | role | | student | C1 | student | And the following "activities" exist: - | activity | name | intro | course | idnumber | grade | navmethod | browsersecurity | showuserpicture | - | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 100 | free | securewindow | 2 | + | activity | name | intro | course | idnumber | grade | navmethod | browsersecurity | showuserpicture | timeopen | timeclose | + | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 100 | free | securewindow | 2 | ##yesterday## | ##tomorrow## | And the following "question categories" exist: | contextlevel | reference | name | | Activity module | quiz1 | Test questions | @@ -27,7 +27,6 @@ Feature: Attempt a quiz in secure layout And quiz "Quiz 1" contains the following questions: | question | page | maxmark | | TF1 | 1 | | - | TF2 | 1 | 3.0 | @javascript Scenario: Large user image in the quiz navigation in secure layout @@ -36,11 +35,47 @@ Feature: Attempt a quiz in secure layout And I switch to a second window Then "Student One" "link" should not exist in the "Quiz navigation" "block" - Scenario: A quiz page on the secure layout shows both the course name and the quiz name + @javascript + Scenario: A quiz page on the secure layout shows both the course name and the quiz name in attempt, summary, and review Given I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" And I should see "Quiz 1" And I should see "Quiz 1 description" When I press "Attempt quiz" + And I switch to a second window Then I should see "Course 1" And I should see "Quiz 1" + And the "class" attribute of "body" "css_element" should contain "limitedwidth" But I should not see "Quiz 1 description" + And I should not see "Opened:" + And I should not see "Closes:" + And I click on "True" "radio" + And I follow "Finish attempt ..." + And I should see "Course 1" + And I should see "Quiz 1" + And the "class" attribute of "body" "css_element" should contain "limitedwidth" + But I should not see "Quiz 1 description" + And I should not see "Opened:" + And I should not see "Closes:" + And I click on "Submit all and finish" "button" + And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue" + And I should see "Course 1" + And I should see "Quiz 1" + And the "class" attribute of "body" "css_element" should contain "limitedwidth" + But I should not see "Quiz 1 description" + And I should not see "Opened:" + And I should not see "Closes:" + + @javascript + Scenario: A quiz review page on the secure layout shows both the course name and the quiz name + Given user "student" has attempted "Quiz 1" with responses: + | slot | response | + | 1 | True | + When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" + And I click on "Review" "button" + And I switch to a second window + Then I should see "Course 1" + And I should see "Quiz 1" + Then the "class" attribute of "body" "css_element" should contain "limitedwidth" + But I should not see "Quiz 1 description" + And I should not see "Opened:" + And I should not see "Closes:"