MDL-42084 Unit tests: Remove unnecessary 'clear time limit change' lines
[moodle.git] / mod / assign / tests / upgradelib_test.php
CommitLineData
47f48152
DW
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/>.
16
17/**
18 * Unit tests for (some of) mod/assign/upgradelib.php.
19 *
20 * @package mod_assign
21 * @category phpunit
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30require_once($CFG->dirroot . '/mod/assign/locallib.php');
31require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
32require_once($CFG->dirroot . '/mod/assignment/lib.php');
9c986ee0 33require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
47f48152
DW
34
35/**
36 * Unit tests for (some of) mod/assign/upgradelib.php.
37 *
38 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 */
9c986ee0 41class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
47f48152
DW
42
43 public function test_upgrade_upload_assignment() {
f159ad73 44 global $DB, $CFG;
45
46 $commentconfig = false;
47 if (!empty($CFG->usecomments)) {
48 $commentconfig = $CFG->usecomments;
49 }
50 $CFG->usecomments = false;
47f48152
DW
51
52 $this->setUser($this->editingteachers[0]);
53 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
54 $params = array('course'=>$this->course->id,
55 'assignmenttype'=>'upload');
56 $record = $generator->create_instance($params);
57
58 $assignment = new assignment_base($record->cmid);
59
60 $this->setAdminUser();
61 $log = '';
62 $upgrader = new assign_upgrade_manager();
63
64 $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
65 $record = $DB->get_record('assign', array('course'=>$this->course->id));
66
67 $cm = get_coursemodule_from_instance('assign', $record->id);
68 $context = context_module::instance($cm->id);
69
70 $assign = new assign($context, $cm, $this->course);
71
72 $plugin = $assign->get_submission_plugin_by_type('onlinetext');
73 $this->assertEmpty($plugin->is_enabled());
74 $plugin = $assign->get_submission_plugin_by_type('comments');
f518843d 75 $this->assertEmpty($plugin->is_enabled());
47f48152
DW
76 $plugin = $assign->get_submission_plugin_by_type('file');
77 $this->assertNotEmpty($plugin->is_enabled());
78 $plugin = $assign->get_feedback_plugin_by_type('comments');
79 $this->assertNotEmpty($plugin->is_enabled());
80 $plugin = $assign->get_feedback_plugin_by_type('file');
81 $this->assertNotEmpty($plugin->is_enabled());
82 $plugin = $assign->get_feedback_plugin_by_type('offline');
83 $this->assertEmpty($plugin->is_enabled());
84
f159ad73 85 $CFG->usecomments = $commentconfig;
18aaeef0 86 course_delete_module($cm->id);
47f48152
DW
87 }
88
89 public function test_upgrade_uploadsingle_assignment() {
f159ad73 90 global $DB, $CFG;
91
92 $commentconfig = false;
93 if (!empty($CFG->usecomments)) {
94 $commentconfig = $CFG->usecomments;
95 }
96 $CFG->usecomments = false;
47f48152
DW
97
98 $this->setUser($this->editingteachers[0]);
99 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
100 $params = array('course'=>$this->course->id,
101 'assignmenttype'=>'uploadsingle');
102 $record = $generator->create_instance($params);
103
104 $assignment = new assignment_base($record->cmid);
105
106 $this->setAdminUser();
107 $log = '';
108 $upgrader = new assign_upgrade_manager();
109
110 $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
111 $record = $DB->get_record('assign', array('course'=>$this->course->id));
112
113 $cm = get_coursemodule_from_instance('assign', $record->id);
114 $context = context_module::instance($cm->id);
115
116 $assign = new assign($context, $cm, $this->course);
117
118 $plugin = $assign->get_submission_plugin_by_type('onlinetext');
119 $this->assertEmpty($plugin->is_enabled());
120 $plugin = $assign->get_submission_plugin_by_type('comments');
121 $this->assertEmpty($plugin->is_enabled());
122 $plugin = $assign->get_submission_plugin_by_type('file');
123 $this->assertNotEmpty($plugin->is_enabled());
124 $plugin = $assign->get_feedback_plugin_by_type('comments');
125 $this->assertNotEmpty($plugin->is_enabled());
126 $plugin = $assign->get_feedback_plugin_by_type('file');
127 $this->assertNotEmpty($plugin->is_enabled());
128 $plugin = $assign->get_feedback_plugin_by_type('offline');
129 $this->assertEmpty($plugin->is_enabled());
130
f159ad73 131 $CFG->usecomments = $commentconfig;
18aaeef0 132 course_delete_module($cm->id);
47f48152
DW
133 }
134
135 public function test_upgrade_onlinetext_assignment() {
f159ad73 136 global $DB, $CFG;
137
138 $commentconfig = false;
139 if (!empty($CFG->usecomments)) {
140 $commentconfig = $CFG->usecomments;
141 }
142 $CFG->usecomments = false;
47f48152
DW
143
144 $this->setUser($this->editingteachers[0]);
145 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
146 $params = array('course'=>$this->course->id,
147 'assignmenttype'=>'online');
148 $record = $generator->create_instance($params);
149
150 $assignment = new assignment_base($record->cmid);
151
152 $this->setAdminUser();
153 $log = '';
154 $upgrader = new assign_upgrade_manager();
155
156 $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
157 $record = $DB->get_record('assign', array('course'=>$this->course->id));
158
159 $cm = get_coursemodule_from_instance('assign', $record->id);
160 $context = context_module::instance($cm->id);
161
162 $assign = new assign($context, $cm, $this->course);
163
164 $plugin = $assign->get_submission_plugin_by_type('onlinetext');
165 $this->assertNotEmpty($plugin->is_enabled());
166 $plugin = $assign->get_submission_plugin_by_type('comments');
167 $this->assertEmpty($plugin->is_enabled());
168 $plugin = $assign->get_submission_plugin_by_type('file');
169 $this->assertEmpty($plugin->is_enabled());
170 $plugin = $assign->get_feedback_plugin_by_type('comments');
171 $this->assertNotEmpty($plugin->is_enabled());
172 $plugin = $assign->get_feedback_plugin_by_type('file');
173 $this->assertEmpty($plugin->is_enabled());
174 $plugin = $assign->get_feedback_plugin_by_type('offline');
175 $this->assertEmpty($plugin->is_enabled());
176
f159ad73 177 $CFG->usecomments = $commentconfig;
18aaeef0 178 course_delete_module($cm->id);
47f48152
DW
179 }
180
181 public function test_upgrade_offline_assignment() {
f159ad73 182 global $DB, $CFG;
183
184 $commentconfig = false;
185 if (!empty($CFG->usecomments)) {
186 $commentconfig = $CFG->usecomments;
187 }
188 $CFG->usecomments = false;
47f48152
DW
189
190 $this->setUser($this->editingteachers[0]);
191 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
192 $params = array('course'=>$this->course->id,
193 'assignmenttype'=>'offline');
194 $record = $generator->create_instance($params);
195
196 $assignment = new assignment_base($record->cmid);
197
198 $this->setAdminUser();
199 $log = '';
200 $upgrader = new assign_upgrade_manager();
201
202 $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
203 $record = $DB->get_record('assign', array('course'=>$this->course->id));
204
205 $cm = get_coursemodule_from_instance('assign', $record->id);
206 $context = context_module::instance($cm->id);
207
208 $assign = new assign($context, $cm, $this->course);
209
210 $plugin = $assign->get_submission_plugin_by_type('onlinetext');
211 $this->assertEmpty($plugin->is_enabled());
212 $plugin = $assign->get_submission_plugin_by_type('comments');
213 $this->assertEmpty($plugin->is_enabled());
214 $plugin = $assign->get_submission_plugin_by_type('file');
215 $this->assertEmpty($plugin->is_enabled());
216 $plugin = $assign->get_feedback_plugin_by_type('comments');
217 $this->assertNotEmpty($plugin->is_enabled());
218 $plugin = $assign->get_feedback_plugin_by_type('file');
219 $this->assertEmpty($plugin->is_enabled());
220 $plugin = $assign->get_feedback_plugin_by_type('offline');
221 $this->assertEmpty($plugin->is_enabled());
222
f159ad73 223 $CFG->usecomments = $commentconfig;
18aaeef0 224 course_delete_module($cm->id);
47f48152
DW
225 }
226}