From 4f99e92a810538a02aff82db3a586a02b9ceb586 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 24 Feb 2022 17:06:51 +0000 Subject: [PATCH] MDL-73954 quiz: fix decimal places for the percentage on review page --- mod/quiz/review.php | 5 ++++- mod/quiz/tests/behat/attempt_basic.feature | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 40f746e661b79..5c9e2ef9440ec 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -216,8 +216,11 @@ $a->grade = html_writer::tag('b', quiz_format_grade($quiz, $grade)); $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); if ($quiz->grade != 100) { + // Show the percentage using the configured number of decimal places, + // but without trailing zeroes. $a->percent = html_writer::tag('b', format_float( - $attempt->sumgrades * 100 / $quiz->sumgrades, 0)); + $attempt->sumgrades * 100 / $quiz->sumgrades, + $quiz->decimalpoints, true, true)); $formattedgrade = get_string('outofpercent', 'quiz', $a); } else { $formattedgrade = get_string('outof', 'quiz', $a); diff --git a/mod/quiz/tests/behat/attempt_basic.feature b/mod/quiz/tests/behat/attempt_basic.feature index 6a5ca5208424a..5b7f51695647e 100644 --- a/mod/quiz/tests/behat/attempt_basic.feature +++ b/mod/quiz/tests/behat/attempt_basic.feature @@ -48,8 +48,11 @@ Feature: Attempt a quiz And I press "Re-attempt quiz" @javascript - Scenario: Attempt a quiz with mulitple sections - Given the following "questions" exist: + Scenario: Attempt a quiz with multiple sections + Given the following "activities" exist: + | activity | name | course | idnumber | grade | + | quiz | Quiz 2 | C1 | quiz2 | 6 | + And the following "questions" exist: | questioncategory | qtype | name | questiontext | | Test questions | truefalse | TF1 | First question | | Test questions | truefalse | TF2 | Second question | @@ -57,7 +60,7 @@ Feature: Attempt a quiz | Test questions | truefalse | TF4 | Fourth question | | Test questions | truefalse | TF5 | Fifth question | | Test questions | truefalse | TF6 | Sixth question | - And quiz "Quiz 1" contains the following questions: + And quiz "Quiz 2" contains the following questions: | question | page | | TF1 | 1 | | TF2 | 1 | @@ -65,14 +68,14 @@ Feature: Attempt a quiz | TF4 | 3 | | TF5 | 4 | | TF6 | 4 | - And quiz "Quiz 1" contains the following sections: + And quiz "Quiz 2" contains the following sections: | heading | firstslot | shuffle | | Section 1 | 1 | 0 | | Section 2 | 3 | 0 | | | 4 | 1 | | Section 3 | 5 | 1 | - When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" + When I am on the "Quiz 2" "mod_quiz > View" page logged in as "student" And I press "Attempt quiz" Then I should see "Section 1" in the "Quiz navigation" "block" @@ -82,6 +85,7 @@ Feature: Attempt a quiz And I should see question "4" in section "Untitled section" in the quiz navigation And I should see question "5" in section "Section 3" in the quiz navigation And I should see question "6" in section "Section 3" in the quiz navigation + And I click on "True" "radio" in the "First question" "question" And I follow "Finish attempt ..." And I should see question "1" in section "Section 1" in the quiz navigation @@ -97,6 +101,7 @@ Feature: Attempt a quiz And I press "Submit all and finish" And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue" + And I should see "1.00 out of 6.00 (16.67%)" in the "Grade" "table_row" And I should see question "1" in section "Section 1" in the quiz navigation And I should see question "2" in section "Section 1" in the quiz navigation And I should see question "3" in section "Section 2" in the quiz navigation