Merge branch 'MDL-31713_override' of git://github.com/andyjdavis/moodle

This commit is contained in:
Damyon Wiese
2013-05-07 15:28:17 +08:00
2 changed files with 36 additions and 0 deletions
+5
View File
@@ -1503,6 +1503,11 @@ class grade_item extends grade_object {
$oldgrade->feedback = $grade->feedback;
$oldgrade->feedbackformat = $grade->feedbackformat;
// MDL-31713 rawgramemin and max must be up to date so conditional access %'s works properly.
$grade->rawgrademin = $this->grademin;
$grade->rawgrademax = $this->grademax;
$grade->rawscaleid = $this->scaleid;
// changed grade?
if ($finalgrade !== false) {
if ($this->is_overridable_item()) {
+31
View File
@@ -63,6 +63,7 @@ class grade_item_testcase extends grade_base_testcase {
$this->sub_test_grade_item_set_calculation();
$this->sub_test_grade_item_get_calculation();
$this->sub_test_grade_item_compute();
$this->sub_test_update_final_grade();
}
protected function sub_test_grade_item_construct() {
@@ -557,4 +558,34 @@ class grade_item_testcase extends grade_base_testcase {
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));
$this->assertEquals($this->grade_grades[5]->finalgrade, $grade_grade->finalgrade);
}
protected function sub_test_update_final_grade() {
// MDL-31713 Check that min and max are set on the grade_grade instance
// if the grade is overridden before the activity has supplied a grade.
$min = 2;
$max = 8;
// Create a brand new grade item.
$grade_item = new grade_item();
$this->assertTrue(method_exists($grade_item, 'insert'));
$grade_item->courseid = $this->courseid;
$grade_item->categoryid = $this->grade_categories[1]->id;
$grade_item->itemname = 'brand new unit test grade item';
$grade_item->itemtype = 'mod';
$grade_item->itemmodule = 'quiz';
$grade_item->iteminfo = 'Grade item used for unit testing';
$grade_item->grademin = $min;
$grade_item->grademax = $max;
$grade_item->insert();
// Override the student grade.
$grade_item->update_final_grade($this->user[1]->id, 7, 'gradebook', '', FORMAT_MOODLE);
// Check the student's grade has the correct min and max grade.
$grade_grade = grade_grade::fetch(array('userid'=>$this->user[1]->id, 'itemid'=>$grade_item->id));
$this->assertEquals($min, $grade_grade->rawgrademin);
$this->assertEquals($max, $grade_grade->rawgrademax);
}
}