From 4d32558974d811fc2239a5c430c9599b5217935e Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 17 Oct 2019 17:36:23 +0100 Subject: [PATCH] MDL-66946 quiz reports: incorrectly show teachers sometimes --- mod/quiz/report/attemptsreport.php | 3 ++- mod/quiz/report/overview/tests/behat/basic.feature | 7 +++---- mod/quiz/report/overview/tests/report_test.php | 9 ++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index 95f02101fec..fc259a226da 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -125,7 +125,8 @@ abstract class quiz_attempts_report extends quiz_default_report { return array($currentgroup, $empty, $empty, $empty); } - $studentsjoins = get_enrolled_with_capabilities_join($this->context); + $studentsjoins = get_enrolled_with_capabilities_join($this->context, '', + array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts')); if (empty($currentgroup)) { return array($currentgroup, $studentsjoins, $empty, $studentsjoins); diff --git a/mod/quiz/report/overview/tests/behat/basic.feature b/mod/quiz/report/overview/tests/behat/basic.feature index a24fcf42d77..91c35bc7069 100644 --- a/mod/quiz/report/overview/tests/behat/basic.feature +++ b/mod/quiz/report/overview/tests/behat/basic.feature @@ -58,8 +58,7 @@ Feature: Basic use of the Grades report # Check changing the form parameters And I set the field "Attempts from" to "enrolled users who have not attempted the quiz" And I press "Show report" - # Check teacher1's grade - And I should see "-" in the "T1 Teacher1" "table_row" + # Note: teachers should not appear in the report. # Check student3's grade And I should see "-" in the "S3 Student3" "table_row" @@ -69,8 +68,8 @@ Feature: Basic use of the Grades report And I should see "25.00" in the "S1 Student1" "table_row" # Check student2's grade And I should see "100.00" in the "S2 Student2" "table_row" - # Check teacher1's grade - And I should see "-" in the "T1 Teacher1" "table_row" + # Check student3's grade + And I should see "-" in the "S3 Student3" "table_row" And I set the field "Attempts from" to "all users who have attempted the quiz" And I press "Show report" diff --git a/mod/quiz/report/overview/tests/report_test.php b/mod/quiz/report/overview/tests/report_test.php index 54606daa649..41fd57dfed6 100644 --- a/mod/quiz/report/overview/tests/report_test.php +++ b/mod/quiz/report/overview/tests/report_test.php @@ -87,6 +87,12 @@ class quiz_overview_report_testcase extends advanced_testcase { // student enrolment does not cause duplicate records in this query. $generator->enrol_user($student2->id, $course->id, null, 'self'); + // Also create a user who should not appear in the reports, + // because they have a role with neither 'mod/quiz:attempt' + // nor 'mod/quiz:reviewmyattempts'. + $tutor = $generator->create_user(); + $generator->enrol_user($tutor->id, $course->id, 'teacher'); + // The test data. $timestamp = 1234567890; $attempts = array( @@ -154,7 +160,8 @@ class quiz_overview_report_testcase extends advanced_testcase { $context = context_module::instance($quiz->cmid); $cm = get_coursemodule_from_id('quiz', $quiz->cmid); $qmsubselect = quiz_report_qm_filter_select($quiz); - $studentsjoins = get_enrolled_with_capabilities_join($context); + $studentsjoins = get_enrolled_with_capabilities_join($context, '', + array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts')); $empty = new \core\dml\sql_join(); // Set the options. -- 2.43.0