Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]
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 27 defined('MOODLE_INTERNAL') || die(); 28 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 34 /** 35 * Unit tests for (some of) mod/assign/upgradelib.php. 36 * 37 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class mod_assign_upgradelib_testcase extends advanced_testcase { 41 42 /** 43 * Data provider for assignment upgrade. 44 * 45 * @return array 46 */ 47 public function assignment_upgrade_provider() { 48 return [ 49 'upload' => [ 50 'type' => 'upload', 51 'submissionplugins' => [ 52 'onlinetext' => true, 53 'comments' => true, 54 'file' => false, 55 ], 56 'feedbackplugins' => [ 57 'comments' => false, 58 'file' => false, 59 'offline' => true, 60 ], 61 ], 62 'uploadsingle' => [ 63 'type' => 'uploadsingle', 64 'submissionplugins' => [ 65 'onlinetext' => true, 66 'comments' => true, 67 'file' => false, 68 ], 69 'feedbackplugins' => [ 70 'comments' => false, 71 'file' => false, 72 'offline' => true, 73 ], 74 ], 75 'online' => [ 76 'type' => 'online', 77 'submissionplugins' => [ 78 'onlinetext' => false, 79 'comments' => true, 80 'file' => true, 81 ], 82 'feedbackplugins' => [ 83 'comments' => false, 84 'file' => true, 85 'offline' => true, 86 ], 87 ], 88 'offline' => [ 89 'type' => 'offline', 90 'submissionplugins' => [ 91 'onlinetext' => true, 92 'comments' => true, 93 'file' => true, 94 ], 95 'feedbackplugins' => [ 96 'comments' => false, 97 'file' => true, 98 'offline' => true, 99 ], 100 ], 101 ]; 102 } 103 104 /** 105 * Test assigment upgrade. 106 * 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 110 */ 111 public function test_upgrade_assignment($type, $plugins) { 112 global $DB, $CFG; 113 114 $this->resetAfterTest(); 115 116 $course = $this->getDataGenerator()->create_course(); 117 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); 118 119 $commentconfig = false; 120 if (!empty($CFG->usecomments)) { 121 $commentconfig = $CFG->usecomments; 122 } 123 $CFG->usecomments = false; 124 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, 131 ]); 132 133 // Run the upgrade. 134 $this->setAdminUser(); 135 $log = ''; 136 $upgrader = new assign_upgrade_manager(); 137 138 $this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log)); 139 $record = $DB->get_record('assign', ['course' => $course->id]); 140 141 $cm = get_coursemodule_from_instance('assign', $record->id); 142 $context = context_module::instance($cm->id); 143 144 $assign = new assign($context, $cm, $course); 145 146 foreach ($plugins as $plugin => $isempty) { 147 $plugin = $assign->get_submission_plugin_by_type($plugin); 148 $this->assertEquals($isempty, empty($plugin->is_enabled())); 149 } 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body