Skip to content

Commit

Permalink
Merge branch 'w45_MDL-42602_m26_userloginevent' of https://github.com…
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Nov 6, 2013
2 parents fe48481 + 93b3aaf commit 7fd16ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
26 changes: 2 additions & 24 deletions auth/ldap/tests/plugin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,8 @@ public function test_ldap_user_loggedin_event() {

$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.
Expand All @@ -271,23 +267,6 @@ public function test_ldap_user_loggedin_event() {
$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];
Expand All @@ -297,7 +276,6 @@ public function test_ldap_user_loggedin_event() {
$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);
Expand Down
1 change: 0 additions & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,6 @@ function complete_user_login($user) {
'other' => array('username' => $USER->username),
)
);
$event->add_record_snapshot('user', $user);
$event->trigger();

if (isguestuser()) {
Expand Down
23 changes: 20 additions & 3 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2446,14 +2446,17 @@ public function test_order_in_string() {
}

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();
Expand All @@ -2466,7 +2469,21 @@ public function test_complete_user_login() {
$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);
}

/**
Expand Down

0 comments on commit 7fd16ca

Please sign in to comment.