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_assign 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_assign 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_assign_restore_date_testcase extends restore_date_testcase { 38 39 /** 40 * Test restore dates. 41 */ 42 public function test_restore_dates() { 43 global $DB, $USER; 44 45 $record = ['cutoffdate' => 100, 'allowsubmissionsfromdate' => 100, 'duedate' => 100, 'timemodified' => 100]; 46 list($course, $assign) = $this->create_course_and_module('assign', $record); 47 $cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]); 48 $assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course); 49 $submission = $assignobj->get_user_submission($USER->id, true); 50 $grade = $assignobj->get_user_grade($USER->id, true); 51 52 // User override. 53 $override = (object)[ 54 'assignid' => $assign->id, 55 'groupid' => 0, 56 'userid' => $USER->id, 57 'sortorder' => 1, 58 'allowsubmissionsfromdate' => 100, 59 'duedate' => 200, 60 'cutoffdate' => 300 61 ]; 62 $DB->insert_record('assign_overrides', $override); 63 64 // Do backup and restore. 65 $newcourseid = $this->backup_and_restore($course); 66 $newassign = $DB->get_record('assign', ['course' => $newcourseid]); 67 68 $this->assertFieldsNotRolledForward($assign, $newassign, ['timemodified']); 69 $props = ['allowsubmissionsfromdate', 'duedate', 'cutoffdate']; 70 $this->assertFieldsRolledForward($assign, $newassign, $props); 71 72 $newsubmission = $DB->get_record('assign_submission', ['assignment' => $newassign->id]); 73 $newoverride = $DB->get_record('assign_overrides', ['assignid' => $newassign->id]); 74 $newgrade = $DB->get_record('assign_grades', ['assignment' => $newassign->id]); 75 76 // Assign submission time checks. 77 $this->assertEquals($submission->timecreated, $newsubmission->timecreated); 78 $this->assertEquals($submission->timemodified, $newsubmission->timemodified); 79 80 // Assign override time checks. 81 $diff = $this->get_diff(); 82 $this->assertEquals($override->duedate + $diff, $newoverride->duedate); 83 $this->assertEquals($override->cutoffdate + $diff, $newoverride->cutoffdate); 84 $this->assertEquals($override->allowsubmissionsfromdate + $diff, $newoverride->allowsubmissionsfromdate); 85 86 // Assign grade time checks. 87 $this->assertEquals($grade->timecreated, $newgrade->timecreated); 88 $this->assertEquals($grade->timemodified, $newgrade->timemodified); 89 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body