Merge branch 'wip-mdl-40044' of git://github.com/rajeshtaneja/moodle

This commit is contained in:
Dan Poltawski 2013-08-12 14:27:35 +08:00
commit 7064ef523b
15 changed files with 573 additions and 17 deletions

View File

@ -46,7 +46,22 @@ $controller = new $classformode[$mode]();
if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) {
$controller->process_submission();
$syscontext->mark_dirty();
add_to_log(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl), '', '', $USER->id);
$event = null;
// Create event depending on mode.
switch ($mode) {
case 'assign':
$event = \core\event\role_allow_assign_updated::create(array('context' => $syscontext));
break;
case 'override':
$event = \core\event\role_allow_override_updated::create(array('context' => $syscontext));
break;
case 'switch':
$event = \core\event\role_allow_switch_updated::create(array('context' => $syscontext));
break;
}
if ($event) {
$event->trigger();
}
redirect($baseurl);
}

View File

@ -110,8 +110,6 @@ if ($roleid) {
$potentialuserselector->invalidate_selected_users();
$currentuserselector->invalidate_selected_users();
$rolename = $assignableroles[$roleid];
add_to_log($course->id, 'role', 'assign', 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id);
// Counts have changed, so reload.
list($assignableroles, $assigncounts, $nameswithcounts) = get_assignable_roles($context, ROLENAME_BOTH, true);
}
@ -130,8 +128,6 @@ if ($roleid) {
$potentialuserselector->invalidate_selected_users();
$currentuserselector->invalidate_selected_users();
$rolename = $assignableroles[$roleid];
add_to_log($course->id, 'role', 'unassign', 'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id);
// Counts have changed, so reload.
list($assignableroles, $assigncounts, $nameswithcounts) = get_assignable_roles($context, ROLENAME_BOTH, true);
}

View File

@ -196,8 +196,22 @@ if (optional_param('cancel', false, PARAM_BOOL)) {
// Process submission in necessary.
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey() && $definitiontable->is_submission_valid()) {
$definitiontable->save_changes();
add_to_log(SITEID, 'role', $action, 'admin/roles/define.php?action=view&roleid=' .
$definitiontable->get_role_id(), $definitiontable->get_role_name(), '', $USER->id);
$tableroleid = $definitiontable->get_role_id();
// Trigger event.
$event = \core\event\role_capabilities_updated::create(
array(
'context' => $systemcontext,
'objectid' => $roleid,
'other' => array('name' => $definitiontable->get_role_name())
)
);
$event->set_legacy_logdata(array(SITEID, 'role', $action, 'admin/roles/define.php?action=view&roleid=' . $tableroleid,
$definitiontable->get_role_name(), '', $USER->id));
if (!empty($role)) {
$event->add_record_snapshot('role', $role);
}
$event->trigger();
if ($action === 'add') {
redirect(new moodle_url('/admin/roles/define.php', array('action'=>'view', 'roleid'=>$definitiontable->get_role_id())));
} else {

View File

@ -90,7 +90,6 @@ switch ($action) {
}
// Deleted a role sitewide...
$systemcontext->mark_dirty();
add_to_log(SITEID, 'role', 'delete', 'admin/roles/manage.php', $roles[$roleid]->localname, '', $USER->id);
redirect($baseurl);
break;

View File

@ -125,7 +125,25 @@ $overridestable->read_submitted_permissions();
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$overridestable->save_changes();
$rolename = $overridableroles[$roleid];
add_to_log($course->id, 'role', 'override', 'admin/roles/override.php?contextid='.$context->id.'&roleid='.$roleid, $rolename, '', $USER->id);
// Trigger event.
$event = \core\event\role_capabilities_updated::create(
array(
'context' => $context,
'objectid' => $roleid,
'courseid' => $courseid,
'other' => array('name' => $rolename)
)
);
$event->set_legacy_logdata(
array(
$course->id, 'role', 'override', 'admin/roles/override.php?contextid=' . $context->id . '&roleid=' . $roleid,
$rolename, '', $USER->id
)
);
$event->add_record_snapshot('role', $role);
$event->trigger();
redirect($returnurl);
}

View File

@ -181,7 +181,12 @@ $string['errorbadrolename'] = 'Incorrect role name';
$string['errorbadroleshortname'] = 'Incorrect role short name';
$string['errorexistsrolename'] = 'Role name already exists';
$string['errorexistsroleshortname'] = 'Role name already exists';
$string['eventroleallowassignupdated'] = 'Allow role assignment';
$string['eventroleallowoverrideupdated'] = 'Allow role override';
$string['eventroleallowswitchupdated'] = 'Allow role switch';
$string['eventroleassigned'] = 'Role assigned';
$string['eventrolecapabilitiesupdated'] = 'Role capabilities updated';
$string['eventroledeleted'] = 'Role deleted';
$string['eventroleunassigned'] = 'Role unassigned';
$string['existingadmins'] = 'Current site administrators';
$string['existingusers'] = '{$a} existing users';

View File

@ -1515,13 +1515,28 @@ function delete_role($roleid) {
$DB->delete_records('role_names', array('roleid'=>$roleid));
$DB->delete_records('role_context_levels', array('roleid'=>$roleid));
// finally delete the role itself
// get this before the name is gone for logging
$rolename = $DB->get_field('role', 'name', array('id'=>$roleid));
// Get role record before it's deleted.
$role = $DB->get_record('role', array('id'=>$roleid));
// Finally delete the role itself.
$DB->delete_records('role', array('id'=>$roleid));
add_to_log(SITEID, 'role', 'delete', 'admin/roles/action=delete&roleid='.$roleid, $rolename, '');
// Trigger event.
$event = \core\event\role_deleted::create(
array(
'context' => context_system::instance(),
'objectid' => $roleid,
'other' =>
array(
'name' => $role->name,
'shortname' => $role->shortname,
'description' => $role->description,
'archetype' => $role->archetype
)
)
);
$event->add_record_snapshot('role', $role);
$event->trigger();
return true;
}

View File

@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Event when role allow assignments is updated.
*
* @package core_event
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_allow_assign_updated extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['crud'] = 'u';
// TODO: MDL-41040 set level.
$this->data['level'] = 50;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventroleallowassignupdated', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Allow role assignments updated by user ' . $this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/roles/allow.php', array('mode' => 'assign'));
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
return array(SITEID, 'role', 'edit allow assign', 'admin/roles/allow.php?mode=assign');
}
}

