Permalink
Browse files

Merge branch 'wip-MDL-59308-master' of git://github.com/marinaglancy/…

…moodle
  • Loading branch information...
dmonllao committed Jun 27, 2017
2 parents 93c97fd + 70b6230 commit 1243fce158e03b46dd3827af56acb114267c172a
Showing with 30 additions and 1 deletion.
  1. +25 −0 calendar/tests/container_test.php
  2. +3 −1 course/lib.php
  3. +2 −0 mod/lesson/locallib.php
@@ -285,6 +285,31 @@ public function test_event_factory_unenrolled_user() {
$this->assertInstanceOf(event_interface::class, $factory->create_instance($event));
}
/**
* Test that when course module is deleted all events are also deleted.
*/
public function test_delete_module_delete_events() {
global $DB;
$user = $this->getDataGenerator()->create_user();
// Create the course we will be using.
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
foreach (core_component::get_plugin_list('mod') as $modname => $unused) {
$module = $this->getDataGenerator()->create_module($modname, ['course' => $course->id]);
// Create bunch of events of different type (user override, group override, module event).
$this->create_event(['userid' => $user->id, 'modulename' => $modname, 'instance' => $module->id]);
$this->create_event(['groupid' => $group->id, 'modulename' => $modname, 'instance' => $module->id]);
$this->create_event(['modulename' => $modname, 'instance' => $module->id]);
$this->create_event(['modulename' => $modname, 'instance' => $module->id, 'courseid' => $course->id]);
// Delete module and make sure all events are deleted.
course_delete_module($module->cmid);
$this->assertEmpty($DB->get_record('event', ['modulename' => $modname, 'instance' => $module->id]));
}
}
/**
* Test getting the event mapper.
*/
@@ -1205,8 +1205,10 @@ function course_delete_module($cmid, $async = false) {
// Delete events from calendar.
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
$coursecontext = context_course::instance($cm->course);
foreach($events as $event) {
$calendarevent = calendar_event::load($event->id);
$event->context = $coursecontext;
$calendarevent = calendar_event::load($event);
$calendarevent->delete();
}
}
@@ -1582,7 +1582,9 @@ public function delete() {
$DB->delete_records("lesson_timer", array("lessonid"=>$this->properties->id));
$DB->delete_records("lesson_branch", array("lessonid"=>$this->properties->id));
if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$this->properties->id))) {
$coursecontext = context_course::instance($cm->course);
foreach($events as $event) {
$event->context = $coursecontext;
$event = calendar_event::load($event);
$event->delete();
}

0 comments on commit 1243fce

Please sign in to comment.