Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / logging / RightsLogFormatterTest.php
blob9f27aa908007e297ed4faf0b22ea6f8b8f8b5e4f
1 <?php
3 use Wikimedia\Rdbms\IDatabase;
4 use Wikimedia\Rdbms\LBFactory;
6 /**
7 * @covers \RightsLogFormatter
8 */
9 class RightsLogFormatterTest extends LogFormatterTestCase {
11 protected function setUp(): void {
12 parent::setUp();
14 $db = $this->createNoOpMock( IDatabase::class, [ 'getInfinity' ] );
15 $db->method( 'getInfinity' )->willReturn( 'infinity' );
16 $lbFactory = $this->createMock( LBFactory::class );
17 $lbFactory->method( 'getReplicaDatabase' )->willReturn( $db );
18 $this->setService( 'DBLoadBalancerFactory', $lbFactory );
21 /**
22 * Provide different rows from the logging table to test
23 * for backward compatibility.
24 * Do not change the existing data, just add a new database row
26 public static function provideRightsLogDatabaseRows() {
27 return [
28 // Current format
31 'type' => 'rights',
32 'action' => 'rights',
33 'comment' => 'rights comment',
34 'user' => 0,
35 'user_text' => 'Sysop',
36 'namespace' => NS_USER,
37 'title' => 'User',
38 'params' => [
39 '4::oldgroups' => [],
40 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
41 'oldmetadata' => [],
42 'newmetadata' => [
43 [ 'expiry' => null ],
44 [ 'expiry' => '20160101123456' ]
49 'text' => 'Sysop changed group membership for User from (none) to '
50 . 'bureaucrat (temporary, until 12:34, 1 January 2016) and administrator',
51 'api' => [
52 'oldgroups' => [],
53 'newgroups' => [ 'sysop', 'bureaucrat' ],
54 'oldmetadata' => [],
55 'newmetadata' => [
56 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
57 [ 'group' => 'bureaucrat', 'expiry' => '2016-01-01T12:34:56Z' ],
63 // Previous format (oldgroups and newgroups as arrays, no metadata)
66 'type' => 'rights',
67 'action' => 'rights',
68 'comment' => 'rights comment',
69 'user' => 0,
70 'user_text' => 'Sysop',
71 'namespace' => NS_USER,
72 'title' => 'User',
73 'params' => [
74 '4::oldgroups' => [],
75 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
79 'text' => 'Sysop changed group membership for User from (none) to '
80 . 'administrator and bureaucrat',
81 'api' => [
82 'oldgroups' => [],
83 'newgroups' => [ 'sysop', 'bureaucrat' ],
84 'oldmetadata' => [],
85 'newmetadata' => [
86 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
87 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
93 // Legacy format (oldgroups and newgroups as numeric-keyed strings)
96 'type' => 'rights',
97 'action' => 'rights',
98 'comment' => 'rights comment',
99 'user' => 0,
100 'user_text' => 'Sysop',
101 'namespace' => NS_USER,
102 'title' => 'User',
103 'params' => [
105 'sysop, bureaucrat',
109 'legacy' => true,
110 'text' => 'Sysop changed group membership for User from (none) to '
111 . 'administrator and bureaucrat',
112 'api' => [
113 'oldgroups' => [],
114 'newgroups' => [ 'sysop', 'bureaucrat' ],
115 'oldmetadata' => [],
116 'newmetadata' => [
117 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
118 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
124 // Really old entry
127 'type' => 'rights',
128 'action' => 'rights',
129 'comment' => 'rights comment',
130 'user' => 0,
131 'user_text' => 'Sysop',
132 'namespace' => NS_USER,
133 'title' => 'User',
134 'params' => [],
137 'legacy' => true,
138 'text' => 'Sysop changed group membership for User',
139 'api' => [],
146 * @dataProvider provideRightsLogDatabaseRows
148 public function testRightsLogDatabaseRows( $row, $extra ) {
149 $this->doTestLogFormatter( $row, $extra );
153 * Provide different rows from the logging table to test
154 * for backward compatibility.
155 * Do not change the existing data, just add a new database row
157 public static function provideAutopromoteLogDatabaseRows() {
158 return [
159 // Current format
162 'type' => 'rights',
163 'action' => 'autopromote',
164 'comment' => 'rights comment',
165 'user' => 0,
166 'user_text' => 'Sysop',
167 'namespace' => NS_USER,
168 'title' => 'Sysop',
169 'params' => [
170 '4::oldgroups' => [ 'sysop' ],
171 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
175 'text' => 'Sysop was automatically promoted from administrator to '
176 . 'administrator and bureaucrat',
177 'api' => [
178 'oldgroups' => [ 'sysop' ],
179 'newgroups' => [ 'sysop', 'bureaucrat' ],
180 'oldmetadata' => [
181 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
183 'newmetadata' => [
184 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
185 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
191 // Legacy format
194 'type' => 'rights',
195 'action' => 'autopromote',
196 'comment' => 'rights comment',
197 'user' => 0,
198 'user_text' => 'Sysop',
199 'namespace' => NS_USER,
200 'title' => 'Sysop',
201 'params' => [
202 'sysop',
203 'sysop, bureaucrat',
207 'legacy' => true,
208 'text' => 'Sysop was automatically promoted from administrator to '
209 . 'administrator and bureaucrat',
210 'api' => [
211 'oldgroups' => [ 'sysop' ],
212 'newgroups' => [ 'sysop', 'bureaucrat' ],
213 'oldmetadata' => [
214 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
216 'newmetadata' => [
217 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
218 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
227 * @dataProvider provideAutopromoteLogDatabaseRows
229 public function testAutopromoteLogDatabaseRows( $row, $extra ) {
230 $this->doTestLogFormatter( $row, $extra );