1 |
efrain |
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 |
*/
|
11 |
efrain |
37 |
public function test_restore_dates(): void {
|
1 |
efrain |
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 |
/**
|
|
|
87 |
* Test backup and restore of an assignment with non-default settings.
|
|
|
88 |
*/
|
11 |
efrain |
89 |
public function test_restore_settings(): void {
|
1 |
efrain |
90 |
global $DB;
|
|
|
91 |
$generator = $this->getDataGenerator();
|
|
|
92 |
$course = $generator->create_course(['startdate' => $this->startdate]);
|
|
|
93 |
$record = [
|
|
|
94 |
'course' => $course->id,
|
|
|
95 |
'name' => random_string(),
|
|
|
96 |
'intro' => random_string(),
|
|
|
97 |
'introformat' => FORMAT_MARKDOWN,
|
|
|
98 |
'alwaysshowdescription' => 1,
|
|
|
99 |
'submissiondrafts' => 1,
|
|
|
100 |
'sendnotifications' => 1,
|
|
|
101 |
'sendlatenotifications' => 1,
|
|
|
102 |
'sendstudentnotifications' => 0,
|
|
|
103 |
'duedate' => time() + 1,
|
|
|
104 |
'cutoffdate' => time(),
|
|
|
105 |
'gradingduedate' => time() + 2,
|
|
|
106 |
'allowsubmissionsfromdate' => time() - 1,
|
|
|
107 |
'grade' => 10,
|
|
|
108 |
'timemodified' => 100,
|
|
|
109 |
'completionsubmit' => 1,
|
|
|
110 |
'requiresubmissionstatement' => 1,
|
|
|
111 |
'teamsubmission' => 1,
|
|
|
112 |
'requireallteammemberssubmit' => 1,
|
|
|
113 |
'teamsubmissiongroupingid' => $generator->create_grouping(['courseid' => $course->id])->id,
|
|
|
114 |
'blindmarking' => 1,
|
|
|
115 |
'hidegrader' => 1,
|
|
|
116 |
'revealidentities' => 1,
|
|
|
117 |
'attemptreopenmethod' => 'manual',
|
|
|
118 |
'maxattempts' => 2,
|
|
|
119 |
'markingworkflow' => 1,
|
|
|
120 |
'markingallocation' => 1,
|
|
|
121 |
'markinganonymous' => 1,
|
|
|
122 |
'preventsubmissionnotingroup' => 1,
|
|
|
123 |
'activityeditor' => [
|
|
|
124 |
'text' => random_string(),
|
|
|
125 |
'format' => FORMAT_MARKDOWN,
|
|
|
126 |
],
|
|
|
127 |
'timelimit' => DAYSECS,
|
|
|
128 |
'submissionattachments' => 1,
|
|
|
129 |
];
|
|
|
130 |
$assign = $this->getDataGenerator()->create_module('assign', $record);
|
|
|
131 |
|
|
|
132 |
// Do backup and restore.
|
|
|
133 |
$newcourseid = $this->backup_and_restore($course, $this->startdate);
|
|
|
134 |
$newassign = $DB->get_record('assign', ['course' => $newcourseid]);
|
|
|
135 |
$newgrouping = $DB->get_record('groupings', ['courseid' => $newcourseid]);
|
|
|
136 |
|
|
|
137 |
// Verify that the settings of the restored assignment are correct.
|
|
|
138 |
foreach ($record as $setting => $value) {
|
|
|
139 |
$newsetting = $newassign->{$setting} ?? null;
|
|
|
140 |
switch ($setting) {
|
|
|
141 |
case 'course':
|
|
|
142 |
// Should match the new course.
|
|
|
143 |
$this->assertEquals($newcourseid, $newsetting);
|
|
|
144 |
break;
|
|
|
145 |
case 'teamsubmissiongroupingid':
|
|
|
146 |
// Should match the new grouping.
|
|
|
147 |
$this->assertEquals($newgrouping->id, $newsetting);
|
|
|
148 |
break;
|
|
|
149 |
case 'revealidentities':
|
|
|
150 |
// Reset to default for a restore without user data.
|
|
|
151 |
$this->assertEquals(0, $newsetting);
|
|
|
152 |
break;
|
|
|
153 |
case 'activityeditor':
|
|
|
154 |
$this->assertEquals($value['text'], $newassign->activity);
|
|
|
155 |
$this->assertEquals($value['format'], $newassign->activityformat);
|
|
|
156 |
break;
|
|
|
157 |
case 'timemodified':
|
|
|
158 |
$this->assertFieldsNotRolledForward($assign, $newassign, ['timemodified']);
|
|
|
159 |
break;
|
|
|
160 |
default:
|
|
|
161 |
// All other settings should match the original assignment.
|
|
|
162 |
$this->assertEquals($value, $newsetting, "Failed for '{$setting}'");
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|