Skip to content

Commit

Permalink
Merge branch 'MDL-40934-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	auth/tests/auth_test.php
  • Loading branch information
Sam Hemelryk committed Aug 6, 2013
2 parents 3550fc2 + d95db91 commit e145762
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 88 deletions.
79 changes: 0 additions & 79 deletions auth/tests/auth_test.php

This file was deleted.

3 changes: 1 addition & 2 deletions lib/authlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ function login_is_lockedout($user) {
function login_attempt_valid($user) {
global $CFG;

$event = \core_auth\event\user_loggedin::create(array('objectid' => $user->id,
'other' => array('username' => $user->username)));
$event = \core\event\user_loggedin::create(array('objectid' => $user->id, 'other' => array('username' => $user->username)));
$event->add_record_snapshot('user', $user);
$event->trigger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
/**
* User login event.
*
* @package core_auth
* @package core
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core_auth\event;
namespace core\event;

defined('MOODLE_INTERNAL') || die();

/**
* User login event class.
*
* @package core_auth
* @package core
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down Expand Up @@ -64,7 +64,7 @@ public static function get_name() {
}

/**
* Get URL related to the action
* Get URL related to the action.
*
* @return \moodle_url
*/
Expand Down
37 changes: 37 additions & 0 deletions lib/tests/authlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,41 @@ public function test_authenticate_user_login() {

ini_set('error_log', $oldlog);
}

public function test_user_loggedin_event() {
global $USER;
$this->resetAfterTest(true);
$this->setAdminUser();

$sink = $this->redirectEvents();
$user = clone($USER);
login_attempt_valid($user);
$events = $sink->get_events();
$sink->close();

$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\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));
}

public function test_user_loggedin_event_exceptions() {
try {
$event = \core\event\user_loggedin::create(array('objectid' => 1));
$this->fail('\core\event\user_loggedin requires other[\'username\']');
} catch(Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}

try {
$event = \core\event\user_loggedin::create(array('other' => array('username' => 'test')));
$this->fail('\core\event\user_loggedin requires objectid');
} catch(Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}

}
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
<directory suffix="_test.php">grade/tests</directory>
<directory suffix="_test.php">grade/grading/tests</directory>
</testsuite>
<testsuite name="core_auth">
<directory suffix="_test.php">auth/tests</directory>
</testsuite>
<testsuite name="core_backup">
<directory suffix="_test.php">backup/controller/tests</directory>
<directory suffix="_test.php">backup/converter/moodle1/tests</directory>
Expand Down

0 comments on commit e145762

Please sign in to comment.