View File

@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Event when role allow override is updated.
*
* @package core_event
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_allow_override_updated extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['crud'] = 'u';
// TODO: MDL-41040 set level.
$this->data['level'] = 50;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventroleallowoverrideupdated', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Allow role override updated by user ' . $this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/roles/allow.php', array('mode' => 'override'));
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
return array(SITEID, 'role', 'edit allow override', 'admin/roles/allow.php?mode=override');
}
}

View File

@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Event when role allow switch is updated.
*
* @package core_event
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_allow_switch_updated extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['crud'] = 'u';
// TODO: MDL-41040 set level.
$this->data['level'] = 50;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventroleallowswitchupdated', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Allow role switch updated by user ' . $this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/roles/allow.php', array('mode' => 'switch'));
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
return array(SITEID, 'role', 'edit allow switch', 'admin/roles/allow.php?mode=switch');
}
}

View File

@ -75,4 +75,16 @@ class role_assigned extends base {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('role_assignments', $this->data['other']['id']);
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
$roles = get_all_roles();
$rolenames = role_fix_names($roles, $this->get_context(), ROLENAME_ORIGINAL, true);
return array($this->courseid, 'role', 'assign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid,
$rolenames[$this->objectid], '', $this->userid);
}
}

View File

@ -0,0 +1,90 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Role updated event.
*
* @package core_event
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_capabilities_updated extends base {
/** @var array Legacy log data */
protected $legacylogdata = null;
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['objecttable'] = 'role';
$this->data['crud'] = 'u';
// TODO: MDL-41040 set level.
$this->data['level'] = 50;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventrolecapabilitiesupdated', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Capabilities for role ' . $this->objectid . ' are updated by user ' . $this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
if ($this->contextlevel === CONTEXT_SYSTEM) {
return new \moodle_url('admin/roles/define.php', array('action' => 'view', 'roleid' => $this->objectid));
} else {
return new \moodle_url('/admin/roles/override.php', array('contextid' => $this->contextid, 'roleid' => $this->objectid));
}
}
/**
* Sets legacy log data.
*
* @param array $legacylogdata
* @return void
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return null|array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}
}

View File

@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Role assigned event.
*
* @package core_event
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class role_deleted extends base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['objecttable'] = 'role';
$this->data['crud'] = 'd';
// TODO: MDL-41040 set level.
$this->data['level'] = 50;
}
/**
* Returns localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventroledeleted', 'role');
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Role ' . $this->objectid . ' is deleted by user ' . $this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/roles/manage.php');
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
return array(SITEID, 'role', 'delete', 'admin/roles/manage.php?action=delete&roleid='.$this->objectid, $this->other['shortname'], '');
}
}

View File

@ -75,4 +75,16 @@ class role_unassigned extends base {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('role_assignments', $this->data['other']['id']);
}
/**
* Returns array of parameters to be passed to legacy add_to_log() function.
*
* @return array
*/
protected function get_legacy_logdata() {
$roles = get_all_roles();
$rolenames = role_fix_names($roles, $this->get_context(), ROLENAME_ORIGINAL, true);
return array($this->courseid, 'role', 'unassign', 'admin/roles/assign.php?contextid='.$this->contextid.'&roleid='.$this->objectid,
$rolenames[$this->objectid], '', $this->userid);
}
}

View File

