See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * @package core_grades 19 * @category phpunit 20 * @copyright nicolas@moodle.com 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 defined('MOODLE_INTERNAL') || die(); 25 26 require_once (__DIR__.'/fixtures/lib.php'); 27 28 29 class core_grade_scale_testcase extends grade_base_testcase { 30 31 public function test_grade_scale() { 32 $this->sub_test_scale_construct(); 33 $this->sub_test_grade_scale_insert(); 34 $this->sub_test_grade_scale_update(); 35 $this->sub_test_grade_scale_delete(); 36 $this->sub_test_grade_scale_fetch(); 37 $this->sub_test_scale_load_items(); 38 $this->sub_test_scale_compact_items(); 39 $this->sub_test_scale_one_item(); 40 } 41 42 protected function sub_test_scale_construct() { 43 $params = new stdClass(); 44 $params->name = 'unittestscale3'; 45 $params->courseid = $this->course->id; 46 $params->userid = $this->userid; 47 $params->scale = 'Distinction, Very Good, Good, Pass, Fail'; 48 $params->description = 'This scale is used to mark standard assignments.'; 49 $params->timemodified = time(); 50 51 $scale = new grade_scale($params, false); 52 53 $this->assertEquals($params->name, $scale->name); 54 $this->assertEquals($params->scale, $scale->scale); 55 $this->assertEquals($params->description, $scale->description); 56 57 } 58 59 protected function sub_test_grade_scale_insert() { 60 $grade_scale = new grade_scale(); 61 $this->assertTrue(method_exists($grade_scale, 'insert')); 62 63 $grade_scale->name = 'unittestscale3'; 64 $grade_scale->courseid = $this->courseid; 65 $grade_scale->userid = $this->userid; 66 $grade_scale->scale = 'Distinction, Very Good, Good, Pass, Fail'; 67 $grade_scale->description = 'This scale is used to mark standard assignments.'; 68 69 $grade_scale->insert(); 70 71 $last_grade_scale = end($this->scale); 72 73 $this->assertEquals($grade_scale->id, $last_grade_scale->id + 1); 74 $this->assertNotEmpty($grade_scale->timecreated); 75 $this->assertNotEmpty($grade_scale->timemodified); 76 } 77 78 protected function sub_test_grade_scale_update() { 79 global $DB; 80 $grade_scale = new grade_scale($this->scale[1], false); 81 $this->assertTrue(method_exists($grade_scale, 'update')); 82 83 $grade_scale->name = 'Updated info for this unittest grade_scale'; 84 $this->assertTrue($grade_scale->update()); 85 $name = $DB->get_field('scale', 'name', array('id' => $this->scale[1]->id)); 86 $this->assertEquals($grade_scale->name, $name); 87 } 88 89 protected function sub_test_grade_scale_delete() { 90 global $DB; 91 $grade_scale = new grade_scale($this->scale[4], false); // Choose one we're not using elsewhere. 92 $this->assertTrue(method_exists($grade_scale, 'delete')); 93 94 $this->assertTrue($grade_scale->delete()); 95 $this->assertFalse($DB->get_record('scale', array('id' => $grade_scale->id))); 96 97 // Keep the reference collection the same as what is in the database. 98 unset($this->scale[4]); 99 } 100 101 protected function sub_test_grade_scale_fetch() { 102 $grade_scale = new grade_scale(); 103 $this->assertTrue(method_exists($grade_scale, 'fetch')); 104 105 $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id)); 106 $this->assertEquals($this->scale[0]->id, $grade_scale->id); 107 $this->assertEquals($this->scale[0]->name, $grade_scale->name); 108 } 109 110 protected function sub_test_scale_load_items() { 111 $scale = new grade_scale($this->scale[0], false); 112 $this->assertTrue(method_exists($scale, 'load_items')); 113 114 $scale->load_items(); 115 $this->assertCount(7, $scale->scale_items); 116 $this->assertEquals('Fairly neutral', $scale->scale_items[2]); 117 118 } 119 120 protected function sub_test_scale_compact_items() { 121 $scale = new grade_scale($this->scale[0], false); 122 $this->assertTrue(method_exists($scale, 'compact_items')); 123 124 $scale->load_items(); 125 $scale->scale = null; 126 $scale->compact_items(); 127 128 // The original string and the new string may have differences in whitespace around the delimiter, and that's OK. 129 $this->assertEquals(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale); 130 } 131 132 protected function sub_test_scale_one_item() { 133 $params = new stdClass(); 134 $params->name = 'unittestscale1i'; 135 $params->courseid = $this->course->id; 136 $params->userid = $this->userid; 137 $params->scale = 'Like'; 138 $params->description = 'This scale is used to like something.'; 139 $params->timemodified = time(); 140 141 $scale = new grade_scale($params, false); 142 $scale->load_items(); 143 144 $this->assertCount(1, $scale->scale_items); 145 $this->assertSame(array('Like'), $scale->scale_items); 146 $this->assertSame('Like', $scale->compact_items()); 147 148 $scale->insert(); 149 150 // Manual grade item with 1 item scale. 151 $grade_item = new stdClass(); 152 $grade_item->courseid = $this->course->id; 153 $grade_item->categoryid = $this->grade_categories[0]->id; 154 $grade_item->itemname = 'manual grade_item scale_1'; 155 $grade_item->itemtype = 'manual'; 156 $grade_item->itemnumber = 0; 157 $grade_item->needsupdate = false; 158 $grade_item->gradetype = GRADE_TYPE_SCALE; 159 $grade_item->scaleid = $scale->id; 160 $grade_item->iteminfo = 'Manual grade item used for unit testing'; 161 $grade_item->timecreated = time(); 162 $grade_item->timemodified = time(); 163 164 $grade_item = new grade_item($grade_item); 165 $grade_item->insert(); 166 167 $this->assertNotEmpty($grade_item->id); 168 $this->assertEquals(1, $grade_item->grademin); 169 $this->assertEquals(1, $grade_item->grademax); 170 171 $status = $scale->is_used(); 172 173 $this->assertTrue($status); 174 175 } 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body