mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-47420 Grades: Get unit tests passing on natural grading branch
Part of: MDL-46576
This commit is contained in:
parent
663949e652
commit
c529f4b30f
@ -414,7 +414,7 @@ abstract class grade_report {
|
||||
* @param string $courseid the course id
|
||||
* @param string $course_item an instance of grade_item
|
||||
* @param string $finalgrade the grade for the course_item
|
||||
* @return array[] containing values for 'grade', 'grademax' and 'grademin'
|
||||
* @return array[] containing values for 'grade', 'grademax', 'grademin', 'aggregationstatus' and 'aggregationweight'
|
||||
*/
|
||||
protected function blank_hidden_total_and_adjust_bounds($courseid, $course_item, $finalgrade) {
|
||||
global $CFG, $DB;
|
||||
@ -432,6 +432,8 @@ abstract class grade_report {
|
||||
if ($coursegradegrade) {
|
||||
$grademin = $coursegradegrade->rawgrademin;
|
||||
$grademax = $coursegradegrade->rawgrademax;
|
||||
} else {
|
||||
$coursegradegrade = new grade_grade(array('userid'=>$this->user->id, 'itemid'=>$course_item->id), false);
|
||||
}
|
||||
$hint = $coursegradegrade->get_aggregation_hint();
|
||||
$aggregationstatus = $hint['status'];
|
||||
@ -443,7 +445,11 @@ abstract class grade_report {
|
||||
}
|
||||
|
||||
if ($this->showtotalsifcontainhidden[$courseid] == GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN) {
|
||||
return array('grade' => $finalgrade, 'grademin' => $grademin, 'grademax' => $grademax);
|
||||
return array('grade' => $finalgrade,
|
||||
'grademin' => $grademin,
|
||||
'grademax' => $grademax,
|
||||
'aggregationstatus' => $aggregationstatus,
|
||||
'aggregationweight' => $aggregationweight);
|
||||
}
|
||||
|
||||
// If we've moved on to another course or user, reload the grades.
|
||||
@ -489,19 +495,19 @@ abstract class grade_report {
|
||||
$finalgrade = null;
|
||||
} else {
|
||||
//use reprocessed marks that exclude hidden items
|
||||
if (isset($hiding_affected['altered'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
|
||||
$finalgrade = $hiding_affected['altered'][$course_item->id];
|
||||
}
|
||||
if (isset($hiding_affected['alteredgrademin'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademin'])) {
|
||||
$grademin = $hiding_affected['alteredgrademin'][$course_item->id];
|
||||
}
|
||||
if (isset($hiding_affected['alteredgrademax'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademax'])) {
|
||||
$grademax = $hiding_affected['alteredgrademax'][$course_item->id];
|
||||
}
|
||||
if (isset($hiding_affected['alteredaggregationstatus'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus'])) {
|
||||
$aggregationstatus = $hiding_affected['alteredaggregationstatus'][$course_item->id];
|
||||
}
|
||||
if (isset($hiding_affected['alteredaggregationweight'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
|
||||
$aggregationweight = $hiding_affected['alteredaggregationweight'][$course_item->id];
|
||||
}
|
||||
}
|
||||
@ -514,16 +520,16 @@ abstract class grade_report {
|
||||
//use reprocessed marks that exclude hidden items
|
||||
$finalgrade = $hiding_affected['unknown'][$course_item->id];
|
||||
|
||||
if (!empty($hiding_affected['alteredgrademin'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademin'])) {
|
||||
$grademin = $hiding_affected['alteredgrademin'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredgrademax'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademax'])) {
|
||||
$grademax = $hiding_affected['alteredgrademax'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredaggregationstatus'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus'])) {
|
||||
$aggregationstatus = $hiding_affected['alteredaggregationstatus'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredaggregationweight'][$course_item->id])) {
|
||||
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
|
||||
$aggregationweight = $hiding_affected['alteredaggregationweight'][$course_item->id];
|
||||
}
|
||||
}
|
||||
|
@ -124,21 +124,26 @@ class core_grade_reportlib_testcase extends advanced_testcase {
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => $datagrade + $forumgrade,
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
// Should blank the student total as course grade depends on a hidden item.
|
||||
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => null,
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
|
||||
// Should return the course total minus the hidden database activity grade.
|
||||
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN);
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => $forumgrade,
|
||||
$this->assertEquals(array('grade' => floatval($forumgrade),
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
|
||||
// Note: we cannot simply hide modules and call $report->blank_hidden_total() again.
|
||||
// It stores grades in a static variable so $report->blank_hidden_total() will return incorrect totals
|
||||
@ -195,14 +200,18 @@ class core_grade_reportlib_testcase extends advanced_testcase {
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => $datagrade + $forumgrade,
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
|
||||
// Should blank the student total as course grade depends on a hidden item.
|
||||
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => null,
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
|
||||
// Should return the course total minus the hidden activity grades.
|
||||
// They are both hidden so should return null.
|
||||
@ -210,6 +219,8 @@ class core_grade_reportlib_testcase extends advanced_testcase {
|
||||
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
|
||||
$this->assertEquals(array('grade' => null,
|
||||
'grademax' => $coursegradeitem->grademax,
|
||||
'grademin' => $coursegradeitem->grademin), $result);
|
||||
'grademin' => $coursegradeitem->grademin,
|
||||
'aggregationstatus' => 'unknown',
|
||||
'aggregationweight' => null), $result);
|
||||
}
|
||||
}
|
||||
|
@ -601,7 +601,7 @@ class grade_category extends grade_object {
|
||||
// Make sure a grade_grade exists for every grade_item.
|
||||
// We need to do this so we can set the aggregationstatus
|
||||
// with a set_field call instead of checking if each one exists and creating/updating.
|
||||
if (count($items) > 0) {
|
||||
if (!empty($items)) {
|
||||
list($ggsql, $params) = $DB->get_in_or_equal(array_keys($items), SQL_PARAMS_NAMED, 'g');
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user