3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * Unit tests for grade_raw object.
29 * @author nicolas@moodle.com
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
34 if (!defined('MOODLE_INTERNAL')) {
35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
38 require_once($CFG->libdir
.'/simpletest/fixtures/gradetest.php');
40 class grade_grade_test
extends grade_test
{
42 function test_grade_grade_construct() {
43 $params = new stdClass();
45 $params->itemid
= $this->grade_items
[0]->id
;
47 $params->rawgrade
= 88;
48 $params->rawgrademax
= 110;
49 $params->rawgrademin
= 18;
51 $grade_grade = new grade_grade($params, false);
52 $this->assertEqual($params->itemid
, $grade_grade->itemid
);
53 $this->assertEqual($params->rawgrade
, $grade_grade->rawgrade
);
56 function test_grade_grade_insert() {
57 $grade_grade = new grade_grade();
58 $this->assertTrue(method_exists($grade_grade, 'insert'));
60 $grade_grade->itemid
= $this->grade_items
[0]->id
;
61 $grade_grade->userid
= 1;
62 $grade_grade->rawgrade
= 88;
63 $grade_grade->rawgrademax
= 110;
64 $grade_grade->rawgrademin
= 18;
66 // Check the grade_item's needsupdate variable first
67 $grade_grade->load_grade_item();
68 $this->assertFalse($grade_grade->grade_item
->needsupdate
);
70 $grade_grade->insert();
72 $last_grade_grade = end($this->grade_grades
);
74 $this->assertEqual($grade_grade->id
, $last_grade_grade->id +
1);
75 $this->assertFalse(empty($grade_grade->timecreated
));
76 $this->assertFalse(empty($grade_grade->timemodified
));
79 function test_grade_grade_update() {
80 $grade_grade = new grade_grade($this->grade_grades
[0]);
81 $this->assertTrue(method_exists($grade_grade, 'update'));
84 function test_grade_grade_fetch() {
85 $grade_grade = new grade_grade();
86 $this->assertTrue(method_exists($grade_grade, 'fetch'));
88 $grades = grade_grade
::fetch(array('id'=>$this->grade_grades
[0]->id
));
89 $this->assertEqual($this->grade_grades
[0]->id
, $grades->id
);
90 $this->assertEqual($this->grade_grades
[0]->rawgrade
, $grades->rawgrade
);
93 function test_grade_grade_fetch_all() {
94 $grade_grade = new grade_grade();
95 $this->assertTrue(method_exists($grade_grade, 'fetch_all'));
97 $grades = grade_grade
::fetch_all(array());
98 $this->assertEqual(count($this->grade_grades
), count($grades));
101 function test_grade_raw_update_feedback() {
105 function test_grade_raw_update_information() {
109 function test_grade_load_text() {
110 $grade_grade = new grade_grade($this->grade_grades
[0]);
111 $this->assertTrue(method_exists($grade_grade, 'load_text'));
112 $this->assertNull($grade_grade->grade_grade_text
);
113 $this->assertNotNull($grade_grade->load_text());
114 $this->assertNotNull($grade_grade->grade_grade_text
);
115 $this->assertEqual($this->grade_grades_text
[0]->id
, $grade_grade->grade_grade_text
->id
);
118 function test_grade_grade_load_grade_item() {
119 $grade_grade = new grade_grade($this->grade_grades
[0]);
120 $this->assertTrue(method_exists($grade_grade, 'load_grade_item'));
121 $this->assertNull($grade_grade->grade_item
);
122 $this->assertTrue($grade_grade->itemid
);
123 $this->assertNotNull($grade_grade->load_grade_item());
124 $this->assertNotNull($grade_grade->grade_item
);
125 $this->assertEqual($this->grade_items
[0]->id
, $grade_grade->grade_item
->id
);
129 function test_grade_grade_standardise_score() {
130 $this->assertEqual(4, round(grade_grade
::standardise_score(6, 0, 7, 0, 5)));
131 $this->assertEqual(40, grade_grade
::standardise_score(50, 30, 80, 0, 100));
135 function test_grade_grade_set_locked() {
136 $grade_item = new grade_item($this->grade_items
[0]);
137 $grade = new grade_grade($grade_item->get_final(1));
138 $this->assertTrue(method_exists($grade, 'set_locked'));
140 $this->assertTrue(empty($grade_item->locked
));
141 $this->assertTrue(empty($grade->locked
));
143 $this->assertTrue($grade->set_locked(true));
144 $this->assertFalse(empty($grade->locked
));
145 $this->assertTrue($grade->set_locked(false));
146 $this->assertTrue(empty($grade->locked
));
148 $this->assertTrue($grade_item->set_locked(true));
149 $grade = new grade_grade($grade_item->get_final(1));
151 $this->assertFalse(empty($grade->locked
));
152 $this->assertFalse($grade->set_locked(false));
154 $this->assertTrue($grade_item->set_locked(false));
155 $grade = new grade_grade($grade_item->get_final(1));
157 $this->assertTrue($grade->set_locked(false));
160 function test_grade_grade_is_locked() {
161 $grade = new grade_grade($this->grade_grades
[0]);
162 $this->assertTrue(method_exists($grade, 'is_locked'));
164 $this->assertFalse($grade->is_locked());
165 $grade->locked
= time();
166 $this->assertTrue($grade->is_locked());
169 function test_grade_grade_set_hidden() {
170 $grade_item = new grade_item($this->grade_items
[0]);
171 $grade = new grade_grade($grade_item->get_final(1));
172 $this->assertTrue(method_exists($grade, 'set_hidden'));
174 $this->assertEqual(0, $grade_item->hidden
);
175 $this->assertEqual(0, $grade->hidden
);
177 $grade->set_hidden(0);
178 $this->assertEqual(0, $grade->hidden
);
180 $grade->set_hidden(1);
181 $this->assertEqual(1, $grade->hidden
);
184 function test_grade_grade_is_hidden() {
185 $grade = new grade_grade($this->grade_grades
[0]);
186 $this->assertTrue(method_exists($grade, 'is_hidden'));
188 $this->assertFalse($grade->is_hidden());
190 $this->assertTrue($grade->is_hidden());
192 $grade->hidden
= time()-666;
193 $this->assertFalse($grade->is_hidden());
195 $grade->hidden
= time()+
666;
196 $this->assertTrue($grade->is_hidden());