MediaWiki REL1_32
deleteAutoPatrolLogsTest.php
Go to the documentation of this file.
1<?php
2
4
6
12
13 public function getMaintenanceClass() {
14 return DeleteAutoPatrolLogs::class;
15 }
16
17 public function setUp() {
18 parent::setUp();
19 $this->tablesUsed = [ 'logging' ];
20
21 $this->cleanLoggingTable();
22 $this->insertLoggingData();
23 }
24
25 private function cleanLoggingTable() {
26 wfGetDB( DB_MASTER )->delete( 'logging', '*' );
27 }
28
29 private function insertLoggingData() {
30 $dbw = wfGetDB( DB_MASTER );
31 $logs = [];
32
33 // Manual patrolling
34 $logs[] = [
35 'log_type' => 'patrol',
36 'log_action' => 'patrol',
37 'log_user' => 7251,
38 'log_params' => '',
39 'log_timestamp' => $dbw->timestamp( '20041223210426' ),
40 'log_namespace' => NS_MAIN,
41 'log_title' => 'DeleteAutoPatrolLogs',
42 ];
43
44 // Autopatrol #1
45 $logs[] = [
46 'log_type' => 'patrol',
47 'log_action' => 'autopatrol',
48 'log_user' => 7252,
49 'log_params' => '',
50 'log_timestamp' => $dbw->timestamp( '20051223210426' ),
51 'log_namespace' => NS_MAIN,
52 'log_title' => 'DeleteAutoPatrolLogs',
53 ];
54
55 // Block
56 $logs[] = [
57 'log_type' => 'block',
58 'log_action' => 'block',
59 'log_user' => 7253,
60 'log_params' => '',
61 'log_timestamp' => $dbw->timestamp( '20061223210426' ),
62 'log_namespace' => NS_MAIN,
63 'log_title' => 'DeleteAutoPatrolLogs',
64 ];
65
66 // Very old/ invalid patrol
67 $logs[] = [
68 'log_type' => 'patrol',
69 'log_action' => 'patrol',
70 'log_user' => 7253,
71 'log_params' => 'nanana',
72 'log_timestamp' => $dbw->timestamp( '20061223210426' ),
73 'log_namespace' => NS_MAIN,
74 'log_title' => 'DeleteAutoPatrolLogs',
75 ];
76
77 // Autopatrol #2
78 $logs[] = [
79 'log_type' => 'patrol',
80 'log_action' => 'autopatrol',
81 'log_user' => 7254,
82 'log_params' => '',
83 'log_timestamp' => $dbw->timestamp( '20071223210426' ),
84 'log_namespace' => NS_MAIN,
85 'log_title' => 'DeleteAutoPatrolLogs',
86 ];
87
88 // Autopatrol #3 old way
89 $logs[] = [
90 'log_type' => 'patrol',
91 'log_action' => 'patrol',
92 'log_user' => 7255,
93 'log_params' => serialize( [ '6::auto' => true ] ),
94 'log_timestamp' => $dbw->timestamp( '20081223210426' ),
95 'log_namespace' => NS_MAIN,
96 'log_title' => 'DeleteAutoPatrolLogs',
97 ];
98
99 // Manual patrol #2 old way
100 $logs[] = [
101 'log_type' => 'patrol',
102 'log_action' => 'patrol',
103 'log_user' => 7256,
104 'log_params' => serialize( [ '6::auto' => false ] ),
105 'log_timestamp' => $dbw->timestamp( '20091223210426' ),
106 'log_namespace' => NS_MAIN,
107 'log_title' => 'DeleteAutoPatrolLogs',
108 ];
109
110 // Autopatrol #4 very old way
111 $logs[] = [
112 'log_type' => 'patrol',
113 'log_action' => 'patrol',
114 'log_user' => 7257,
115 'log_params' => "9227851\n0\n1",
116 'log_timestamp' => $dbw->timestamp( '20081223210426' ),
117 'log_namespace' => NS_MAIN,
118 'log_title' => 'DeleteAutoPatrolLogs',
119 ];
120
121 // Manual patrol #3 very old way
122 $logs[] = [
123 'log_type' => 'patrol',
124 'log_action' => 'patrol',
125 'log_user' => 7258,
126 'log_params' => "9227851\n0\n0",
127 'log_timestamp' => $dbw->timestamp( '20091223210426' ),
128 'log_namespace' => NS_MAIN,
129 'log_title' => 'DeleteAutoPatrolLogs',
130 ];
131
132 $dbw->insert( 'logging', $logs );
133 }
134
135 public function runProvider() {
136 $allRows = [
137 (object)[
138 'log_type' => 'patrol',
139 'log_action' => 'patrol',
140 'log_user' => '7251',
141 ],
142 (object)[
143 'log_type' => 'patrol',
144 'log_action' => 'autopatrol',
145 'log_user' => '7252',
146 ],
147 (object)[
148 'log_type' => 'block',
149 'log_action' => 'block',
150 'log_user' => '7253',
151 ],
152 (object)[
153 'log_type' => 'patrol',
154 'log_action' => 'patrol',
155 'log_user' => '7253',
156 ],
157 (object)[
158 'log_type' => 'patrol',
159 'log_action' => 'autopatrol',
160 'log_user' => '7254',
161 ],
162 (object)[
163 'log_type' => 'patrol',
164 'log_action' => 'patrol',
165 'log_user' => '7255',
166 ],
167 (object)[
168 'log_type' => 'patrol',
169 'log_action' => 'patrol',
170 'log_user' => '7256',
171 ],
172 (object)[
173 'log_type' => 'patrol',
174 'log_action' => 'patrol',
175 'log_user' => '7257',
176 ],
177 (object)[
178 'log_type' => 'patrol',
179 'log_action' => 'patrol',
180 'log_user' => '7258',
181 ],
182 ];
183
184 $cases = [
185 'dry run' => [
186 $allRows,
187 [ '--sleep', '0', '--dry-run', '-q' ]
188 ],
189 'basic run' => [
190 [
191 $allRows[0],
192 $allRows[2],
193 $allRows[3],
194 $allRows[5],
195 $allRows[6],
196 $allRows[7],
197 $allRows[8],
198 ],
199 [ '--sleep', '0', '-q' ]
200 ],
201 'run with before' => [
202 [
203 $allRows[0],
204 $allRows[2],
205 $allRows[3],
206 $allRows[4],
207 $allRows[5],
208 $allRows[6],
209 $allRows[7],
210 $allRows[8],
211 ],
212 [ '--sleep', '0', '--before', '20060123210426', '-q' ]
213 ],
214 'run with check-old' => [
215 [
216 $allRows[0],
217 $allRows[1],
218 $allRows[2],
219 $allRows[3],
220 $allRows[4],
221 $allRows[6],
222 $allRows[8],
223 ],
224 [ '--sleep', '0', '--check-old', '-q' ]
225 ],
226 ];
227
228 foreach ( $cases as $key => $case ) {
229 yield $key . '-batch-size-1' => [
230 $case[0],
231 array_merge( $case[1], [ '--batch-size', '1' ] )
232 ];
233 yield $key . '-batch-size-5' => [
234 $case[0],
235 array_merge( $case[1], [ '--batch-size', '5' ] )
236 ];
237 yield $key . '-batch-size-1000' => [
238 $case[0],
239 array_merge( $case[1], [ '--batch-size', '1000' ] )
240 ];
241 }
242 }
243
247 public function testRun( $expected, $args ) {
248 // FIXME: fails under postgres
249 $this->markTestSkippedIfDbType( 'postgres' );
250
251 $this->maintenance->loadWithArgv( $args );
252
253 $this->maintenance->execute();
254
255 $remainingLogs = wfGetDB( DB_REPLICA )->select(
256 [ 'logging' ],
257 [ 'log_type', 'log_action', 'log_user' ],
258 [],
259 __METHOD__,
260 [ 'ORDER BY' => 'log_id' ]
261 );
262
263 $this->assertEquals( $expected, iterator_to_array( $remainingLogs, false ) );
264 }
265
266 public function testFromId() {
267 $fromId = wfGetDB( DB_REPLICA )->selectField(
268 'logging',
269 'log_id',
270 [ 'log_params' => 'nanana' ]
271 );
272
273 $this->maintenance->loadWithArgv( [ '--sleep', '0', '--from-id', strval( $fromId ), '-q' ] );
274
275 $this->maintenance->execute();
276
277 $remainingLogs = wfGetDB( DB_REPLICA )->select(
278 [ 'logging' ],
279 [ 'log_type', 'log_action', 'log_user' ],
280 [],
281 __METHOD__,
282 [ 'ORDER BY' => 'log_id' ]
283 );
284
285 $deleted = [
286 'log_type' => 'patrol',
287 'log_action' => 'autopatrol',
288 'log_user' => '7254',
289 ];
290 $notDeleted = [
291 'log_type' => 'patrol',
292 'log_action' => 'autopatrol',
293 'log_user' => '7252',
294 ];
295
296 $remainingLogs = array_map(
297 function ( $val ) {
298 return (array)$val;
299 },
300 iterator_to_array( $remainingLogs, false )
301 );
302
303 $this->assertNotContains( $deleted, $remainingLogs );
304 $this->assertContains( $notDeleted, $remainingLogs );
305 }
306
307}
serialize()
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
if( $line===false) $args
Definition cdb.php:64
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
markTestSkippedIfDbType( $type)
Skip the test if using the specified database type.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition globals.txt:62
const NS_MAIN
Definition Defines.php:64
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26