diff --git a/mod/quiz/tests/behat/attempt_basic.feature b/mod/quiz/tests/behat/attempt_basic.feature index c8e0ffd505a..259dcbb0ebb 100644 --- a/mod/quiz/tests/behat/attempt_basic.feature +++ b/mod/quiz/tests/behat/attempt_basic.feature @@ -75,6 +75,7 @@ Feature: Attempt a quiz And I should see "Grade" And I should see "25.00 out of 100.00" And I follow "Finish review" + And I should see "Highest grade: 25.00 / 100.00" And I press "Re-attempt quiz" @javascript diff --git a/mod/quiz/tests/behat/view_grade_recover_grades.feature b/mod/quiz/tests/behat/view_grade_recover_grades.feature new file mode 100644 index 00000000000..7b21d166677 --- /dev/null +++ b/mod/quiz/tests/behat/view_grade_recover_grades.feature @@ -0,0 +1,93 @@ +@mod @mod_quiz +Feature: Testing view quiz grade feedback with recover grades setting + As a user + I want the quiz grade and completion status to reflect the recover grades setting used when re-enrolling a user + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher | Teacher | One | teacher@example.com | + | student | Student | One | student@example.com | + And the following "courses" exist: + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher | C1 | editingteacher | + | student | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | completion | completionusegrade | + | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 2 | 1 | + And the following "question categories" exist: + | contextlevel | reference | name | + | Activity module | quiz1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | TF1 | First question | + And quiz "Quiz 1" contains the following questions: + | question | page | + | TF1 | 1 | + And user "student" has attempted "Quiz 1" with responses: + | slot | response | + | 1 | True | + + Scenario Outline: Teachers can view grade feedback and score regardless of recover grades setting + Given the following config values are set as admin: + | recovergradesdefault | | + And user "teacher" has attempted "Quiz 1" with responses: + | slot | response | + | 1 | True | + When I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher" + # Grade feedback and grade score should be the same. Recover grades setting should not affect the score + Then I should see "Highest grade: 100.00 / 100.00" + And I should see "100.00 out of 100.00" in the "Grade" "table_row" + + Examples: + | recovergradesetting | + | 0 | + | 1 | + + Scenario Outline: View quiz grade feedback and score with recover grades settings + Given the following config values are set as admin: + | recovergradesdefault | | + When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" + # Grade feedback and grade score should be the same. Recover grades setting should not affect users who are not unenrolled + Then I should see "Highest grade: 100.00 / 100.00" + And I should see "100.00 out of 100.00" in the "Grade" "table_row" + And I should see "Done: Receive a grade" in the "[data-region='completion-info']" "css_element" + + Examples: + | recovergradesetting | + | 0 | + | 1 | + + @javascript + Scenario Outline: View quiz after unenrolling and re-enrolling user + Given the following config values are set as admin: + | recovergradesdefault | | + And I log in as "teacher" + And I am on "Course 1" course homepage + And I navigate to course participants + And I click on "Unenrol" "icon" in the "Student One" "table_row" + And I click on "Unenrol" "button" in the "Unenrol" "dialogue" + And the following "course enrolments" exist: + | user | course | role | + | student | C1 | student | + When I am on the "Quiz 1" "mod_quiz > View" page logged in as "student" + Then I should see "" in the "[id='feedback']" "css_element" + And I should see "100.00 out of 100.00" in the "Grade" "table_row" + And I should see "" in the "[data-region='completion-info']" "css_element" + # Re-attempt the quiz + And I press "Re-attempt quiz" + And I should see "First question" + And I click on "True" "radio" in the "First question" "question" + And I click on "Finish attempt ..." "button" in the "region-main" "region" + And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue" + And I follow "Finish review" + And I should see "Highest grade: 100.00 / 100.00" in the "[id='feedback']" "css_element" + + Examples: + | recovergradesetting | overallgradefeedback | mycompletionstatus | + | 0 | Highest grade: Not yet graded / 100.00 | To do: Receive a grade | + | 1 | Highest grade: 100.00 / 100.00 | Done: Receive a grade | diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 327b9c6f2ed..fdf38eb8856 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -116,6 +116,7 @@ foreach (array_reverse($viewobj->attemptobjs) as $attemptobj) { } // Work out the final grade, checking whether it was overridden in the gradebook. +// First, get an initial grade to display. if (!$canpreview) { $mygrade = quiz_get_best_grade($quiz, $USER->id); } else if ($lastfinishedattempt) { @@ -126,6 +127,7 @@ if (!$canpreview) { $mygrade = null; } +// Now, check the grade in the gradebook, if there is one. $mygradeoverridden = false; $gradebookfeedback = ''; @@ -137,25 +139,23 @@ $gradeitem = grade_item::fetch([ 'courseid' => $course->id, ]); -if ($gradeitem) { - if ($CFG->recovergradesdefault && $gradeitem->refresh_grades($USER->id)) { - $grade = $gradeitem->get_grade($USER->id, false); - if ($grade->overridden) { - if ($gradeitem->needsupdate) { - // It is Error, but let's be consistent with the old code. - $mygrade = 0; - } else { - $mygrade = $grade->finalgrade; - } - $mygradeoverridden = true; - } +// If there's a grade item grade, then get that grade for this user. +// Users who can preview the quiz (eg teachers) won't have a proper grade, +// so no point getting their grades here. +if (!$canpreview && $gradeitem) { + $grade = $gradeitem->get_grade($USER->id, false); + $mygrade = $grade->finalgrade; // Use this grade to display in the view page. - if (!empty($grade->feedback)) { - $gradebookfeedback = $grade->feedback; + if ($grade->overridden) { + if ($gradeitem->needsupdate) { + // It is Error, but let's be consistent with the old code. + $mygrade = 0; } - } else { - // It is Error, but let's be consistent with the old code. - $mygrade = 0; + $mygradeoverridden = true; + } + + if (!empty($grade->feedback)) { + $gradebookfeedback = $grade->feedback; } } @@ -169,7 +169,7 @@ $PAGE->add_body_class('limitedwidth'); /** @var renderer $output */ $output = $PAGE->get_renderer('mod_quiz'); -// Print table with existing attempts. +// Print overall stats and table with existing attempts. if ($attempts) { // Work out which columns we need, taking account what data is available in each attempt. list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts);