Merge branch 'MDL-53537_m34v4' of https://github.com/sbourget/moodle

This commit is contained in:
Andrew Nicols 2017-08-16 08:46:55 +08:00
commit 34cf57f1d0
5 changed files with 182 additions and 0 deletions

View file

@ -1900,6 +1900,52 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEventContextNotUsed($event);
}
/**
* Test that triggering a course_backup_created event works as expected.
*/
public function test_course_backup_created_event() {
global $CFG;
// Get the necessary files to perform backup and restore.
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
$this->resetAfterTest();
// Set to admin user.
$this->setAdminUser();
// The user id is going to be 2 since we are the admin user.
$userid = 2;
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Create backup file and save it to the backup location.
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
$sink = $this->redirectEvents();
$bc->execute_plan();
// Capture the event.
$events = $sink->get_events();
$sink->close();
// Validate the event.
$event = array_pop($events);
$this->assertInstanceOf('\core\event\course_backup_created', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($bc->get_courseid(), $event->objectid);
$this->assertEquals(context_course::instance($bc->get_courseid())->id, $event->contextid);
$url = new moodle_url('/course/view.php', array('id' => $event->objectid));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
// Destroy the resource controller since we are done using it.
$bc->destroy();
}
/**
* Test that triggering a course_restored event works as expected.
*/