Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / grade / simpletest / testgradegrades.php
blob3d338d186cf9d659f53e4e65d384589b816d6ce3
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // //
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. //
16 // //
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: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Unit tests for grade_raw object.
29 * @author nicolas@moodle.com
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31 * @package moodlecore
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;
46 $params->userid = 1;
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);
76 // timecreated will only be set if the grade was submitted by an activity module
77 $this->assertTrue(empty($grade_grade->timecreated));
78 // timemodified will only be set if the grade was submitted by an activity module
79 $this->assertTrue(empty($grade_grade->timemodified));
82 function test_grade_grade_update() {
83 $grade_grade = new grade_grade($this->grade_grades[0]);
84 $this->assertTrue(method_exists($grade_grade, 'update'));
87 function test_grade_grade_fetch() {
88 $grade_grade = new grade_grade();
89 $this->assertTrue(method_exists($grade_grade, 'fetch'));
91 $grades = grade_grade::fetch(array('id'=>$this->grade_grades[0]->id));
92 $this->assertEqual($this->grade_grades[0]->id, $grades->id);
93 $this->assertEqual($this->grade_grades[0]->rawgrade, $grades->rawgrade);
96 function test_grade_grade_fetch_all() {
97 $grade_grade = new grade_grade();
98 $this->assertTrue(method_exists($grade_grade, 'fetch_all'));
100 $grades = grade_grade::fetch_all(array());
101 $this->assertEqual(count($this->grade_grades), count($grades));
104 function test_grade_grade_load_grade_item() {
105 $grade_grade = new grade_grade($this->grade_grades[0]);
106 $this->assertTrue(method_exists($grade_grade, 'load_grade_item'));
107 $this->assertNull($grade_grade->grade_item);
108 $this->assertTrue($grade_grade->itemid);
109 $this->assertNotNull($grade_grade->load_grade_item());
110 $this->assertNotNull($grade_grade->grade_item);
111 $this->assertEqual($this->grade_items[0]->id, $grade_grade->grade_item->id);
115 function test_grade_grade_standardise_score() {
116 $this->assertEqual(4, round(grade_grade::standardise_score(6, 0, 7, 0, 5)));
117 $this->assertEqual(40, grade_grade::standardise_score(50, 30, 80, 0, 100));
122 * Disabling this test: the set_locked() arguments have been modified, rendering these tests useless until they are re-written
124 function test_grade_grade_set_locked() {
125 $grade_item = new grade_item($this->grade_items[0]);
126 $grade = new grade_grade($grade_item->get_final(1));
127 $this->assertTrue(method_exists($grade, 'set_locked'));
129 $this->assertTrue(empty($grade_item->locked));
130 $this->assertTrue(empty($grade->locked));
132 $this->assertTrue($grade->set_locked(true));
133 $this->assertFalse(empty($grade->locked));
134 $this->assertTrue($grade->set_locked(false));
135 $this->assertTrue(empty($grade->locked));
137 $this->assertTrue($grade_item->set_locked(true, true));
138 $grade = new grade_grade($grade_item->get_final(1));
140 $this->assertFalse(empty($grade->locked));
141 $this->assertFalse($grade->set_locked(true, false));
143 $this->assertTrue($grade_item->set_locked(true, false));
144 $grade = new grade_grade($grade_item->get_final(1));
146 $this->assertTrue($grade->set_locked(true, false));
150 function test_grade_grade_is_locked() {
151 $grade = new grade_grade($this->grade_grades[0]);
152 $this->assertTrue(method_exists($grade, 'is_locked'));
154 $this->assertFalse($grade->is_locked());
155 $grade->locked = time();
156 $this->assertTrue($grade->is_locked());
159 function test_grade_grade_set_hidden() {
160 $grade_item = new grade_item($this->grade_items[0]);
161 $grade = new grade_grade($grade_item->get_final(1));
162 $this->assertTrue(method_exists($grade, 'set_hidden'));
164 $this->assertEqual(0, $grade_item->hidden);
165 $this->assertEqual(0, $grade->hidden);
167 $grade->set_hidden(0);
168 $this->assertEqual(0, $grade->hidden);
170 $grade->set_hidden(1);
171 $this->assertEqual(1, $grade->hidden);
174 function test_grade_grade_is_hidden() {
175 $grade = new grade_grade($this->grade_grades[0]);
176 $this->assertTrue(method_exists($grade, 'is_hidden'));
178 $this->assertFalse($grade->is_hidden());
179 $grade->hidden = 1;
180 $this->assertTrue($grade->is_hidden());
182 $grade->hidden = time()-666;
183 $this->assertFalse($grade->is_hidden());
185 $grade->hidden = time()+666;
186 $this->assertTrue($grade->is_hidden());