mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-36061_userid' of git://github.com/andyjdavis/moodle
This commit is contained in:
commit
491391873e
4 changed files with 80 additions and 5 deletions
|
@ -1423,30 +1423,33 @@ class grade_item extends grade_object {
|
|||
* Refetch grades from modules, plugins.
|
||||
*
|
||||
* @param int $userid optional, limit the refetch to a single user
|
||||
* @return bool Returns true on success or if there is nothing to do
|
||||
*/
|
||||
public function refresh_grades($userid=0) {
|
||||
global $DB;
|
||||
if ($this->itemtype == 'mod') {
|
||||
if ($this->is_outcome_item()) {
|
||||
//nothing to do
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$activity = $DB->get_record($this->itemmodule, array('id' => $this->iteminstance))) {
|
||||
debugging("Can not find $this->itemmodule activity with id $this->iteminstance");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) {
|
||||
debugging('Can not find course module');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$activity->modname = $this->itemmodule;
|
||||
$activity->cmidnumber = $cm->idnumber;
|
||||
|
||||
grade_update_mod_grades($activity);
|
||||
return grade_update_mod_grades($activity, $userid);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,6 +58,7 @@ class grade_item_testcase extends grade_base_testcase {
|
|||
$this->sub_test_grade_item_is_course_item();
|
||||
$this->sub_test_grade_item_fetch_course_item();
|
||||
$this->sub_test_grade_item_depends_on();
|
||||
$this->sub_test_refresh_grades();
|
||||
$this->sub_test_grade_item_is_calculated();
|
||||
$this->sub_test_grade_item_set_calculation();
|
||||
$this->sub_test_grade_item_get_calculation();
|
||||
|
@ -483,6 +484,18 @@ class grade_item_testcase extends grade_base_testcase {
|
|||
$this->assertEquals($res, $deps);
|
||||
}
|
||||
|
||||
protected function sub_test_refresh_grades() {
|
||||
// Testing with the grade item for a mod_assignment instance.
|
||||
$grade_item = new grade_item($this->grade_items[0], false);
|
||||
$this->assertTrue(method_exists($grade_item, 'refresh_grades'));
|
||||
$this->assertTrue($grade_item->refresh_grades());
|
||||
|
||||
// Break the grade item and check error handling.
|
||||
$grade_item->iteminstance = 123456789;
|
||||
$this->assertFalse($grade_item->refresh_grades());
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
protected function sub_test_grade_item_is_calculated() {
|
||||
$grade_item = new grade_item($this->grade_items[1], false);
|
||||
$this->assertTrue(method_exists($grade_item, 'is_calculated'));
|
||||
|
|
|
@ -1190,7 +1190,7 @@ function grade_update_mod_grades($modinstance, $userid=0) {
|
|||
$updategradesfunc($modinstance, $userid);
|
||||
|
||||
} else {
|
||||
// mudule does not support grading??
|
||||
// Module does not support grading?
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
59
lib/tests/gradelib_test.php
Normal file
59
lib/tests/gradelib_test.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for /lib/gradelib.php.
|
||||
*
|
||||
* @package core_grade
|
||||
* @category phpunit
|
||||
* @copyright 2012 Andrew Davis
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
class gradelib_testcase extends advanced_testcase {
|
||||
|
||||
public function test_grade_update_mod_grades() {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Create a broken module instance.
|
||||
$modinstance = new stdClass();
|
||||
$modinstance->modname = 'doesntexist';
|
||||
|
||||
$this->assertFalse(grade_update_mod_grades($modinstance));
|
||||
// A debug message should have been generated.
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Create a course and instance of mod_assign.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$assigndata['course'] = $course->id;
|
||||
$assigndata['name'] = 'lightwork assignment';
|
||||
$modinstance = self::getDataGenerator()->create_module('assign', $assigndata);
|
||||
|
||||
// grade_update_mod_grades() requires 2 additional properties, cmidnumber and modname.
|
||||
$cm = get_coursemodule_from_instance('assign', $modinstance->id, 0, false, MUST_EXIST);
|
||||
$modinstance->cmidnumber = $cm->id;
|
||||
$modinstance->modname = 'assign';
|
||||
|
||||
$this->assertTrue(grade_update_mod_grades($modinstance));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue