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_outcome 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_outcome_test
extends grade_test
{
42 function test_grade_outcome_construct() {
43 $params = new stdClass();
45 $params->courseid
= $this->courseid
;
46 $params->shortname
= 'Team work';
48 $grade_outcome = new grade_outcome($params, false);
49 $this->assertEqual($params->courseid
, $grade_outcome->courseid
);
50 $this->assertEqual($params->shortname
, $grade_outcome->shortname
);
53 function test_grade_outcome_insert() {
54 $grade_outcome = new grade_outcome();
55 $this->assertTrue(method_exists($grade_outcome, 'insert'));
57 $grade_outcome->courseid
= $this->courseid
;
58 $grade_outcome->shortname
= 'tw';
59 $grade_outcome->fullname
= 'Team work';
61 $grade_outcome->insert();
63 $last_grade_outcome = end($this->grade_outcomes
);
65 $this->assertEqual($grade_outcome->id
, $last_grade_outcome->id +
1);
66 $this->assertFalse(empty($grade_outcome->timecreated
));
67 $this->assertFalse(empty($grade_outcome->timemodified
));
70 function test_grade_outcome_update() {
71 $grade_outcome = new grade_outcome($this->grade_outcomes
[0]);
72 $this->assertTrue(method_exists($grade_outcome, 'update'));
73 $grade_outcome->shortname
= 'Team work';
74 $this->assertTrue($grade_outcome->update());
75 $shortname = get_field('grade_outcomes', 'shortname', 'id', $this->grade_outcomes
[0]->id
);
76 $this->assertEqual($grade_outcome->shortname
, $shortname);
79 function test_grade_outcome_delete() {
80 $grade_outcome = new grade_outcome($this->grade_outcomes
[0]);
81 $this->assertTrue(method_exists($grade_outcome, 'delete'));
83 $this->assertTrue($grade_outcome->delete());
84 $this->assertFalse(get_record('grade_outcomes', 'id', $grade_outcome->id
));
87 function test_grade_outcome_fetch() {
88 $grade_outcome = new grade_outcome();
89 $this->assertTrue(method_exists($grade_outcome, 'fetch'));
91 $grade_outcome = grade_outcome
::fetch(array('id'=>$this->grade_outcomes
[0]->id
));
92 $this->assertEqual($this->grade_outcomes
[0]->id
, $grade_outcome->id
);
93 $this->assertEqual($this->grade_outcomes
[0]->shortname
, $grade_outcome->shortname
);
95 $this->assertEqual($this->scale
[2]->id
, $grade_outcome->scale
->id
);
98 function test_grade_outcome_fetch_all() {
99 $grade_outcome = new grade_outcome();
100 $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
102 $grade_outcomes = grade_outcome
::fetch_all(array());
103 $this->assertEqual(count($this->grade_outcomes
), count($grade_outcomes));