Skip to content

Commit

Permalink
MDL-73954 quiz: fix decimal places for the percentage on review page
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Mar 4, 2022
1 parent 1d99ba1 commit 4f99e92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion mod/quiz/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions mod/quiz/tests/behat/attempt_basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,34 @@ 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 |
| Test questions | truefalse | TF3 | Third question |
| 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 |
| TF3 | 2 |
| 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"
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4f99e92

Please sign in to comment.