Skip to content

Commit

Permalink
backup check
Browse files Browse the repository at this point in the history
  • Loading branch information
ewallah committed Aug 16, 2018
1 parent 0456160 commit b3ec8d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function get_action_icons(stdClass $instance) {
* @param stdClass $data
* @param stdClass $course
* @param int $oldid
* @SuppressWarnings(PHPMD.UnusedFormalParameter) */
*/
public function restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid) {
global $DB;
$para = ['courseid' => $data->courseid, 'enrol' => 'coursecompleted', 'customint1' => $data->customint1];
Expand All @@ -174,7 +174,7 @@ public function restore_instance(restore_enrolments_structure_step $step, stdCla
* @param stdClass $instance
* @param int $userid
* @param int $oldinstancestatus
* @SuppressWarnings(PHPMD.UnusedFormalParameter) */
*/
public function restore_user_enrolment(restore_enrolments_structure_step $step, $data, $instance, $userid, $oldinstancestatus) {
$this->enrol_user($instance, $userid, null, $data->timestart, $data->timeend, $data->status);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public function edit_instance_form($instance, MoodleQuickForm $mform, $context)
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK.
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter) */
*/
public function edit_instance_validation($data, $files, $instance, $context) {

global $DB;
Expand Down
42 changes: 41 additions & 1 deletion tests/coursecompleted_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ public function test_privacy() {
public function test_library() {
$plugin = enrol_get_plugin('coursecompleted');
$this->setAdminUser();
$this->asserttrue($plugin->can_add_instance($this->course1->id));
$this->assertEquals($plugin->get_name(), 'coursecompleted');
$this->assertEquals($plugin->get_config('enabled'), null);
$this->assertTrue($plugin->roles_protected());
$this->assertTrue($plugin->can_add_instance($this->course1->id));
$this->assertTrue($plugin->allow_unenrol($this->instance));
$this->assertTrue($plugin->allow_manage($this->instance));
$this->assertTrue($plugin->can_hide_show_instance($this->instance));
Expand All @@ -198,6 +201,12 @@ public function test_library() {
$plugin->get_description_text($this->instance));
$this->assertContains('Test course 2', $plugin->enrol_page_hook($this->instance));
$this->setUser($this->student);
$page = new moodle_page();
$page->set_context(context_course::instance($this->course1->id));
$page->set_course($this->course1);
$page->set_pagelayout('standard');
$page->set_pagetype('course-view');
$page->set_url('/enrol/index.php?id=' . $this->course1->id);
$this->assertfalse($plugin->can_add_instance($this->course1->id));
$this->assertfalse($plugin->allow_unenrol($this->instance));
$this->assertfalse($plugin->allow_manage($this->instance));
Expand All @@ -223,4 +232,35 @@ public function test_form() {
$mform = new MoodleQuickForm('searchform', 'POST', $page->url);
$plugin->edit_instance_form($this->instance, $mform, context_course::instance($this->course1->id));
}

/**
* Test backup.
*/
public function test_backup() {
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
$this->setAdminUser();
$ccompletion = new completion_completion(['course' => $this->course2->id, 'userid' => $this->student->id]);
$ccompletion->mark_complete(time());
$now = time();
while (($task = \core\task\manager::get_next_adhoc_task($now)) !== null) {
$task->execute();
\core\task\manager::adhoc_task_complete($task);
}
$bc = new backup_controller(backup::TYPE_1COURSE, $this->course1->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO,
backup::MODE_GENERAL, 2);
$bc->execute_plan();
$results = $bc->get_results();
$file = $results['backup_destination'];
$fp = get_file_packer('application/vnd.moodle.backup');
$filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
$file->extract_to_pathname($fp, $filepath);
$bc->destroy();
$rc = new restore_controller('test-restore-course-event', $this->course1->id, backup::INTERACTIVE_NO,
backup::MODE_GENERAL, 2, backup::TARGET_NEW_COURSE);
$rc->execute_precheck();
$rc->execute_plan();
$rc->destroy();
}
}

0 comments on commit b3ec8d8

Please sign in to comment.