@ -398,6 +398,27 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($result);
$permission = $DB->get_record('role_capabilities', array('contextid'=>$frontcontext->id, 'roleid'=>$student->id, 'capability'=>'moodle/backup:backupcourse'));
$this->assertEmpty($permission);
// Test event trigger.
$rolecapabilityevent = \core\event\role_capabilities_updated::create(array('context' => $syscontext,
'objectid' => $student->id,
'other' => array('name' => $student->shortname)
));
$expectedlegacylog = array(SITEID, 'role', 'view', 'admin/roles/define.php?action=view&roleid=' . $student->id,
$student->shortname, '', $user->id);
$rolecapabilityevent->set_legacy_logdata($expectedlegacylog);
$rolecapabilityevent->add_record_snapshot('role', $student);
$sink = $this->redirectEvents();
$rolecapabilityevent->trigger();
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertInstanceOf('\core\event\role_capabilities_updated', $event);
$expectedurl = new moodle_url('admin/roles/define.php', array('action' => 'view', 'roleid' => $student->id));
$this->assertEquals($expectedurl, $event->get_url());
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
@ -487,13 +508,18 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertSame('', $event->other['component']);
$this->assertEquals(0, $event->other['itemid']);
$this->assertSame('role_assigned', $event::get_legacy_eventname());
$roles = get_all_roles();
$rolenames = role_fix_names($roles, $context, ROLENAME_ORIGINAL, true);
$expectedlegacylog = array($course->id, 'role', 'assign',
'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$role->id, $rolenames[$role->id], '', $USER->id);
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
* Test role unassigning.
*/
public function test_role_unassign() {
global $DB;
global $DB, $USER;
$this->resetAfterTest();
@ -530,6 +556,11 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertCount(3, $event->other);
$this->assertSame('', $event->other['component']);
$this->assertEquals(0, $event->other['itemid']);
$roles = get_all_roles();
$rolenames = role_fix_names($roles, $context, ROLENAME_ORIGINAL, true);
$expectedlegacylog = array($course->id, 'role', 'unassign',
'admin/roles/assign.php?contextid='.$context->id.'&roleid='.$role->id, $rolenames[$role->id], '', $USER->id);
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
@ -644,7 +675,13 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid'=>$role->id)));
$this->assertTrue($DB->record_exists('role_allow_override', array('allowoverride'=>$role->id)));
// Delete role and get event.
$sink = $this->redirectEvents();
$result = delete_role($role->id);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertTrue($result);
$this->assertFalse($DB->record_exists('role', array('id'=>$role->id)));
$this->assertFalse($DB->record_exists('role_assignments', array('roleid'=>$role->id)));
@ -655,6 +692,21 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('role_allow_assign', array('allowassign'=>$role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('roleid'=>$role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('allowoverride'=>$role->id)));
// Test triggered event.
$this->assertInstanceOf('\core\event\role_deleted', $event);
$this->assertSame('role', $event->target);
$this->assertSame('role', $event->objecttable);
$this->assertSame($role->id, $event->objectid);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertSame($role->name, $event->other['name']);
$this->assertSame($role->shortname, $event->other['shortname']);
$this->assertSame($role->description, $event->other['description']);
$this->assertSame($role->archetype, $event->other['archetype']);
$expectedlegacylog = array(SITEID, 'role', 'delete', 'admin/roles/manage.php?action=delete&roleid='.$role->id,
$role->shortname, '');
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
@ -884,7 +936,7 @@ class core_accesslib_testcase extends advanced_testcase {
* Test allowing of role assignments.
*/
public function test_allow_assign() {
global $DB;
global $DB, $CFG;
$this->resetAfterTest();
@ -894,13 +946,26 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('role_allow_assign', array('roleid'=>$otherid, 'allowassign'=>$student->id)));
allow_assign($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_assign', array('roleid'=>$otherid, 'allowassign'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_assign_updated::create(array('context' => context_system::instance()));
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertInstanceOf('\core\event\role_allow_assign_updated', $event);
$mode = 'assign';
$baseurl = new moodle_url('/admin/roles/allow.php', array('mode' => $mode));
$expectedlegacylog = array(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl));
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
* Test allowing of role overrides.
*/
public function test_allow_override() {
global $DB;
global $DB, $CFG;
$this->resetAfterTest();
@ -910,13 +975,26 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('role_allow_override', array('roleid'=>$otherid, 'allowoverride'=>$student->id)));
allow_override($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid'=>$otherid, 'allowoverride'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_override_updated::create(array('context' => context_system::instance()));
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertInstanceOf('\core\event\role_allow_override_updated', $event);
$mode = 'override';
$baseurl = new moodle_url('/admin/roles/allow.php', array('mode' => $mode));
$expectedlegacylog = array(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl));
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**
* Test allowing of role switching.
*/
public function test_allow_switch() {
global $DB;
global $DB, $CFG;
$this->resetAfterTest();
@ -926,6 +1004,19 @@ class core_accesslib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('role_allow_switch', array('roleid'=>$otherid, 'allowswitch'=>$student->id)));
allow_switch($otherid, $student->id);
$this->assertTrue($DB->record_exists('role_allow_switch', array('roleid'=>$otherid, 'allowswitch'=>$student->id)));
// Test event trigger.
$allowroleassignevent = \core\event\role_allow_switch_updated::create(array('context' => context_system::instance()));
$sink = $this->redirectEvents();
$allowroleassignevent->trigger();
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertInstanceOf('\core\event\role_allow_switch_updated', $event);
$mode = 'switch';
$baseurl = new moodle_url('/admin/roles/allow.php', array('mode' => $mode));
$expectedlegacylog = array(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl));
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
/**