From f41741e7ba23dfa6014884f747cf2d5c3232bbf6 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 15 Apr 2012 14:19:41 +0200 Subject: [PATCH 1/2] MDL-32437 fix invalid gradebook query sql --- grade/querylib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grade/querylib.php b/grade/querylib.php index 6cf97634db8..43ba59690dd 100644 --- a/grade/querylib.php +++ b/grade/querylib.php @@ -335,7 +335,7 @@ function grade_get_gradable_activities($courseid, $modulename='') { $params = array($courseid, $modulename, GRADE_TYPE_NONE, $modulename); $sql = "SELECT cm.*, m.name, md.name as modname - FROM {grade_items} gi, {course_modules} cm, {modules} md, {$modulename} m + FROM {grade_items} gi, {course_modules} cm, {modules} md, {{$modulename}} m WHERE gi.courseid = ? AND gi.itemtype = 'mod' AND gi.itemmodule = ? AND From 7467f4c911dfa6533578bc929fe566b4bb0bfd90 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 15 Apr 2012 14:19:58 +0200 Subject: [PATCH 2/2] MDL-32437 add gradebook querylib tests --- grade/tests/querylib_test.php | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 grade/tests/querylib_test.php diff --git a/grade/tests/querylib_test.php b/grade/tests/querylib_test.php new file mode 100644 index 00000000000..b37df345940 --- /dev/null +++ b/grade/tests/querylib_test.php @@ -0,0 +1,53 @@ +. + +/** + * Unit tests for grade quering + * + * @pacakge core_grade + * @category phpunit + * @copyright 2011 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->libdir.'/gradelib.php'); +require_once($CFG->dirroot.'/grade/querylib.php'); + + +class grade_querylib_testcase extends advanced_testcase { + + public function test_grade_get_gradable_activities() { + $this->resetAfterTest(true); + + $course = $this->getDataGenerator()->create_course(); + $data1 = $this->getDataGenerator()->create_module('data', array('assessed'=>1, 'scale'=>100, 'course'=>$course->id)); + $data2 = $this->getDataGenerator()->create_module('data', array('assessed'=>0, 'course'=>$course->id)); + $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed'=>1, 'scale'=>100, 'course'=>$course->id)); + $forum2 = $this->getDataGenerator()->create_module('forum', array('assessed'=>0, 'course'=>$course->id)); + + $cms = grade_get_gradable_activities($course->id); + $this->assertEquals(2, count($cms)); + $this->assertTrue(isset($cms[$data1->cmid])); + $this->assertTrue(isset($cms[$forum1->cmid])); + + $cms = grade_get_gradable_activities($course->id, 'forum'); + $this->assertEquals(1, count($cms)); + $this->assertTrue(isset($cms[$forum1->cmid])); + } +}