3 use Wikimedia\Rdbms\IDatabase
;
4 use Wikimedia\Rdbms\LBFactory
;
7 * @covers \RightsLogFormatter
9 class RightsLogFormatterTest
extends LogFormatterTestCase
{
11 protected function setUp(): void
{
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 );
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() {
33 'comment' => 'rights comment',
35 'user_text' => 'Sysop',
36 'namespace' => NS_USER
,
40 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
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',
53 'newgroups' => [ 'sysop', 'bureaucrat' ],
56 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
57 [ 'group' => 'bureaucrat', 'expiry' => '2016-01-01T12:34:56Z' ],
63 // Previous format (oldgroups and newgroups as arrays, no metadata)
68 'comment' => 'rights comment',
70 'user_text' => 'Sysop',
71 'namespace' => NS_USER
,
75 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
79 'text' => 'Sysop changed group membership for User from (none) to '
80 . 'administrator and bureaucrat',
83 'newgroups' => [ 'sysop', 'bureaucrat' ],
86 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
87 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
93 // Legacy format (oldgroups and newgroups as numeric-keyed strings)
98 'comment' => 'rights comment',
100 'user_text' => 'Sysop',
101 'namespace' => NS_USER
,
110 'text' => 'Sysop changed group membership for User from (none) to '
111 . 'administrator and bureaucrat',
114 'newgroups' => [ 'sysop', 'bureaucrat' ],
117 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
118 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
128 'action' => 'rights',
129 'comment' => 'rights comment',
131 'user_text' => 'Sysop',
132 'namespace' => NS_USER
,
138 'text' => 'Sysop changed group membership for User',
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() {
163 'action' => 'autopromote',
164 'comment' => 'rights comment',
166 'user_text' => 'Sysop',
167 'namespace' => NS_USER
,
170 '4::oldgroups' => [ 'sysop' ],
171 '5::newgroups' => [ 'sysop', 'bureaucrat' ],
175 'text' => 'Sysop was automatically promoted from administrator to '
176 . 'administrator and bureaucrat',
178 'oldgroups' => [ 'sysop' ],
179 'newgroups' => [ 'sysop', 'bureaucrat' ],
181 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
184 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
185 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
195 'action' => 'autopromote',
196 'comment' => 'rights comment',
198 'user_text' => 'Sysop',
199 'namespace' => NS_USER
,
208 'text' => 'Sysop was automatically promoted from administrator to '
209 . 'administrator and bureaucrat',
211 'oldgroups' => [ 'sysop' ],
212 'newgroups' => [ 'sysop', 'bureaucrat' ],
214 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
217 [ 'group' => 'sysop', 'expiry' => 'infinity' ],
218 [ 'group' => 'bureaucrat', 'expiry' => 'infinity' ],
227 * @dataProvider provideAutopromoteLogDatabaseRows
229 public function testAutopromoteLogDatabaseRows( $row, $extra ) {
230 $this->doTestLogFormatter( $row, $extra );