Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Restore override tests. 19 * 20 * @package mod_quiz 21 * @author 2019 Nathan Nguyen <nathannguyen@catalyst-au.net> 22 * @copyright Catalyst IT 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php"); 30 /** 31 * Restore override tests. 32 * 33 * @package mod_quiz 34 * @author 2019 Nathan Nguyen <nathannguyen@catalyst-au.net> 35 * @copyright Catalyst IT 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class mod_quiz_restore_override_testcase extends restore_date_testcase { 39 40 /** 41 * Test restore overrides. 42 */ 43 public function test_restore_overrides() { 44 global $DB, $USER; 45 $this->resetAfterTest(); 46 47 $course = $this->getDataGenerator()->create_course(); 48 $quizgen = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); 49 $quiz = $quizgen->create_instance(['course' => $course->id]); 50 51 $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); 52 $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); 53 54 $now = 100; 55 56 // Group overrides. 57 $groupoverride1 = (object)[ 58 'quiz' => $quiz->id, 59 'groupid' => $group1->id, 60 'timeopen' => $now, 61 'timeclose' => $now + 20 62 ]; 63 $DB->insert_record('quiz_overrides', $groupoverride1); 64 65 $groupoverride2 = (object)[ 66 'quiz' => $quiz->id, 67 'groupid' => $group2->id, 68 'timeopen' => $now, 69 'timeclose' => $now + 40 70 ]; 71 $DB->insert_record('quiz_overrides', $groupoverride2); 72 73 // Current quiz overrides. 74 $overrides = $DB->get_records('quiz_overrides', ['quiz' => $quiz->id]); 75 $this->assertEquals(2, count($overrides)); 76 77 // User Override. 78 $useroverride = (object)[ 79 'quiz' => $quiz->id, 80 'userid' => $USER->id, 81 'sortorder' => 1, 82 'timeopen' => 100, 83 'timeclose' => 200 84 ]; 85 $DB->insert_record('quiz_overrides', $useroverride); 86 87 // Current quiz overrides. 88 $overrides = $DB->get_records('quiz_overrides', ['quiz' => $quiz->id]); 89 $this->assertEquals(3, count($overrides)); 90 91 // Back up and restore including group info and user info. 92 set_config('backup_general_groups', 1, 'backup'); 93 $newcourseid = $this->backup_and_restore($course); 94 $newquiz = $DB->get_record('quiz', ['course' => $newcourseid]); 95 $overrides = $DB->get_records('quiz_overrides', ['quiz' => $newquiz->id]); 96 // 2 groups overrides and 1 user override. 97 $this->assertEquals(3, count($overrides)); 98 99 // Back up and restore with user info and without group info. 100 set_config('backup_general_groups', 0, 'backup'); 101 $newcourseid = $this->backup_and_restore($course); 102 $newquiz = $DB->get_record('quiz', ['course' => $newcourseid]); 103 $overrides = $DB->get_records('quiz_overrides', ['quiz' => $newquiz->id]); 104 // 1 user override. 105 $this->assertEquals(1, count($overrides)); 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body