Commit 63245172 authored by Mark Nelson's avatar Mark Nelson
Browse files

MDL-40909 core_enrol: removed 'unenrol' add_to_log calls

Before each of these calls a call to unenrol_user() is made, which
triggers the event 'user_enrolment_deleted'. Nothing more is needed.
parent 50ac4392
......@@ -139,7 +139,6 @@ if ($canunenrol && optional_param('remove', false, PARAM_BOOL) && confirm_sesske
if (!empty($userstounassign)) {
foreach($userstounassign as $removeuser) {
$enrol_manual->unenrol_user($instance, $removeuser->id);
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
}
$potentialuserselector->invalidate_selected_users();
......
......@@ -49,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance));
if ($confirm and confirm_sesskey()) {
$plugin->unenrol_user($instance, $USER->id);
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere!
redirect(new moodle_url('/index.php'));
}
......
......@@ -49,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance));
if ($confirm and confirm_sesskey()) {
$plugin->unenrol_user($instance, $USER->id);
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
redirect(new moodle_url('/index.php'));
}
......
......@@ -49,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance));
if ($confirm and confirm_sesskey()) {
$plugin->unenrol_user($instance, $USER->id);
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere!
redirect(new moodle_url('/index.php'));
}
......
......@@ -316,4 +316,45 @@ class core_enrollib_testcase extends advanced_testcase {
$expectedlegacyeventdata->courseid = $course1->id;
$this->assertEventLegacyData($expectedlegacyeventdata, $event);
}
/**
* Test user_enrolment_deleted event.
*/
public function test_user_enrolment_deleted_event() {
global $DB;
$this->resetAfterTest(true);
$manualplugin = enrol_get_plugin('manual');
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$student = $DB->get_record('role', array('shortname' => 'student'));
$enrol = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
// Enrol user.
$manualplugin->enrol_user($enrol, $user->id, $student->id);
// Get the user enrolment information, used to validate legacy event data.
$dbuserenrolled = $DB->get_record('user_enrolments', array('userid' => $user->id));
// Unenrol user and capture event.
$sink = $this->redirectEvents();
$manualplugin->unenrol_user($enrol, $user->id);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
// Validate the event.
$this->assertInstanceOf('\core\event\user_enrolment_deleted', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals('user_unenrolled', $event->get_legacy_eventname());
$expectedlegacyeventdata = $dbuserenrolled;
$expectedlegacyeventdata->enrol = $manualplugin->get_name();
$expectedlegacyeventdata->courseid = $course->id;
$expectedlegacyeventdata->lastenrol = true;
$this->assertEventLegacyData($expectedlegacyeventdata, $event);
$expected = array($course->id, 'course', 'unenrol', '../enrol/users.php?id=' . $course->id, $course->id);
$this->assertEventLegacyLogData($expected, $event);
}
}
......@@ -95,6 +95,14 @@ class user_enrolment_deleted extends base {
return (object)$this->other['userenrolment'];
}
/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'course', 'unenrol', '../enrol/users.php?id=' . $this->courseid, $this->courseid);
}
/**
* Custom validation.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment