3 namespace MediaWiki\Tests\Maintenance
;
5 use DeleteAutoPatrolLogs
;
9 * @covers \DeleteAutoPatrolLogs
11 class DeleteAutoPatrolLogsTest
extends MaintenanceBaseTestCase
{
13 public function getMaintenanceClass() {
14 return DeleteAutoPatrolLogs
::class;
17 protected function setUp(): void
{
20 $this->insertLoggingData();
23 private function insertLoggingData() {
24 $dbw = $this->getDb();
27 $comment = \MediaWiki\MediaWikiServices
::getInstance()->getCommentStore()
28 ->createComment( $dbw, '' );
32 'log_type' => 'patrol',
33 'log_action' => 'patrol',
36 'log_timestamp' => $dbw->timestamp( '20041223210426' ),
37 'log_namespace' => NS_MAIN
,
38 'log_title' => 'DeleteAutoPatrolLogs',
39 'log_comment_id' => $comment->id
,
44 'log_type' => 'patrol',
45 'log_action' => 'autopatrol',
48 'log_timestamp' => $dbw->timestamp( '20051223210426' ),
49 'log_namespace' => NS_MAIN
,
50 'log_title' => 'DeleteAutoPatrolLogs',
51 'log_comment_id' => $comment->id
,
56 'log_type' => 'block',
57 'log_action' => 'block',
60 'log_timestamp' => $dbw->timestamp( '20061223210426' ),
61 'log_namespace' => NS_MAIN
,
62 'log_title' => 'DeleteAutoPatrolLogs',
63 'log_comment_id' => $comment->id
,
66 // Very old/ invalid patrol
68 'log_type' => 'patrol',
69 'log_action' => 'patrol',
71 'log_params' => 'nanana',
72 'log_timestamp' => $dbw->timestamp( '20061223210426' ),
73 'log_namespace' => NS_MAIN
,
74 'log_title' => 'DeleteAutoPatrolLogs',
75 'log_comment_id' => $comment->id
,
80 'log_type' => 'patrol',
81 'log_action' => 'autopatrol',
84 'log_timestamp' => $dbw->timestamp( '20071223210426' ),
85 'log_namespace' => NS_MAIN
,
86 'log_title' => 'DeleteAutoPatrolLogs',
87 'log_comment_id' => $comment->id
,
90 // Autopatrol #3 old way
92 'log_type' => 'patrol',
93 'log_action' => 'patrol',
95 'log_params' => serialize( [ '6::auto' => true ] ),
96 'log_timestamp' => $dbw->timestamp( '20081223210426' ),
97 'log_namespace' => NS_MAIN
,
98 'log_title' => 'DeleteAutoPatrolLogs',
99 'log_comment_id' => $comment->id
,
102 // Manual patrol #2 old way
104 'log_type' => 'patrol',
105 'log_action' => 'patrol',
107 'log_params' => serialize( [ '6::auto' => false ] ),
108 'log_timestamp' => $dbw->timestamp( '20091223210426' ),
109 'log_namespace' => NS_MAIN
,
110 'log_title' => 'DeleteAutoPatrolLogs',
111 'log_comment_id' => $comment->id
,
114 // Autopatrol #4 very old way
116 'log_type' => 'patrol',
117 'log_action' => 'patrol',
119 'log_params' => "9227851\n0\n1",
120 'log_timestamp' => $dbw->timestamp( '20081223210426' ),
121 'log_namespace' => NS_MAIN
,
122 'log_title' => 'DeleteAutoPatrolLogs',
123 'log_comment_id' => $comment->id
,
126 // Manual patrol #3 very old way
128 'log_type' => 'patrol',
129 'log_action' => 'patrol',
131 'log_params' => "9227851\n0\n0",
132 'log_timestamp' => $dbw->timestamp( '20091223210426' ),
133 'log_namespace' => NS_MAIN
,
134 'log_title' => 'DeleteAutoPatrolLogs',
135 'log_comment_id' => $comment->id
,
138 $dbw->newInsertQueryBuilder()
139 ->insertInto( 'logging' )
141 ->caller( __METHOD__
)
145 public static function runProvider() {
148 'log_type' => 'patrol',
149 'log_action' => 'patrol',
150 'log_actor' => '7251',
153 'log_type' => 'patrol',
154 'log_action' => 'autopatrol',
155 'log_actor' => '7252',
158 'log_type' => 'block',
159 'log_action' => 'block',
160 'log_actor' => '7253',
163 'log_type' => 'patrol',
164 'log_action' => 'patrol',
165 'log_actor' => '7253',
168 'log_type' => 'patrol',
169 'log_action' => 'autopatrol',
170 'log_actor' => '7254',
173 'log_type' => 'patrol',
174 'log_action' => 'patrol',
175 'log_actor' => '7255',
178 'log_type' => 'patrol',
179 'log_action' => 'patrol',
180 'log_actor' => '7256',
183 'log_type' => 'patrol',
184 'log_action' => 'patrol',
185 'log_actor' => '7257',
188 'log_type' => 'patrol',
189 'log_action' => 'patrol',
190 'log_actor' => '7258',
197 [ '--sleep', '0', '--dry-run', '-q' ]
209 [ '--sleep', '0', '-q' ]
211 'run with before' => [
222 [ '--sleep', '0', '--before', '20060123210426', '-q' ]
224 'run with check-old' => [
234 [ '--sleep', '0', '--check-old', '-q' ]
238 foreach ( $cases as $key => $case ) {
239 yield
$key . '-batch-size-1' => [
241 array_merge( $case[1], [ '--batch-size', '1' ] )
243 yield
$key . '-batch-size-5' => [
245 array_merge( $case[1], [ '--batch-size', '5' ] )
247 yield
$key . '-batch-size-1000' => [
249 array_merge( $case[1], [ '--batch-size', '1000' ] )
255 * @dataProvider runProvider
257 public function testRun( $expected, $args ) {
258 $this->maintenance
->loadWithArgv( $args );
260 $this->maintenance
->execute();
262 $remainingLogs = $this->getDb()->newSelectQueryBuilder()
263 ->select( [ 'log_type', 'log_action', 'log_actor' ] )
265 ->orderBy( 'log_id' )
266 ->caller( __METHOD__
)->fetchResultSet();
268 $this->assertEquals( $expected, iterator_to_array( $remainingLogs, false ) );
271 public function testFromId() {
272 $fromId = $this->getDb()->newSelectQueryBuilder()
275 ->where( [ 'log_params' => 'nanana' ] )
278 $this->maintenance
->loadWithArgv( [ '--sleep', '0', '--from-id', strval( $fromId ), '-q' ] );
280 $this->maintenance
->execute();
282 $remainingLogs = $this->getDb()->newSelectQueryBuilder()
283 ->select( [ 'log_type', 'log_action', 'log_actor' ] )
285 ->orderBy( 'log_id' )
286 ->caller( __METHOD__
)->fetchResultSet();
289 'log_type' => 'patrol',
290 'log_action' => 'autopatrol',
291 'log_actor' => '7254',
294 'log_type' => 'patrol',
295 'log_action' => 'autopatrol',
296 'log_actor' => '7252',
299 $remainingLogs = array_map(
300 static function ( $val ) {
303 iterator_to_array( $remainingLogs, false )
306 $this->assertNotContains( $deleted, $remainingLogs );
307 $this->assertContains( $notDeleted, $remainingLogs );