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 * Test restore logic. 19 * 20 * @package qtype_essay 21 * @copyright 2019 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 global $CFG; 28 require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php"); 29 30 /** 31 * Test restore logic. 32 * 33 * @copyright 2019 The Open University 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class qtype_essay_restore_testcase extends restore_date_testcase { 37 38 /** 39 * Test missing qtype_essay_options creation. 40 * 41 * Old backup files may contain essays with no qtype_essay_options record. 42 * During restore, we add default options for any questions like that. 43 * That is what is tested in this file. 44 */ 45 public function test_restore_create_missing_qtype_essay_options() { 46 global $DB; 47 48 // Create a course with one essay question in its question bank. 49 $generator = $this->getDataGenerator(); 50 $course = $generator->create_course(); 51 $contexts = new question_edit_contexts(context_course::instance($course->id)); 52 $category = question_make_default_categories($contexts->all()); 53 $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); 54 $essay = $questiongenerator->create_question('essay', null, array('category' => $category->id)); 55 56 // Remove the options record, which means that the backup will look like a backup made in an old Moodle. 57 $DB->delete_records('qtype_essay_options', ['questionid' => $essay->id]); 58 59 // Do backup and restore. 60 $newcourseid = $this->backup_and_restore($course); 61 62 // Verify that the restored question has options. 63 $contexts = new question_edit_contexts(context_course::instance($newcourseid)); 64 $newcategory = question_make_default_categories($contexts->all()); 65 $newessay = $DB->get_record('question', ['category' => $newcategory->id, 'qtype' => 'essay']); 66 $this->assertTrue($DB->record_exists('qtype_essay_options', ['questionid' => $newessay->id])); 67 } 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body