PageRenderTime 27ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/MoodleWebRole/lib/grade/simpletest/testgradegrades.php

#
PHP | 191 lines | 94 code | 37 blank | 60 comment | 1 complexity | 6782657b74a08eb072b71875c1ef8e35 MD5 | raw file
  1<?php // $Id: testgradegrades.php,v 1.4.2.2 2008/03/27 17:13:01 nicolasconnault Exp $
  2
  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///////////////////////////////////////////////////////////////////////////
 25
 26/**
 27 * Unit tests for grade_raw object.
 28 *
 29 * @author nicolas@moodle.com
 30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 31 * @package moodlecore
 32 */
 33
 34if (!defined('MOODLE_INTERNAL')) {
 35    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
 36}
 37
 38require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
 39
 40class grade_grade_test extends grade_test {
 41
 42    function test_grade_grade_construct() {
 43        $params = new stdClass();
 44
 45        $params->itemid = $this->grade_items[0]->id;
 46        $params->userid = 1;
 47        $params->rawgrade = 88;
 48        $params->rawgrademax = 110;
 49        $params->rawgrademin = 18;
 50
 51        $grade_grade = new grade_grade($params, false);
 52        $this->assertEqual($params->itemid, $grade_grade->itemid);
 53        $this->assertEqual($params->rawgrade, $grade_grade->rawgrade);
 54    }
 55
 56    function test_grade_grade_insert() {
 57        $grade_grade = new grade_grade();
 58        $this->assertTrue(method_exists($grade_grade, 'insert'));
 59
 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;
 65
 66        // Check the grade_item's needsupdate variable first
 67        $grade_grade->load_grade_item();
 68        $this->assertFalse($grade_grade->grade_item->needsupdate);
 69
 70        $grade_grade->insert();
 71
 72        $last_grade_grade = end($this->grade_grades);
 73
 74        $this->assertEqual($grade_grade->id, $last_grade_grade->id + 1);
 75
 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));
 80    }
 81
 82    function test_grade_grade_update() {
 83        $grade_grade = new grade_grade($this->grade_grades[0]);
 84        $this->assertTrue(method_exists($grade_grade, 'update'));
 85    }
 86
 87    function test_grade_grade_fetch() {
 88        $grade_grade = new grade_grade();
 89        $this->assertTrue(method_exists($grade_grade, 'fetch'));
 90
 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);
 94    }
 95
 96    function test_grade_grade_fetch_all() {
 97        $grade_grade = new grade_grade();
 98        $this->assertTrue(method_exists($grade_grade, 'fetch_all'));
 99
100        $grades = grade_grade::fetch_all(array());
101        $this->assertEqual(count($this->grade_grades), count($grades));
102    }
103
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);
112    }
113
114
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));
118    }
119
120    
121    /*
122     * Disabling this test: the set_locked() arguments have been modified, rendering these tests useless until they are re-written
123
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'));
128
129        $this->assertTrue(empty($grade_item->locked));
130        $this->assertTrue(empty($grade->locked));
131
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));
136
137        $this->assertTrue($grade_item->set_locked(true, true));
138        $grade = new grade_grade($grade_item->get_final(1));
139
140        $this->assertFalse(empty($grade->locked));
141        $this->assertFalse($grade->set_locked(true, false));
142
143        $this->assertTrue($grade_item->set_locked(true, false));
144        $grade = new grade_grade($grade_item->get_final(1));
145
146        $this->assertTrue($grade->set_locked(true, false));
147    }
148    */
149
150    function test_grade_grade_is_locked() {
151        $grade = new grade_grade($this->grade_grades[0]);
152        $this->assertTrue(method_exists($grade, 'is_locked'));
153
154        $this->assertFalse($grade->is_locked());
155        $grade->locked = time();
156        $this->assertTrue($grade->is_locked());
157    }
158
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'));
163
164        $this->assertEqual(0, $grade_item->hidden);
165        $this->assertEqual(0, $grade->hidden);
166
167        $grade->set_hidden(0);
168        $this->assertEqual(0, $grade->hidden);
169
170        $grade->set_hidden(1);
171        $this->assertEqual(1, $grade->hidden);
172    }
173
174    function test_grade_grade_is_hidden() {
175        $grade = new grade_grade($this->grade_grades[0]);
176        $this->assertTrue(method_exists($grade, 'is_hidden'));
177
178        $this->assertFalse($grade->is_hidden());
179        $grade->hidden = 1;
180        $this->assertTrue($grade->is_hidden());
181
182        $grade->hidden = time()-666;
183        $this->assertFalse($grade->is_hidden());
184
185        $grade->hidden = time()+666;
186        $this->assertTrue($grade->is_hidden());
187    }
188
189
190}
191?>