MDL-42084 Unit tests: Remove unnecessary 'clear time limit change' lines
[moodle.git] / mod / assign / tests / upgradelib_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  * 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  */
27 defined('MOODLE_INTERNAL') || die();
29 global $CFG;
30 require_once($CFG->dirroot . '/mod/assign/locallib.php');
31 require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
32 require_once($CFG->dirroot . '/mod/assignment/lib.php');
33 require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
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  */
41 class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
43     public function test_upgrade_upload_assignment() {
44         global $DB, $CFG;
46         $commentconfig = false;
47         if (!empty($CFG->usecomments)) {
48             $commentconfig = $CFG->usecomments;
49         }
50         $CFG->usecomments = false;
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);
58         $assignment = new assignment_base($record->cmid);
60         $this->setAdminUser();
61         $log = '';
62         $upgrader = new assign_upgrade_manager();
64         $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
65         $record = $DB->get_record('assign', array('course'=>$this->course->id));
67         $cm = get_coursemodule_from_instance('assign', $record->id);
68         $context = context_module::instance($cm->id);
70         $assign = new assign($context, $cm, $this->course);
72         $plugin = $assign->get_submission_plugin_by_type('onlinetext');
73         $this->assertEmpty($plugin->is_enabled());
74         $plugin = $assign->get_submission_plugin_by_type('comments');
75         $this->assertEmpty($plugin->is_enabled());
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());
85         $CFG->usecomments = $commentconfig;
86         course_delete_module($cm->id);
87     }
89     public function test_upgrade_uploadsingle_assignment() {
90         global $DB, $CFG;
92         $commentconfig = false;
93         if (!empty($CFG->usecomments)) {
94             $commentconfig = $CFG->usecomments;
95         }
96         $CFG->usecomments = false;
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);
104         $assignment = new assignment_base($record->cmid);
106         $this->setAdminUser();
107         $log = '';
108         $upgrader = new assign_upgrade_manager();
110         $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
111         $record = $DB->get_record('assign', array('course'=>$this->course->id));
113         $cm = get_coursemodule_from_instance('assign', $record->id);
114         $context = context_module::instance($cm->id);
116         $assign = new assign($context, $cm, $this->course);
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());
131         $CFG->usecomments = $commentconfig;
132         course_delete_module($cm->id);
133     }
135     public function test_upgrade_onlinetext_assignment() {
136         global $DB, $CFG;
138         $commentconfig = false;
139         if (!empty($CFG->usecomments)) {
140             $commentconfig = $CFG->usecomments;
141         }
142         $CFG->usecomments = false;
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);
150         $assignment = new assignment_base($record->cmid);
152         $this->setAdminUser();
153         $log = '';
154         $upgrader = new assign_upgrade_manager();
156         $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
157         $record = $DB->get_record('assign', array('course'=>$this->course->id));
159         $cm = get_coursemodule_from_instance('assign', $record->id);
160         $context = context_module::instance($cm->id);
162         $assign = new assign($context, $cm, $this->course);
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());
177         $CFG->usecomments = $commentconfig;
178         course_delete_module($cm->id);
179     }
181     public function test_upgrade_offline_assignment() {
182         global $DB, $CFG;
184         $commentconfig = false;
185         if (!empty($CFG->usecomments)) {
186             $commentconfig = $CFG->usecomments;
187         }
188         $CFG->usecomments = false;
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);
196         $assignment = new assignment_base($record->cmid);
198         $this->setAdminUser();
199         $log = '';
200         $upgrader = new assign_upgrade_manager();
202         $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
203         $record = $DB->get_record('assign', array('course'=>$this->course->id));
205         $cm = get_coursemodule_from_instance('assign', $record->id);
206         $context = context_module::instance($cm->id);
208         $assign = new assign($context, $cm, $this->course);
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());
223         $CFG->usecomments = $commentconfig;
224         course_delete_module($cm->id);
225     }