Debian Codegraph @

tests/phpunit/includes/logging/NewUsersLogFormatterTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * @covers \NewUsersLogFormatter
5 * @group Database
6 */
7 class NewUsersLogFormatterTest extends LogFormatterTestCase {
8
9 protected function setUp(): void {
10 parent::setUp();
11
12 // Register LogHandler, see $wgNewUserLog in Setup.php
13 $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', [
14 'newusers/newusers' => NewUsersLogFormatter::class,
15 'newusers/create' => NewUsersLogFormatter::class,
16 'newusers/create2' => NewUsersLogFormatter::class,
17 'newusers/byemail' => NewUsersLogFormatter::class,
18 'newusers/autocreate' => NewUsersLogFormatter::class,
19 ] );
20 }
21
22 /**
23 * Provide different rows from the logging table to test
24 * for backward compatibility.
25 * Do not change the existing data, just add a new database row
26 */
27 public static function provideNewUsersLogDatabaseRows() {
28 return [
29 // Only old logs
30 [
31 [
32 'type' => 'newusers',
33 'action' => 'newusers',
34 'comment' => 'newusers comment',
35 'user' => 0,
36 'user_text' => 'New user',
37 'namespace' => NS_USER,
38 'title' => 'New user',
39 'params' => [],
40 ],
41 [
42 'legacy' => true,
43 'text' => 'User account New user was created',
44 'api' => [],
45 ],
46 ],
47 ];
48 }
49
50 /**
51 * @dataProvider provideNewUsersLogDatabaseRows
52 */
53 public function testNewUsersLogDatabaseRows( $row, $extra ) {
54 $this->doTestLogFormatter( $row, $extra );
55 }
56
57 /**
58 * Provide different rows from the logging table to test
59 * for backward compatibility.
60 * Do not change the existing data, just add a new database row
61 */
62 public static function provideCreateLogDatabaseRows() {
63 return [
64 // Current format
65 [
66 [
67 'type' => 'newusers',
68 'action' => 'create',
69 'comment' => 'newusers comment',
70 'user' => 0,
71 'user_text' => 'New user',
72 'namespace' => NS_USER,
73 'title' => 'New user',
74 'params' => [
75 '4::userid' => 1,
76 ],
77 ],
78 [
79 'text' => 'User account New user was created',
80 'api' => [
81 'userid' => 1,
82 ],
83 ],
84 ],
85 ];
86 }
87
88 /**
89 * @dataProvider provideCreateLogDatabaseRows
90 */
91 public function testCreateLogDatabaseRows( $row, $extra ) {
92 $this->doTestLogFormatter( $row, $extra );
93 }
94
95 /**
96 * Provide different rows from the logging table to test
97 * for backward compatibility.
98 * Do not change the existing data, just add a new database row
99 */
100 public static function provideCreate2LogDatabaseRows() {
101 return [
102 // Current format
103 [
104 [
105 'type' => 'newusers',
106 'action' => 'create2',
107 'comment' => 'newusers comment',
108 'user' => 0,
109 'user_text' => 'User',
110 'namespace' => NS_USER,
111 'title' => 'UTSysop'
112 ],
113 [
114 'text' => 'User account UTSysop was created by User'
115 ],
116 ],
117 ];
118 }
119
120 /**
121 * Provide different rows from the logging table to test
122 * for backward compatibility.
123 * Do not change the existing data, just add a new database row
124 */
125 public static function provideByemailLogDatabaseRows() {
126 return [
127 // Current format
128 [
129 [
130 'type' => 'newusers',
131 'action' => 'byemail',
132 'comment' => 'newusers comment',
133 'user' => 0,
134 'user_text' => 'Sysop',
135 'namespace' => NS_USER,
136 'title' => 'UTSysop'
137 ],
138 [
139 'text' => 'User account UTSysop was created by Sysop and password was sent by email'
140 ],
141 ],
142 ];
143 }
144
145 /**
146 * @dataProvider provideCreate2LogDatabaseRows
147 * @dataProvider provideByemailLogDatabaseRows
148 */
149 public function testCreate2LogDatabaseRows( $row, $extra ) {
150 // Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres)
151 $user = static::getTestSysop()->getUser();
152 $row['params']['4::userid'] = $user->getId();
153 $extra['api']['userid'] = $user->getId();
154 $this->doTestLogFormatter( $row, $extra );
155 }
156
157 /**
158 * Provide different rows from the logging table to test
159 * for backward compatibility.
160 * Do not change the existing data, just add a new database row
161 */
162 public static function provideAutocreateLogDatabaseRows() {
163 return [
164 // Current format
165 [
166 [
167 'type' => 'newusers',
168 'action' => 'autocreate',
169 'comment' => 'newusers comment',
170 'user' => 0,
171 'user_text' => 'New user',
172 'namespace' => NS_USER,
173 'title' => 'New user',
174 'params' => [
175 '4::userid' => 1,
176 ],
177 ],
178 [
179 'text' => 'User account New user was created automatically',
180 'api' => [
181 'userid' => 1,
182 ],
183 ],
184 ],
185 ];
186 }
187
188 /**
189 * @dataProvider provideAutocreateLogDatabaseRows
190 */
191 public function testAutocreateLogDatabaseRows( $row, $extra ) {
192 $this->doTestLogFormatter( $row, $extra );
193 }
194 }