MDL-55609 mod_assign: Remove shared setUp for all tests
[moodle.git] / mod / assign / tests / upgradelib_test.php
blob517d0ef38cc111ace65272e6e6366e6338dec493
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.
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.
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
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');
34 /**
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 {
42 /**
43 * Data provider for assignment upgrade.
45 * @return array
47 public function assignment_upgrade_provider() {
48 return [
49 'upload' => [
50 'type' => 'upload',
51 'submissionplugins' => [
52 'onlinetext' => true,
53 'comments' => true,
54 'file' => false,
56 'feedbackplugins' => [
57 'comments' => false,
58 'file' => false,
59 'offline' => true,
62 'uploadsingle' => [
63 'type' => 'uploadsingle',
64 'submissionplugins' => [
65 'onlinetext' => true,
66 'comments' => true,
67 'file' => false,
69 'feedbackplugins' => [
70 'comments' => false,
71 'file' => false,
72 'offline' => true,
75 'online' => [
76 'type' => 'online',
77 'submissionplugins' => [
78 'onlinetext' => false,
79 'comments' => true,
80 'file' => true,
82 'feedbackplugins' => [
83 'comments' => false,
84 'file' => true,
85 'offline' => true,
88 'offline' => [
89 'type' => 'offline',
90 'submissionplugins' => [
91 'onlinetext' => true,
92 'comments' => true,
93 'file' => true,
95 'feedbackplugins' => [
96 'comments' => false,
97 'file' => true,
98 'offline' => true,
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) {
112 global $DB, $CFG;
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,
133 // Run the upgrade.
134 $this->setAdminUser();
135 $log = '';
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()));