MediaWiki  REL1_31
deleteAutoPatrolLogsTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
12 
13  public function getMaintenanceClass() {
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  $logs = [];
31 
32  // Manual patrolling
33  $logs[] = [
34  'log_type' => 'patrol',
35  'log_action' => 'patrol',
36  'log_user' => 7251,
37  'log_params' => '',
38  'log_timestamp' => 20041223210426
39  ];
40 
41  // Autopatrol #1
42  $logs[] = [
43  'log_type' => 'patrol',
44  'log_action' => 'autopatrol',
45  'log_user' => 7252,
46  'log_params' => '',
47  'log_timestamp' => 20051223210426
48  ];
49 
50  // Block
51  $logs[] = [
52  'log_type' => 'block',
53  'log_action' => 'block',
54  'log_user' => 7253,
55  'log_params' => '',
56  'log_timestamp' => 20061223210426
57  ];
58 
59  // Very old/ invalid patrol
60  $logs[] = [
61  'log_type' => 'patrol',
62  'log_action' => 'patrol',
63  'log_user' => 7253,
64  'log_params' => 'nanana',
65  'log_timestamp' => 20061223210426
66  ];
67 
68  // Autopatrol #2
69  $logs[] = [
70  'log_type' => 'patrol',
71  'log_action' => 'autopatrol',
72  'log_user' => 7254,
73  'log_params' => '',
74  'log_timestamp' => 20071223210426
75  ];
76 
77  // Autopatrol #3 old way
78  $logs[] = [
79  'log_type' => 'patrol',
80  'log_action' => 'patrol',
81  'log_user' => 7255,
82  'log_params' => serialize( [ '6::auto' => true ] ),
83  'log_timestamp' => 20081223210426
84  ];
85 
86  // Manual patrol #2 old way
87  $logs[] = [
88  'log_type' => 'patrol',
89  'log_action' => 'patrol',
90  'log_user' => 7256,
91  'log_params' => serialize( [ '6::auto' => false ] ),
92  'log_timestamp' => 20091223210426
93  ];
94 
95  wfGetDB( DB_MASTER )->insert( 'logging', $logs );
96  }
97 
98  public function runProvider() {
99  $allRows = [
100  (object)[
101  'log_type' => 'patrol',
102  'log_action' => 'patrol',
103  'log_user' => '7251',
104  ],
105  (object)[
106  'log_type' => 'patrol',
107  'log_action' => 'autopatrol',
108  'log_user' => '7252',
109  ],
110  (object)[
111  'log_type' => 'block',
112  'log_action' => 'block',
113  'log_user' => '7253',
114  ],
115  (object)[
116  'log_type' => 'patrol',
117  'log_action' => 'patrol',
118  'log_user' => '7253',
119  ],
120  (object)[
121  'log_type' => 'patrol',
122  'log_action' => 'autopatrol',
123  'log_user' => '7254',
124  ],
125  (object)[
126  'log_type' => 'patrol',
127  'log_action' => 'patrol',
128  'log_user' => '7255',
129  ],
130  (object)[
131  'log_type' => 'patrol',
132  'log_action' => 'patrol',
133  'log_user' => '7256',
134  ],
135  ];
136 
137  $cases = [
138  'dry run' => [
139  $allRows,
140  [ '--sleep', '0', '--dry-run', '-q' ]
141  ],
142  'basic run' => [
143  [
144  $allRows[0],
145  $allRows[2],
146  $allRows[3],
147  $allRows[5],
148  $allRows[6],
149  ],
150  [ '--sleep', '0', '-q' ]
151  ],
152  'run with before' => [
153  [
154  $allRows[0],
155  $allRows[2],
156  $allRows[3],
157  $allRows[4],
158  $allRows[5],
159  $allRows[6],
160  ],
161  [ '--sleep', '0', '--before', '20060123210426', '-q' ]
162  ],
163  'run with check-old' => [
164  [
165  $allRows[0],
166  $allRows[1],
167  $allRows[2],
168  $allRows[3],
169  $allRows[4],
170  $allRows[6],
171  ],
172  [ '--sleep', '0', '--check-old', '-q' ]
173  ],
174  ];
175 
176  foreach ( $cases as $key => $case ) {
177  yield $key . '-batch-size-1' => [
178  $case[0],
179  array_merge( $case[1], [ '--batch-size', '1' ] )
180  ];
181  yield $key . '-batch-size-5' => [
182  $case[0],
183  array_merge( $case[1], [ '--batch-size', '5' ] )
184  ];
185  yield $key . '-batch-size-1000' => [
186  $case[0],
187  array_merge( $case[1], [ '--batch-size', '1000' ] )
188  ];
189  }
190  }
191 
195  public function testRun( $expected, $args ) {
196  $this->maintenance->loadWithArgv( $args );
197 
198  $this->maintenance->execute();
199 
200  $remainingLogs = wfGetDB( DB_REPLICA )->select(
201  [ 'logging' ],
202  [ 'log_type', 'log_action', 'log_user' ],
203  [],
204  __METHOD__,
205  [ 'ORDER BY' => 'log_id' ]
206  );
207 
208  $this->assertEquals( $expected, iterator_to_array( $remainingLogs, false ) );
209  }
210 
211  public function testFromId() {
212  $fromId = wfGetDB( DB_REPLICA )->selectField(
213  'logging',
214  'log_id',
215  [ 'log_params' => 'nanana' ]
216  );
217 
218  $this->maintenance->loadWithArgv( [ '--sleep', '0', '--from-id', strval( $fromId ), '-q' ] );
219 
220  $this->maintenance->execute();
221 
222  $remainingLogs = wfGetDB( DB_REPLICA )->select(
223  [ 'logging' ],
224  [ 'log_type', 'log_action', 'log_user' ],
225  [],
226  __METHOD__,
227  [ 'ORDER BY' => 'log_id' ]
228  );
229 
230  $deleted = [
231  'log_type' => 'patrol',
232  'log_action' => 'autopatrol',
233  'log_user' => '7254',
234  ];
235  $notDeleted = [
236  'log_type' => 'patrol',
237  'log_action' => 'autopatrol',
238  'log_user' => '7252',
239  ];
240 
241  $remainingLogs = array_map(
242  function ( $val ) {
243  return (array)$val;
244  },
245  iterator_to_array( $remainingLogs, false )
246  );
247 
248  $this->assertNotContains( $deleted, $remainingLogs );
249  $this->assertContains( $notDeleted, $remainingLogs );
250  }
251 
252 }
object
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 For a description of the see design txt $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:64
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest
Database DeleteAutoPatrolLogs.
Definition: deleteAutoPatrolLogsTest.php:11
DeleteAutoPatrolLogs
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: deleteAutoPatrolLogs.php:26
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\runProvider
runProvider()
Definition: deleteAutoPatrolLogsTest.php:98
serialize
serialize()
Definition: ApiMessage.php:184
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\insertLoggingData
insertLoggingData()
Definition: deleteAutoPatrolLogsTest.php:29
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWiki\Tests\Maintenance
Definition: backup_LogTest.php:3
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase
Definition: MaintenanceBaseTestCase.php:9
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\testFromId
testFromId()
Definition: deleteAutoPatrolLogsTest.php:211
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\testRun
testRun( $expected, $args)
runProvider
Definition: deleteAutoPatrolLogsTest.php:195
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\setUp
setUp()
Definition: deleteAutoPatrolLogsTest.php:17
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\getMaintenanceClass
getMaintenanceClass()
Definition: deleteAutoPatrolLogsTest.php:13
$args
if( $line===false) $args
Definition: cdb.php:64
MediaWiki\Tests\Maintenance\DeleteAutoPatrolLogsTest\cleanLoggingTable
cleanLoggingTable()
Definition: deleteAutoPatrolLogsTest.php:25
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56