MDL-50285 gradereport_user: Grade categories calculate wrong with suspended users (Student's view)

This commit is contained in:
Damien Bezborodov 2015-05-15 13:06:04 +09:30 committed by David Monllao
parent d34a865a61
commit e604d38fc7
2 changed files with 73 additions and 2 deletions

View File

@ -859,7 +859,7 @@ class grade_report_user extends grade_report {
* Builds the grade item averages.
*/
function calculate_averages() {
global $USER, $DB;
global $USER, $DB, $CFG;
if ($this->showaverage) {
// This settings are actually grader report settings (not user report)
@ -882,7 +882,11 @@ class grade_report_user extends grade_report {
list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
// Limit to users with an active enrolment.
list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
$coursecontext = $this->context->get_course_context(true);
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext);
list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context, '', 0, $showonlyactiveenrol);
$params = array_merge($this->groupwheresql_params, $gradebookrolesparams, $enrolledparams, $relatedctxparams);
$params['courseid'] = $this->courseid;

View File

@ -0,0 +1,67 @@
@core @core_grades
Feature: Average grades are displayed in the gradebook
In order to check the expected results are displayed
As an admin
I need to assign grades and check that they display correctly in the gradebook.
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
And I log in as "admin"
And I am on site homepage
And I follow "Course 1"
# Enable averages
And I navigate to "Grades" node in "Course administration"
And I navigate to "Course grade settings" node in "Grade administration > Setup"
And I set the following fields to these values:
| Show average | Show |
And I press "Save changes"
# Add a manual grade item
And I navigate to "Categories and items" node in "Grade administration > Setup"
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
And I press "Save changes"
# Give all student the same grade for the manual grade item
And I navigate to "Grader report" node in "Grade administration"
And I turn editing mode on
And I give the grade "50.00" to the user "Student 1" for the grade item "Manual item 1"
And I give the grade "50.00" to the user "Student 2" for the grade item "Manual item 1"
And I give the grade "50.00" to the user "Student 3" for the grade item "Manual item 1"
And I press "Save changes"
And I turn editing mode off
# Suspend a user
And I navigate to "Enrolled users" node in "Course administration > Users"
And I click on "Edit" "link" in the "Student 2" "table_row"
And I set the following fields to these values:
| Status | Suspended |
And I press "Save changes"
Scenario: Grade a grade item and ensure the results display correctly in the gradebook
# Check the admin grade table
And I navigate to "Grades" node in "Course administration"
Then I should see "50.00" in the ".avg.r0.lastrow .c1" "css_element"
Then I should see "50.00" in the ".avg.r0.lastrow .c2" "css_element"
And I log out
# Check the user grade table
And I log in as "student1"
And I am on site homepage
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
Then I should see "50.00" in the ".level2.column-grade" "css_element"
Then I should see "50.00" in the ".level2.column-average" "css_element"
And I log out