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 date tests. 19 * 20 * @package mod_feedback 21 * @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com> 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 * Restore date tests. 32 * 33 * @package mod_feedback 34 * @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_feedback_restore_date_testcase extends restore_date_testcase { 38 39 public function test_restore_dates() { 40 global $DB, $USER; 41 42 $time = 10000; 43 list($course, $feedback) = $this->create_course_and_module('feedback', ['timeopen' => $time, 'timeclose' => $time]); 44 45 // Create response. 46 $response = new stdClass(); 47 $response->feedback = $feedback->id; 48 $response->userid = $USER->id; 49 $response->anonymous_response = FEEDBACK_ANONYMOUS_NO; 50 $response->timemodified = $time; 51 $completedid = $DB->insert_record('feedback_completed', $response); 52 $response = $DB->get_record('feedback_completed', array('id' => $completedid), '*', MUST_EXIST); 53 54 // Do backup and restore. 55 $newcourseid = $this->backup_and_restore($course); 56 $newfeedback = $DB->get_record('feedback', ['course' => $newcourseid]); 57 $newresponse = $DB->get_record('feedback_completed', ['feedback' => $newfeedback->id]); 58 59 $this->assertFieldsNotRolledForward($feedback, $newfeedback, ['timemodified']); 60 $props = ['timeopen', 'timeclose']; 61 $this->assertFieldsRolledForward($feedback, $newfeedback, $props); 62 $this->assertEquals($response->timemodified, $newresponse->timemodified); 63 } 64 65 /** 66 * Test that dependency for items is restored correctly. 67 */ 68 public function test_restore_item_dependency() { 69 global $DB; 70 // Create a course and a feedback activity. 71 $course = $this->getDataGenerator()->create_course(); 72 $feedback = $this->getDataGenerator()->create_module('feedback', array('course' => $course)); 73 $feedbackgenerator = $this->getDataGenerator()->get_plugin_generator('mod_feedback'); 74 75 // Create a couple of items which depend on each other. 76 $item1 = $feedbackgenerator->create_item_numeric($feedback); 77 $item2 = $feedbackgenerator->create_item_numeric($feedback, array('dependitem' => $item1->id)); 78 $DB->set_field('feedback_item', 'dependitem', $item2->id, ['id' => $item1->id]); 79 80 // Create one more item with fake/broken dependitem. 81 $item3 = $feedbackgenerator->create_item_numeric($feedback, array('dependitem' => 123456)); 82 83 // Backup and restore the course. 84 $restoredcourseid = $this->backup_and_restore($course); 85 $restoredfeedback = $DB->get_record('feedback', ['course' => $restoredcourseid]); 86 87 // Restored item1 and item2 are expected to be dependent the same way as the original ones. 88 $restoreditem1 = $DB->get_record('feedback_item', ['feedback' => $restoredfeedback->id, 'name' => $item1->name]); 89 $restoreditem2 = $DB->get_record('feedback_item', ['feedback' => $restoredfeedback->id, 'name' => $item2->name]); 90 $this->assertEquals($restoreditem2->id, $restoreditem1->dependitem); 91 $this->assertEquals($restoreditem1->id, $restoreditem2->dependitem); 92 93 // Restored item3 is expected to have an empty dependitem. 94 $restoreditem3 = $DB->get_record('feedback_item', ['feedback' => $restoredfeedback->id, 'name' => $item3->name]); 95 $this->assertEquals(0, $restoreditem3->dependitem); 96 } 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body