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 namespace mod_assign\backup; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->libdir . '/phpunit/classes/restore_date_testcase.php'); 23 require_once($CFG->dirroot . '/mod/assign/tests/fixtures/testable_assign.php'); 24 25 /** 26 * Restore date tests. 27 * 28 * @package mod_assign 29 * @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class restore_date_test extends \restore_date_testcase { 33 34 /** 35 * Test restore dates. 36 */ 37 public function test_restore_dates() { 38 global $DB, $USER; 39 40 $record = ['cutoffdate' => 100, 'allowsubmissionsfromdate' => 100, 'duedate' => 100, 'timemodified' => 100]; 41 list($course, $assign) = $this->create_course_and_module('assign', $record); 42 $cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]); 43 $assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course); 44 $submission = $assignobj->get_user_submission($USER->id, true); 45 $grade = $assignobj->get_user_grade($USER->id, true); 46 47 // User override. 48 $override = (object)[ 49 'assignid' => $assign->id, 50 'groupid' => 0, 51 'userid' => $USER->id, 52 'sortorder' => 1, 53 'allowsubmissionsfromdate' => 100, 54 'duedate' => 200, 55 'cutoffdate' => 300 56 ]; 57 $DB->insert_record('assign_overrides', $override); 58 59 // Do backup and restore. 60 $newcourseid = $this->backup_and_restore($course); 61 $newassign = $DB->get_record('assign', ['course' => $newcourseid]); 62 63 $this->assertFieldsNotRolledForward($assign, $newassign, ['timemodified']); 64 $props = ['allowsubmissionsfromdate', 'duedate', 'cutoffdate']; 65 $this->assertFieldsRolledForward($assign, $newassign, $props); 66 67 $newsubmission = $DB->get_record('assign_submission', ['assignment' => $newassign->id]); 68 $newoverride = $DB->get_record('assign_overrides', ['assignid' => $newassign->id]); 69 $newgrade = $DB->get_record('assign_grades', ['assignment' => $newassign->id]); 70 71 // Assign submission time checks. 72 $this->assertEquals($submission->timecreated, $newsubmission->timecreated); 73 $this->assertEquals($submission->timemodified, $newsubmission->timemodified); 74 75 // Assign override time checks. 76 $diff = $this->get_diff(); 77 $this->assertEquals($override->duedate + $diff, $newoverride->duedate); 78 $this->assertEquals($override->cutoffdate + $diff, $newoverride->cutoffdate); 79 $this->assertEquals($override->allowsubmissionsfromdate + $diff, $newoverride->allowsubmissionsfromdate); 80 81 // Assign grade time checks. 82 $this->assertEquals($grade->timecreated, $newgrade->timecreated); 83 $this->assertEquals($grade->timemodified, $newgrade->timemodified); 84 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body