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_text 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_text_test
extends grade_test
{
42 function test_grade_grade_text_construct() {
43 $params = new stdClass();
45 $params->gradeid
= $this->grade_grades
[0]->id
;
46 $params->information
= 'Thumbs down';
47 $params->informationformat
= FORMAT_PLAIN
;
48 $params->feedback
= 'Good, but not good enough..';
49 $params->feedbackformat
= FORMAT_PLAIN
;
51 $grade_grade_text = new grade_grade_text($params, false);
52 $this->assertEqual($params->gradeid
, $grade_grade_text->gradeid
);
53 $this->assertEqual($params->information
, $grade_grade_text->information
);
54 $this->assertEqual($params->informationformat
, $grade_grade_text->informationformat
);
55 $this->assertEqual($params->feedback
, $grade_grade_text->feedback
);
56 $this->assertEqual($params->feedbackformat
, $grade_grade_text->feedbackformat
);
59 function test_grade_grade_text_insert() {
62 $grade_grade_text = new grade_grade_text();
63 $this->assertTrue(method_exists($grade_grade_text, 'insert'));
65 $grade_grade_text->gradeid
= $this->grade_grades
[0]->id
;
66 $grade_grade_text->information
= 'Thumbs down';
67 $grade_grade_text->informationformat
= FORMAT_PLAIN
;
68 $grade_grade_text->feedback
= 'Good, but not good enough..';
69 $grade_grade_text->feedbackformat
= FORMAT_PLAIN
;
70 $grade_grade_text->usermodified
= $USER->id
;
72 $grade_grade_text->insert();
74 $last_grade_grade_text = end($this->grade_grades_text
);
76 $this->assertEqual($grade_grade_text->id
, $last_grade_grade_text->id +
1);
77 $this->assertFalse(empty($grade_grade_text->timecreated
));
78 $this->assertFalse(empty($grade_grade_text->timemodified
));
79 $this->assertEqual($USER->id
, $grade_grade_text->usermodified
);
82 function test_grade_grade_text_update() {
83 $grade_grade_text = new grade_grade_text($this->grade_grades_text
[0]);
84 $this->assertTrue(method_exists($grade_grade_text, 'update'));
86 $this->assertTrue($grade_grade_text->update(89));
87 $information = get_field('grade_grades_text', 'information', 'id', $this->grade_grades_text
[0]->id
);
88 $this->assertEqual($grade_grade_text->information
, $information);
91 function test_grade_grade_text_delete() {
92 $grade_grade_text = new grade_grade_text($this->grade_grades_text
[0]);
93 $this->assertTrue(method_exists($grade_grade_text, 'delete'));
95 $this->assertTrue($grade_grade_text->delete());
96 $this->assertFalse(get_record('grade_grades_text', 'id', $grade_grade_text->id
));
99 function test_grade_grade_text_fetch() {
100 $grade_grade_text = new grade_grade_text();
101 $this->assertTrue(method_exists($grade_grade_text, 'fetch'));
103 $grade_grade_text = grade_grade_text
::fetch(array('id'=>$this->grade_grades_text
[0]->id
));
104 $this->assertEqual($this->grade_grades_text
[0]->id
, $grade_grade_text->id
);
105 $this->assertEqual($this->grade_grades_text
[0]->information
, $grade_grade_text->information
);
108 function test_grade_grade_text_fetch_all() {
109 $grade_grade_text = new grade_grade_text();
110 $this->assertTrue(method_exists($grade_grade_text, 'fetch_all'));
112 $grade_grade_texts = grade_grade_text
::fetch_all(array());
113 $this->assertEqual(count($this->grade_grades_text
[0]), count($grade_grade_texts));