2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Unit tests for (some of) mod/assign/upgradelib.php.
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
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');
35 * Unit tests for (some of) mod/assign/upgradelib.php.
37 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class mod_assign_upgradelib_testcase
extends advanced_testcase
{
43 * Data provider for assignment upgrade.
47 public function assignment_upgrade_provider() {
51 'submissionplugins' => [
56 'feedbackplugins' => [
63 'type' => 'uploadsingle',
64 'submissionplugins' => [
69 'feedbackplugins' => [
77 'submissionplugins' => [
78 'onlinetext' => false,
82 'feedbackplugins' => [
90 'submissionplugins' => [
95 'feedbackplugins' => [
105 * Test assigment upgrade.
107 * @dataProvider assignment_upgrade_provider
108 * @param string $type The type of assignment
109 * @param array $plugins Which plugins shuld or shoudl not be enabled
111 public function test_upgrade_assignment($type, $plugins) {
114 $this->resetAfterTest();
116 $course = $this->getDataGenerator()->create_course();
117 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
119 $commentconfig = false;
120 if (!empty($CFG->usecomments
)) {
121 $commentconfig = $CFG->usecomments
;
123 $CFG->usecomments
= false;
125 // Create the old assignment.
126 $this->setUser($teacher);
127 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
128 $assignment = $generator->create_instance([
129 'course' => $course->id
,
130 'assignmenttype' => $type,
134 $this->setAdminUser();
136 $upgrader = new assign_upgrade_manager();
138 $this->assertTrue($upgrader->upgrade_assignment($assignment->id
, $log));
139 $record = $DB->get_record('assign', ['course' => $course->id
]);
141 $cm = get_coursemodule_from_instance('assign', $record->id
);
142 $context = context_module
::instance($cm->id
);
144 $assign = new assign($context, $cm, $course);
146 foreach ($plugins as $plugin => $isempty) {
147 $plugin = $assign->get_submission_plugin_by_type($plugin);
148 $this->assertEquals($isempty, empty($plugin->is_enabled()));