forked from phpbb-extensions/teamsecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_change_notification_test.php
More file actions
174 lines (165 loc) · 4.24 KB
/
email_change_notification_test.php
File metadata and controls
174 lines (165 loc) · 4.24 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?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 email_change_notification_test extends listener_base
{
/**
* Data set for test_email_change_notification
*
* @return array Array of test data
*/
public static function email_change_notification_data()
{
return array(
array(
'core.acp_users_overview_modify_data',
true,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array(
'USERNAME' => '',
'NEW_EMAIL' => 'new@mail.tld',
'OLD_EMAIL' => 'old@mail.tld',
'IP_ADDRESS' => '1:1:1',
'HOST_NAME' => false,
'CONTACT' => 'admin@mail.tld',
)
),
array(
'core.acp_users_overview_modify_data',
true,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'old@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.acp_users_overview_modify_data',
false,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.acp_users_overview_modify_data',
true,
false,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.acp_users_overview_modify_data',
false,
false,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.ucp_profile_reg_details_sql_ary',
true,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array(
'USERNAME' => '',
'NEW_EMAIL' => 'new@mail.tld',
'OLD_EMAIL' => 'old@mail.tld',
'IP_ADDRESS' => '1:1:1',
'HOST_NAME' => false,
'CONTACT' => 'admin@mail.tld',
)
),
array(
'core.ucp_profile_reg_details_sql_ary',
true,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'old@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.ucp_profile_reg_details_sql_ary',
false,
true,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.ucp_profile_reg_details_sql_ary',
true,
false,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
array(
'core.ucp_profile_reg_details_sql_ary',
false,
false,
array('user_id' => 1, 'user_email' => 'old@mail.tld'),
array('email' => 'new@mail.tld'),
'admin@mail.tld',
'1:1:1',
array()
),
);
}
/**
* Test email change information is being sent
*
* @dataProvider email_change_notification_data
*/
public function test_email_change_notification($listener, $enabled, $in_watch_group, $user_row, $data, $contact, $ip, $expected)
{
$this->config = new \phpbb\config\config(array(
'sec_email_changes' => $enabled,
'sec_contact_name' => $contact,
));
$this->user->data['user_id'] = $user_row['user_id'];
$this->user->data['user_email'] = $user_row['user_email'];
$this->user->ip = $ip;
$this->set_listener();
$this->listener->expects(self::atMost(1))
->method('in_watch_group')
->willReturn($in_watch_group);
// Check send_message once if conditions are true,
// otherwise check that it is never called.
$this->listener->expects(($enabled && $this->user->data['user_email'] != $data['email'] && $in_watch_group) ? self::once() : self::never())
->method('send_message')
->with($expected);
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener($listener, array($this->listener, 'email_change_notification'));
$event_data = array('user_row', 'data');
$dispatcher->trigger_event($listener, compact($event_data));
}
}