Línea 33... |
Línea 33... |
33 |
*
|
33 |
*
|
34 |
* @package core_course
|
34 |
* @package core_course
|
35 |
* @copyright 2016 Frédéric Massart - FMCorz.net
|
35 |
* @copyright 2016 Frédéric Massart - FMCorz.net
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
37 |
*/
|
37 |
*/
|
38 |
class restore_test extends \advanced_testcase {
|
38 |
final class restore_test extends \advanced_testcase {
|
Línea 39... |
Línea 39... |
39 |
|
39 |
|
40 |
/**
|
40 |
/**
|
41 |
* Backup a course and return its backup ID.
|
41 |
* Backup a course and return its backup ID.
|
42 |
*
|
42 |
*
|
Línea 223... |
Línea 223... |
223 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
223 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
224 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
224 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
Línea 225... |
Línea 225... |
225 |
|
225 |
|
Línea 226... |
Línea 226... |
226 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
226 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
- |
|
227 |
|
227 |
|
228 |
// Create two courses with different start dates, in each course create an assignment
|
228 |
// Create two courses with different start dates,in each course create a chat that opens 1 week after the course start date.
|
229 |
// that is due 1 week after the course start date.
|
- |
|
230 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
229 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
231 |
'startdate' => $startdate]);
|
- |
|
232 |
$assign1 = $dg->create_module('assign',
|
230 |
'startdate' => $startdate]);
|
233 |
['name' => 'First', 'course' => $c1->id, 'duedate' => $c1->startdate + 1 * WEEKSECS]
|
231 |
$chat1 = $dg->create_module('chat', ['name' => 'First', 'course' => $c1->id, 'chattime' => $c1->startdate + 1 * WEEKSECS]);
|
234 |
);
|
- |
|
235 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
232 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
236 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
- |
|
237 |
$assign2 = $dg->create_module('assign',
|
233 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
238 |
['name' => 'Second', 'course' => $c2->id, 'duedate' => $c2->startdate + 1 * WEEKSECS]
|
Línea 234... |
Línea 239... |
234 |
$chat2 = $dg->create_module('chat', ['name' => 'Second', 'course' => $c2->id, 'chattime' => $c2->startdate + 1 * WEEKSECS]);
|
239 |
);
|
235 |
$backupid = $this->backup_course($c1->id);
|
240 |
$backupid = $this->backup_course($c1->id);
|
236 |
|
241 |
|
237 |
// The information is restored but adapted because names are already taken.
|
242 |
// The information is restored but adapted because names are already taken.
|
238 |
$c2 = $this->async_restore_to_existing_course($backupid, $c2->id);
|
243 |
$c2 = $this->async_restore_to_existing_course($backupid, $c2->id);
|
239 |
$this->assertEquals('SN_1', $c2->shortname);
|
244 |
$this->assertEquals('SN_1', $c2->shortname);
|
240 |
$this->assertEquals('FN copy 1', $c2->fullname);
|
245 |
$this->assertEquals('FN copy 1', $c2->fullname);
|
Línea 241... |
Línea 246... |
241 |
$this->assertEquals('DESC', $c2->summary);
|
246 |
$this->assertEquals('DESC', $c2->summary);
|
242 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
247 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
243 |
$this->assertEquals($startdate, $c2->startdate);
|
248 |
$this->assertEquals($startdate, $c2->startdate);
|
244 |
|
249 |
|
245 |
// Now course c2 has two chats - one ('Second') was already there and one ('First') was restored from the backup.
|
250 |
// Now course c2 has two assignments - one ('Second') was already there and one ('First') was restored from the backup.
|
246 |
// Their dates are exactly the same as they were in the original modules.
|
251 |
// Their dates are exactly the same as they were in the original modules.
|
247 |
$restoredchat1 = $DB->get_record('chat', ['name' => 'First', 'course' => $c2->id]);
|
252 |
$restoredassign1 = $DB->get_record('assign', ['name' => 'First', 'course' => $c2->id]);
|
Línea 248... |
Línea 253... |
248 |
$restoredchat2 = $DB->get_record('chat', ['name' => 'Second', 'course' => $c2->id]);
|
253 |
$restoredassign2 = $DB->get_record('assign', ['name' => 'Second', 'course' => $c2->id]);
|
249 |
$this->assertEquals($chat1->chattime, $restoredchat1->chattime);
|
254 |
$this->assertEquals($assign1->duedate, $restoredassign1->duedate);
|
250 |
$this->assertEquals($chat2->chattime, $restoredchat2->chattime);
|
255 |
$this->assertEquals($assign2->duedate, $restoredassign2->duedate);
|
Línea 259... |
Línea 264... |
259 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
264 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
260 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
265 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
Línea 261... |
Línea 266... |
261 |
|
266 |
|
Línea 262... |
Línea 267... |
262 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
267 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
- |
|
268 |
|
263 |
|
269 |
// Create two courses with different start dates, in each course create an assignment
|
264 |
// Create two courses with different start dates,in each course create a chat that opens 1 week after the course start date.
|
270 |
// that is due 1 week after the course start date.
|
- |
|
271 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
265 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
272 |
'startdate' => $startdate]);
|
- |
|
273 |
$assign1 = $dg->create_module('assign',
|
266 |
'startdate' => $startdate]);
|
274 |
['name' => 'First', 'course' => $c1->id, 'duedate' => $c1->startdate + 1 * WEEKSECS]
|
267 |
$chat1 = $dg->create_module('chat', ['name' => 'First', 'course' => $c1->id, 'chattime' => $c1->startdate + 1 * WEEKSECS]);
|
275 |
);
|
- |
|
276 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
268 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
277 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
- |
|
278 |
$assign2 = $dg->create_module('assign',
|
269 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
279 |
['name' => 'Second', 'course' => $c2->id, 'duedate' => $c2->startdate + 1 * WEEKSECS]
|
Línea 270... |
Línea 280... |
270 |
$chat2 = $dg->create_module('chat', ['name' => 'Second', 'course' => $c2->id, 'chattime' => $c2->startdate + 1 * WEEKSECS]);
|
280 |
);
|
271 |
$backupid = $this->backup_course($c1->id);
|
281 |
$backupid = $this->backup_course($c1->id);
|
272 |
|
282 |
|
Línea 273... |
Línea 283... |
273 |
// The information is restored and the existing course settings is modified.
|
283 |
// The information is restored and the existing course settings is modified.
|
274 |
$c2 = $this->async_restore_to_existing_course($backupid, $c2->id, 2, backup::TARGET_CURRENT_DELETING);
|
284 |
$c2 = $this->async_restore_to_existing_course($backupid, $c2->id, 2, backup::TARGET_CURRENT_DELETING);
|
275 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
285 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
276 |
|
286 |
|
277 |
// Now course2 should have a new forum with the original forum deleted.
|
287 |
// Now course2 should have a new assignment with the original assignment deleted.
|
278 |
$restoredchat1 = $DB->get_record('chat', ['name' => 'First', 'course' => $c2->id]);
|
288 |
$restoredassign1 = $DB->get_record('assign', ['name' => 'First', 'course' => $c2->id]);
|
Línea 279... |
Línea 289... |
279 |
$restoredchat2 = $DB->get_record('chat', ['name' => 'Second', 'course' => $c2->id]);
|
289 |
$restoredassign2 = $DB->get_record('assign', ['name' => 'Second', 'course' => $c2->id]);
|
280 |
$this->assertEquals($chat1->chattime, $restoredchat1->chattime);
|
290 |
$this->assertEquals($assign1->duedate, $restoredassign1->duedate);
|
Línea 432... |
Línea 442... |
432 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
442 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_fullname'));
|
433 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
443 |
$this->assertEquals(1, get_config('restore', 'restore_merge_course_startdate'));
|
Línea 434... |
Línea 444... |
434 |
|
444 |
|
Línea 435... |
Línea 445... |
435 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
445 |
$startdate = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
- |
|
446 |
|
436 |
|
447 |
// Create two courses with different start dates,in each course create an assignment
|
437 |
// Create two courses with different start dates,in each course create a chat that opens 1 week after the course start date.
|
448 |
// that opens 1 week after the course start date.
|
- |
|
449 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
438 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
450 |
'startdate' => $startdate]);
|
- |
|
451 |
$assign1 = $dg->create_module('assign',
|
439 |
'startdate' => $startdate]);
|
452 |
['name' => 'First', 'course' => $c1->id, 'duedate' => $c1->startdate + 1 * WEEKSECS]
|
440 |
$chat1 = $dg->create_module('chat', ['name' => 'First', 'course' => $c1->id, 'chattime' => $c1->startdate + 1 * WEEKSECS]);
|
453 |
);
|
- |
|
454 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
441 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
455 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
- |
|
456 |
$assign2 = $dg->create_module('assign',
|
442 |
'startdate' => $startdate + 2 * WEEKSECS]);
|
457 |
['name' => 'Second', 'course' => $c2->id, 'duedate' => $c2->startdate + 1 * WEEKSECS]
|
Línea 443... |
Línea 458... |
443 |
$chat2 = $dg->create_module('chat', ['name' => 'Second', 'course' => $c2->id, 'chattime' => $c2->startdate + 1 * WEEKSECS]);
|
458 |
);
|
444 |
$backupid = $this->backup_course($c1->id);
|
459 |
$backupid = $this->backup_course($c1->id);
|
445 |
|
460 |
|
Línea 451... |
Línea 466... |
451 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
466 |
$this->assertEquals(FORMAT_MOODLE, $c2->summaryformat);
|
452 |
$this->assertEquals($startdate, $c2->startdate);
|
467 |
$this->assertEquals($startdate, $c2->startdate);
|
Línea 453... |
Línea 468... |
453 |
|
468 |
|
454 |
// Now course c2 has two chats - one ('Second') was already there and one ('First') was restored from the backup.
|
469 |
// Now course c2 has two chats - one ('Second') was already there and one ('First') was restored from the backup.
|
455 |
// Their dates are exactly the same as they were in the original modules.
|
470 |
// Their dates are exactly the same as they were in the original modules.
|
456 |
$restoredchat1 = $DB->get_record('chat', ['name' => 'First', 'course' => $c2->id]);
|
471 |
$restoredassign1 = $DB->get_record('assign', ['name' => 'First', 'course' => $c2->id]);
|
457 |
$restoredchat2 = $DB->get_record('chat', ['name' => 'Second', 'course' => $c2->id]);
|
472 |
$restoredassign2 = $DB->get_record('assign', ['name' => 'Second', 'course' => $c2->id]);
|
458 |
$this->assertEquals($chat1->chattime, $restoredchat1->chattime);
|
473 |
$this->assertEquals($assign1->duedate, $restoredassign1->duedate);
|
459 |
$this->assertEquals($chat2->chattime, $restoredchat2->chattime);
|
474 |
$this->assertEquals($assign2->duedate, $restoredassign2->duedate);
|
Línea 460... |
Línea 475... |
460 |
}
|
475 |
}
|
461 |
|
476 |
|
462 |
public function test_restore_course_shortname_in_existing_course_without_permissions(): void {
|
477 |
public function test_restore_course_shortname_in_existing_course_without_permissions(): void {
|
Línea 541... |
Línea 556... |
541 |
$manager = array_shift($managers);
|
556 |
$manager = array_shift($managers);
|
542 |
$roleid = $this->create_role_with_caps('moodle/restore:rolldates', CAP_PROHIBIT);
|
557 |
$roleid = $this->create_role_with_caps('moodle/restore:rolldates', CAP_PROHIBIT);
|
543 |
$dg->role_assign($manager->id, $u1->id);
|
558 |
$dg->role_assign($manager->id, $u1->id);
|
544 |
$dg->role_assign($roleid, $u1->id);
|
559 |
$dg->role_assign($roleid, $u1->id);
|
Línea 545... |
Línea 560... |
545 |
|
560 |
|
- |
|
561 |
// Create two courses with different start dates, in each course create an assignment that
|
546 |
// Create two courses with different start dates,in each course create a chat that opens 1 week after the course start date.
|
562 |
// is due 1 week after the course start date.
|
547 |
$startdate1 = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
563 |
$startdate1 = mktime(12, 0, 0, 7, 1, 2016); // 01-Jul-2016.
|
548 |
$startdate2 = mktime(12, 0, 0, 1, 13, 2000); // 13-Jan-2000.
|
564 |
$startdate2 = mktime(12, 0, 0, 1, 13, 2000); // 13-Jan-2000.
|
549 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
565 |
$c1 = $dg->create_course(['shortname' => 'SN', 'fullname' => 'FN', 'summary' => 'DESC', 'summaryformat' => FORMAT_MOODLE,
|
- |
|
566 |
'startdate' => $startdate1]);
|
550 |
'startdate' => $startdate1]);
|
567 |
$assign1 = $dg->create_module('assign',
|
- |
|
568 |
['name' => 'First', 'course' => $c1->id, 'duedate' => $c1->startdate + 1 * WEEKSECS]
|
551 |
$chat1 = $dg->create_module('chat', ['name' => 'First', 'course' => $c1->id, 'chattime' => $c1->startdate + 1 * WEEKSECS]);
|
569 |
);
|
552 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
570 |
$c2 = $dg->create_course(['shortname' => 'A', 'fullname' => 'B', 'summary' => 'C', 'summaryformat' => FORMAT_PLAIN,
|
- |
|
571 |
'startdate' => $startdate2]);
|
553 |
'startdate' => $startdate2]);
|
572 |
$assign2 = $dg->create_module('assign',
|
- |
|
573 |
['name' => 'Second', 'course' => $c2->id, 'duedate' => $c2->startdate + 1 * WEEKSECS]
|
Línea 554... |
Línea 574... |
554 |
$chat2 = $dg->create_module('chat', ['name' => 'Second', 'course' => $c2->id, 'chattime' => $c2->startdate + 1 * WEEKSECS]);
|
574 |
);
|
555 |
|
575 |
|
556 |
// The startdate does not change.
|
576 |
// The startdate does not change.
|
557 |
$backupid = $this->backup_course($c1->id);
|
577 |
$backupid = $this->backup_course($c1->id);
|
558 |
$restored = $this->restore_to_existing_course($backupid, $c2->id, $u1->id);
|
578 |
$restored = $this->restore_to_existing_course($backupid, $c2->id, $u1->id);
|
559 |
$this->assertEquals('SN_1', $restored->shortname);
|
579 |
$this->assertEquals('SN_1', $restored->shortname);
|
560 |
$this->assertEquals('FN copy 1', $restored->fullname);
|
580 |
$this->assertEquals('FN copy 1', $restored->fullname);
|
561 |
$this->assertEquals('DESC', $restored->summary);
|
581 |
$this->assertEquals('DESC', $restored->summary);
|
Línea 562... |
Línea 582... |
562 |
$this->assertEquals(FORMAT_MOODLE, $restored->summaryformat);
|
582 |
$this->assertEquals(FORMAT_MOODLE, $restored->summaryformat);
|
563 |
$this->assertEquals($startdate2, $restored->startdate);
|
583 |
$this->assertEquals($startdate2, $restored->startdate);
|
564 |
|
584 |
|
565 |
// Now course c2 has two chats - one ('Second') was already there and one ('First') was restored from the backup.
|
585 |
// Now course c2 has two assignments - one ('Second') was already there and one ('First') was restored from the backup.
|
566 |
// Start date of the restored chat ('First') was changed to be 1 week after the c2 start date.
|
586 |
// Start date of the restored assignment ('First') was changed to be 1 week after the c2 start date.
|
567 |
$restoredchat1 = $DB->get_record('chat', ['name' => 'First', 'course' => $c2->id]);
|
587 |
$restoredassign1 = $DB->get_record('assign', ['name' => 'First', 'course' => $c2->id]);
|
568 |
$restoredchat2 = $DB->get_record('chat', ['name' => 'Second', 'course' => $c2->id]);
|
588 |
$restoredassign2 = $DB->get_record('assign', ['name' => 'Second', 'course' => $c2->id]);
|
569 |
$this->assertNotEquals($chat1->chattime, $restoredchat1->chattime);
|
589 |
$this->assertNotEquals($assign1->duedate, $restoredassign1->duedate);
|
Línea 570... |
Línea 590... |
570 |
$this->assertEquals($chat2->chattime, $restoredchat2->chattime);
|
590 |
$this->assertEquals($assign2->duedate, $restoredassign2->duedate);
|
571 |
$this->assertEquals($c2->startdate + 1 * WEEKSECS, $restoredchat2->chattime);
|
591 |
$this->assertEquals($c2->startdate + 1 * WEEKSECS, $restoredassign2->duedate);
|
572 |
}
|
592 |
}
|
573 |
|
593 |
|
574 |
/**
|
594 |
/**
|
- |
|
595 |
* Tests course restore with editor in course format.
|
- |
|
596 |
*
|
575 |
* Tests course restore with editor in course format.
|
597 |
* @author Matthew Hilton
|
576 |
*
|
598 |
* @covers \core_courseformat\base
|
577 |
* @author Matthew Hilton
|
599 |
* @covers \backup_course_structure_step
|
Línea 578... |
Línea 600... |
578 |
* @covers \core_courseformat
|
600 |
* @covers \restore_course_structure_step
|