forked from phpbb-extensions/teamsecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogin_notification_test.php
More file actions
70 lines (60 loc) · 1.94 KB
/
login_notification_test.php
File metadata and controls
70 lines (60 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
*
* Team Security Measures extension for the phpBB Forum Software package.
*
* @copyright (c) 2015 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\teamsecurity\tests\event;
class login_notification_test extends listener_base
{
/**
* Data set for test_acp_login_notification
*
* @return array Array of test data
*/
public static function acp_login_notification_data()
{
return array(
array(true, true, 'foo', '1:1:1', array(
'USERNAME' => 'foo',
'IP_ADDRESS' => '1:1:1',
'HOST_NAME' => false,
'LOGIN_TIME' => '',
)),
array(true, false, null, null, array()),
array(true, false, null, null, array()),
array(false, false,null, null, array()),
);
}
/**
* Test ACP login information is being sent
*
* @dataProvider acp_login_notification_data
*/
public function test_acp_login_notification($enabled, $admin, $username, $ip, $expected)
{
$this->config = new \phpbb\config\config(array(
'sec_login_email' => $enabled,
));
$this->user->data['username'] = $username;
$this->user->ip = $ip;
// Set some user DateTime options
$this->user->timezone = new \DateTimeZone('UTC');
$this->lang->lang('datetime', array());
$this->set_listener();
// Set the LOGIN_TIME now, since we can't set it during the data array setup
$expected['LOGIN_TIME'] = $this->user->format_date(time(), $this->config['default_dateformat'], true);
// Check send_message once if enabled and admin are true,
// otherwise check that it is never called.
$this->listener->expects(($enabled && $admin) ? self::once() : self::never())
->method('send_message')
->with($expected);
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.login_box_redirect', array($this->listener, 'acp_login_notification'));
$event_data = array('admin');
$dispatcher->trigger_event('core.login_box_redirect', compact($event_data));
}
}