Merge "PHPUnit autoload file for PhpStorm"
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / RightsLogFormatterTest.php
1 <?php
2
3 class RightsLogFormatterTest extends LogFormatterTestCase {
4
5 /**
6 * Provide different rows from the logging table to test
7 * for backward compatibility.
8 * Do not change the existing data, just add a new database row
9 */
10 public static function provideRightsLogDatabaseRows() {
11 return [
12 // Current format
13 [
14 [
15 'type' => 'rights',
16 'action' => 'rights',
17 'comment' => 'rights comment',
18 'user' => 0,
19 'user_text' => 'Sysop',
20 'namespace' => NS_USER,
21 'title' => 'User',
22 'params' => [
23 '4::oldgroups' => [],
24 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
25 'oldmetadata' => [],
26 'newmetadata' => [
27 [ 'expiry' => null ],
28 [ 'expiry' => '20160101123456' ]
29 ],
30 ],
31 ],
32 [
33 'text' => 'Sysop changed group membership for User from (none) to '
34 . 'bureaucrat (temporary, until 12:34, 1 January 2016) and administrator',
35 'api' => [
36 'oldgroups' => [],
37 'newgroups' => [ 'sysop', 'bureaucrat' ],
38 'oldmetadata' => [],
39 'newmetadata' => [
40 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
41 [ 'group' => 'bureaucrat', 'expiry' => '2016-01-01T12:34:56Z' ],
42 ],
43 ],
44 ],
45 ],
46
47 // Previous format (oldgroups and newgroups as arrays, no metadata)
48 [
49 [
50 'type' => 'rights',
51 'action' => 'rights',
52 'comment' => 'rights comment',
53 'user' => 0,
54 'user_text' => 'Sysop',
55 'namespace' => NS_USER,
56 'title' => 'User',
57 'params' => [
58 '4::oldgroups' => [],
59 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
60 ],
61 ],
62 [
63 'text' => 'Sysop changed group membership for User from (none) to '
64 . 'administrator and bureaucrat',
65 'api' => [
66 'oldgroups' => [],
67 'newgroups' => [ 'sysop', 'bureaucrat' ],
68 'oldmetadata' => [],
69 'newmetadata' => [
70 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
71 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
72 ],
73 ],
74 ],
75 ],
76
77 // Legacy format (oldgroups and newgroups as numeric-keyed strings)
78 [
79 [
80 'type' => 'rights',
81 'action' => 'rights',
82 'comment' => 'rights comment',
83 'user' => 0,
84 'user_text' => 'Sysop',
85 'namespace' => NS_USER,
86 'title' => 'User',
87 'params' => [
88 '',
89 'sysop, bureaucrat',
90 ],
91 ],
92 [
93 'legacy' => true,
94 'text' => 'Sysop changed group membership for User from (none) to '
95 . 'administrator and bureaucrat',
96 'api' => [
97 'oldgroups' => [],
98 'newgroups' => [ 'sysop', 'bureaucrat' ],
99 'oldmetadata' => [],
100 'newmetadata' => [
101 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
102 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
103 ],
104 ],
105 ],
106 ],
107
108 // Really old entry
109 [
110 [
111 'type' => 'rights',
112 'action' => 'rights',
113 'comment' => 'rights comment',
114 'user' => 0,
115 'user_text' => 'Sysop',
116 'namespace' => NS_USER,
117 'title' => 'User',
118 'params' => [],
119 ],
120 [
121 'legacy' => true,
122 'text' => 'Sysop changed group membership for User',
123 'api' => [],
124 ],
125 ],
126 ];
127 }
128
129 /**
130 * @dataProvider provideRightsLogDatabaseRows
131 */
132 public function testRightsLogDatabaseRows( $row, $extra ) {
133 $this->doTestLogFormatter( $row, $extra );
134 }
135
136 /**
137 * Provide different rows from the logging table to test
138 * for backward compatibility.
139 * Do not change the existing data, just add a new database row
140 */
141 public static function provideAutopromoteLogDatabaseRows() {
142 return [
143 // Current format
144 [
145 [
146 'type' => 'rights',
147 'action' => 'autopromote',
148 'comment' => 'rights comment',
149 'user' => 0,
150 'user_text' => 'Sysop',
151 'namespace' => NS_USER,
152 'title' => 'Sysop',
153 'params' => [
154 '4::oldgroups' => [ 'sysop' ],
155 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
156 ],
157 ],
158 [
159 'text' => 'Sysop was automatically promoted from administrator to '
160 . 'administrator and bureaucrat',
161 'api' => [
162 'oldgroups' => [ 'sysop' ],
163 'newgroups' => [ 'sysop', 'bureaucrat' ],
164 'oldmetadata' => [
165 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
166 ],
167 'newmetadata' => [
168 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
169 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
170 ],
171 ],
172 ],
173 ],
174
175 // Legacy format
176 [
177 [
178 'type' => 'rights',
179 'action' => 'autopromote',
180 'comment' => 'rights comment',
181 'user' => 0,
182 'user_text' => 'Sysop',
183 'namespace' => NS_USER,
184 'title' => 'Sysop',
185 'params' => [
186 'sysop',
187 'sysop, bureaucrat',
188 ],
189 ],
190 [
191 'legacy' => true,
192 'text' => 'Sysop was automatically promoted from administrator to '
193 . 'administrator and bureaucrat',
194 'api' => [
195 'oldgroups' => [ 'sysop' ],
196 'newgroups' => [ 'sysop', 'bureaucrat' ],
197 'oldmetadata' => [
198 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
199 ],
200 'newmetadata' => [
201 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
202 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
203 ],
204 ],
205 ],
206 ],
207 ];
208 }
209
210 /**
211 * @dataProvider provideAutopromoteLogDatabaseRows
212 */
213 public function testAutopromoteLogDatabaseRows( $row, $extra ) {
214 $this->doTestLogFormatter( $row, $extra );
215 }
216 }