[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); 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 */ 41 class mod_assign_upgradelib_testcase extends mod_assign_base_testcase { 42 43 public function test_upgrade_upload_assignment() { 44 global $DB, $CFG; 45 46 $commentconfig = false; 47 if (!empty($CFG->usecomments)) { 48 $commentconfig = $CFG->usecomments; 49 } 50 $CFG->usecomments = false; 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 $assignment = $generator->create_instance($params); 57 58 $this->setAdminUser(); 59 $log = ''; 60 $upgrader = new assign_upgrade_manager(); 61 62 $this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log)); 63 $record = $DB->get_record('assign', array('course'=>$this->course->id)); 64 65 $cm = get_coursemodule_from_instance('assign', $record->id); 66 $context = context_module::instance($cm->id); 67 68 $assign = new assign($context, $cm, $this->course); 69 70 $plugin = $assign->get_submission_plugin_by_type('onlinetext'); 71 $this->assertEmpty($plugin->is_enabled()); 72 $plugin = $assign->get_submission_plugin_by_type('comments'); 73 $this->assertEmpty($plugin->is_enabled()); 74 $plugin = $assign->get_submission_plugin_by_type('file'); 75 $this->assertNotEmpty($plugin->is_enabled()); 76 $plugin = $assign->get_feedback_plugin_by_type('comments'); 77 $this->assertNotEmpty($plugin->is_enabled()); 78 $plugin = $assign->get_feedback_plugin_by_type('file'); 79 $this->assertNotEmpty($plugin->is_enabled()); 80 $plugin = $assign->get_feedback_plugin_by_type('offline'); 81 $this->assertEmpty($plugin->is_enabled()); 82 83 $CFG->usecomments = $commentconfig; 84 course_delete_module($cm->id); 85 } 86 87 public function test_upgrade_uploadsingle_assignment() { 88 global $DB, $CFG; 89 90 $commentconfig = false; 91 if (!empty($CFG->usecomments)) { 92 $commentconfig = $CFG->usecomments; 93 } 94 $CFG->usecomments = false; 95 96 $this->setUser($this->editingteachers[0]); 97 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment'); 98 $params = array('course'=>$this->course->id, 99 'assignmenttype'=>'uploadsingle'); 100 $assignment = $generator->create_instance($params); 101 102 $this->setAdminUser(); 103 $log = ''; 104 $upgrader = new assign_upgrade_manager(); 105 106 $this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log)); 107 $record = $DB->get_record('assign', array('course'=>$this->course->id)); 108 109 $cm = get_coursemodule_from_instance('assign', $record->id); 110 $context = context_module::instance($cm->id); 111 112 $assign = new assign($context, $cm, $this->course); 113 114 $plugin = $assign->get_submission_plugin_by_type('onlinetext'); 115 $this->assertEmpty($plugin->is_enabled()); 116 $plugin = $assign->get_submission_plugin_by_type('comments'); 117 $this->assertEmpty($plugin->is_enabled()); 118 $plugin = $assign->get_submission_plugin_by_type('file'); 119 $this->assertNotEmpty($plugin->is_enabled()); 120 $plugin = $assign->get_feedback_plugin_by_type('comments'); 121 $this->assertNotEmpty($plugin->is_enabled()); 122 $plugin = $assign->get_feedback_plugin_by_type('file'); 123 $this->assertNotEmpty($plugin->is_enabled()); 124 $plugin = $assign->get_feedback_plugin_by_type('offline'); 125 $this->assertEmpty($plugin->is_enabled()); 126 127 $CFG->usecomments = $commentconfig; 128 course_delete_module($cm->id); 129 } 130 131 public function test_upgrade_onlinetext_assignment() { 132 global $DB, $CFG; 133 134 $commentconfig = false; 135 if (!empty($CFG->usecomments)) { 136 $commentconfig = $CFG->usecomments; 137 } 138 $CFG->usecomments = false; 139 140 $this->setUser($this->editingteachers[0]); 141 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment'); 142 $params = array('course'=>$this->course->id, 143 'assignmenttype'=>'online'); 144 $assignment = $generator->create_instance($params); 145 146 $this->setAdminUser(); 147 $log = ''; 148 $upgrader = new assign_upgrade_manager(); 149 150 $this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log)); 151 $record = $DB->get_record('assign', array('course'=>$this->course->id)); 152 153 $cm = get_coursemodule_from_instance('assign', $record->id); 154 $context = context_module::instance($cm->id); 155 156 $assign = new assign($context, $cm, $this->course); 157 158 $plugin = $assign->get_submission_plugin_by_type('onlinetext'); 159 $this->assertNotEmpty($plugin->is_enabled()); 160 $plugin = $assign->get_submission_plugin_by_type('comments'); 161 $this->assertEmpty($plugin->is_enabled()); 162 $plugin = $assign->get_submission_plugin_by_type('file'); 163 $this->assertEmpty($plugin->is_enabled()); 164 $plugin = $assign->get_feedback_plugin_by_type('comments'); 165 $this->assertNotEmpty($plugin->is_enabled()); 166 $plugin = $assign->get_feedback_plugin_by_type('file'); 167 $this->assertEmpty($plugin->is_enabled()); 168 $plugin = $assign->get_feedback_plugin_by_type('offline'); 169 $this->assertEmpty($plugin->is_enabled()); 170 171 $CFG->usecomments = $commentconfig; 172 course_delete_module($cm->id); 173 } 174 175 public function test_upgrade_offline_assignment() { 176 global $DB, $CFG; 177 178 $commentconfig = false; 179 if (!empty($CFG->usecomments)) { 180 $commentconfig = $CFG->usecomments; 181 } 182 $CFG->usecomments = false; 183 184 $this->setUser($this->editingteachers[0]); 185 $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment'); 186 $params = array('course'=>$this->course->id, 187 'assignmenttype'=>'offline'); 188 $assignment = $generator->create_instance($params); 189 190 $this->setAdminUser(); 191 $log = ''; 192 $upgrader = new assign_upgrade_manager(); 193 194 $this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log)); 195 $record = $DB->get_record('assign', array('course'=>$this->course->id)); 196 197 $cm = get_coursemodule_from_instance('assign', $record->id); 198 $context = context_module::instance($cm->id); 199 200 $assign = new assign($context, $cm, $this->course); 201 202 $plugin = $assign->get_submission_plugin_by_type('onlinetext'); 203 $this->assertEmpty($plugin->is_enabled()); 204 $plugin = $assign->get_submission_plugin_by_type('comments'); 205 $this->assertEmpty($plugin->is_enabled()); 206 $plugin = $assign->get_submission_plugin_by_type('file'); 207 $this->assertEmpty($plugin->is_enabled()); 208 $plugin = $assign->get_feedback_plugin_by_type('comments'); 209 $this->assertNotEmpty($plugin->is_enabled()); 210 $plugin = $assign->get_feedback_plugin_by_type('file'); 211 $this->assertEmpty($plugin->is_enabled()); 212 $plugin = $assign->get_feedback_plugin_by_type('offline'); 213 $this->assertEmpty($plugin->is_enabled()); 214 215 $CFG->usecomments = $commentconfig; 216 course_delete_module($cm->id); 217 } 218 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |