MDL-32323 add grade tests
[moodle.git] / lib / grade / tests / grade_outcome_test.php
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/>.
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  */
24 defined('MOODLE_INTERNAL') || die();
26 require_once(__DIR__.'/fixtures/lib.php');
29 class grade_outcome_testcase extends grade_base_testcase {
31     public function test_grade_outcome() {
32         $this->sub_test_grade_outcome_construct();
33         $this->sub_test_grade_outcome_insert();
34         $this->sub_test_grade_outcome_update();
35         $this->sub_test_grade_outcome_delete();
36         //$this->sub_test_grade_outcome_fetch();
37         $this->sub_test_grade_outcome_fetch_all();
38     }
40     protected function sub_test_grade_outcome_construct() {
41         $params = new stdClass();
43         $params->courseid = $this->courseid;
44         $params->shortname = 'Team work';
46         $grade_outcome = new grade_outcome($params, false);
47         $this->assertEquals($params->courseid, $grade_outcome->courseid);
48         $this->assertEquals($params->shortname, $grade_outcome->shortname);
49     }
51     protected function sub_test_grade_outcome_insert() {
52         $grade_outcome = new grade_outcome();
53         $this->assertTrue(method_exists($grade_outcome, 'insert'));
55         $grade_outcome->courseid = $this->courseid;
56         $grade_outcome->shortname = 'tw';
57         $grade_outcome->fullname = 'Team work';
59         $grade_outcome->insert();
61         $last_grade_outcome = end($this->grade_outcomes);
63         $this->assertEquals($grade_outcome->id, $last_grade_outcome->id + 1);
64         $this->assertFalse(empty($grade_outcome->timecreated));
65         $this->assertFalse(empty($grade_outcome->timemodified));
66     }
68     protected function sub_test_grade_outcome_update() {
69         global $DB;
70         $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
71         $this->assertTrue(method_exists($grade_outcome, 'update'));
72         $grade_outcome->shortname = 'Team work';
73         $this->assertTrue($grade_outcome->update());
74         $shortname = $DB->get_field('grade_outcomes', 'shortname', array('id' => $this->grade_outcomes[0]->id));
75         $this->assertEquals($grade_outcome->shortname, $shortname);
76     }
78     protected function sub_test_grade_outcome_delete() {
79         global $DB;
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($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
85     }
87     protected function sub_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         $grade_outcome->load_scale();
93         $this->assertEquals($this->grade_outcomes[0]->id, $grade_outcome->id);
94         $this->assertEquals($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
96         $this->assertEquals($this->scale[2]->id, $grade_outcome->scale->id);
97     }
99     protected function sub_test_grade_outcome_fetch_all() {
100         $grade_outcome = new grade_outcome();
101         $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
103         $grade_outcomes = grade_outcome::fetch_all(array());
104         $this->assertEquals(count($this->grade_outcomes), count($grade_outcomes));
105     }