Commit 7fd16ca1 authored by Damyon Wiese's avatar Damyon Wiese
Browse files

Merge branch 'w45_MDL-42602_m26_userloginevent' of https://github.com/skodak/moodle

parents fe484811 93b3aaf4
......@@ -246,12 +246,8 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->resetAfterTest();
$this->setAdminUser();
$user = clone($USER);
// The USER variable no longer stores the password hash, so set it here.
$user->password = 'password';
$this->assertFalse(isloggedin());
$user = $DB->get_record('user', array('username'=>'admin'));
// Note: we are just going to trigger the function that calls the event,
// not actually perform a LDAP login, for the sake of sanity.
......@@ -271,23 +267,6 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$events = $sink->get_events();
$sink->close();
// Unset the password now.
unset($user->password);
// Get the user from the DB and set the expected variables.
$dbuser = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
$user->firstaccess = (int) $dbuser->firstaccess;
$user->lastaccess = (int) $dbuser->lastaccess;
$user->currentlogin = (int) $dbuser->currentlogin;
$user->sesskey = sesskey();
$user->lastcourseaccess = array();
$user->currentcourseaccess = array();
$user->groupmember = array();
$user->profile = array();
$user->preference = array(
'_lastloaded' => time()
);
// Check that the event is valid.
$this->assertCount(2, $events);
$event = $events[0];
......@@ -297,7 +276,6 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->assertEquals('user', $event->objecttable);
$this->assertEquals('2', $event->objectid);
$this->assertEquals(context_system::instance()->id, $event->contextid);
$this->assertEquals($user, $event->get_record_snapshot('user', 2));
$expectedlog = array(SITEID, 'user', 'login', 'view.php?id=' . $USER->id . '&course=' . SITEID, $user->id,
0, $user->id);
$this->assertEventLegacyLogData($expectedlog, $event);
......
......@@ -4450,7 +4450,6 @@ function complete_user_login($user) {
'other' => array('username' => $USER->username),
)
);
$event->add_record_snapshot('user', $user);
$event->trigger();
if (isguestuser()) {
......
......@@ -2446,14 +2446,17 @@ class core_moodlelib_testcase extends advanced_testcase {
}
public function test_complete_user_login() {
global $USER;
global $USER, $DB;
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser(0);
$sink = $this->redirectEvents();
@complete_user_login($user); // Hide session header errors.
$loginuser = clone($user);
$this->setCurrentTimeStart();
@complete_user_login($loginuser); // Hide session header errors.
$this->assertSame($loginuser, $USER);
$this->assertEquals($user->id, $USER->id);
$events = $sink->get_events();
$sink->close();
......@@ -2466,7 +2469,21 @@ class core_moodlelib_testcase extends advanced_testcase {
$this->assertEquals('user', $event->objecttable);
$this->assertEquals($user->id, $event->objectid);
$this->assertEquals(context_system::instance()->id, $event->contextid);
$this->assertEquals($user, $event->get_record_snapshot('user', $user->id));
$user = $DB->get_record('user', array('id'=>$user->id));
$this->assertTimeCurrent($user->firstaccess);
$this->assertTimeCurrent($user->lastaccess);
$this->assertTimeCurrent($user->timemodified);
$this->assertTimeCurrent($USER->firstaccess);
$this->assertTimeCurrent($USER->lastaccess);
$this->assertTimeCurrent($USER->timemodified);
$this->assertTimeCurrent($USER->currentlogin);
$this->assertSame(sesskey(), $USER->sesskey);
$this->assertTimeCurrent($USER->preference['_lastloaded']);
$this->assertObjectNotHasAttribute('password', $USER);
$this->assertObjectNotHasAttribute('description', $USER);
}
/**
......
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