mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-40934-master' of git://github.com/FMCorz/moodle
Conflicts: auth/tests/auth_test.php
This commit is contained in:
commit
e145762b17
@ -1,79 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Tests for auth.
|
||||
*
|
||||
* @package core_auth
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/authlib.php');
|
||||
|
||||
/**
|
||||
* Auth testcase class.
|
||||
*
|
||||
* @package core_auth
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_auth_testcase extends advanced_testcase {
|
||||
|
||||
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_auth\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));
|
||||
|
||||
$this->assertEventLegacyData(null, $event);
|
||||
$expectedlog = array(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $user->id, 0, $user->id);
|
||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||
}
|
||||
|
||||
public function test_user_loggedin_event_exceptions() {
|
||||
try {
|
||||
$event = \core_auth\event\user_loggedin::create(array('objectid' => 1));
|
||||
$this->fail('\core_auth\event\user_loggedin requires other[\'username\']');
|
||||
} catch(Exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
|
||||
try {
|
||||
$event = \core_auth\event\user_loggedin::create(array('other' => array('username' => 'test')));
|
||||
$this->fail('\core_auth\event\user_loggedin requires objectid');
|
||||
} catch(Exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
@ -64,7 +64,7 @@ class user_loggedin extends \core\event\base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
@ -184,4 +184,41 @@ class core_authlib_testcase extends advanced_testcase {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user