MediaWiki  1.32.0
populateChangeTagDefTest.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 = [ 'change_tag', 'change_tag_def', 'updatelog' ];
20 
21  $this->cleanChangeTagTables();
22  $this->insertChangeTagData();
23  }
24 
25  private function cleanChangeTagTables() {
26  wfGetDB( DB_MASTER )->delete( 'change_tag', '*' );
27  wfGetDB( DB_MASTER )->delete( 'change_tag_def', '*' );
28  wfGetDB( DB_MASTER )->delete( 'updatelog', '*' );
29  }
30 
31  private function insertChangeTagData() {
32  $changeTags = [];
33 
34  $changeTags[] = [
35  'ct_rc_id' => 1234,
36  'ct_tag' => 'One Tag',
37  ];
38 
39  $changeTags[] = [
40  'ct_rc_id' => 1235,
41  'ct_tag' => 'Two Tags',
42  ];
43 
44  $changeTags[] = [
45  'ct_log_id' => 1236,
46  'ct_tag' => 'Two Tags',
47  ];
48 
49  $changeTags[] = [
50  'ct_rev_id' => 1237,
51  'ct_tag' => 'Three Tags',
52  ];
53 
54  $changeTags[] = [
55  'ct_rc_id' => 1238,
56  'ct_tag' => 'Three Tags',
57  ];
58 
59  $changeTags[] = [
60  'ct_log_id' => 1239,
61  'ct_tag' => 'Three Tags',
62  ];
63 
64  wfGetDB( DB_MASTER )->insert( 'change_tag', $changeTags );
65  }
66 
67  public function testRun() {
68  $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
69  $this->maintenance->loadWithArgv( [ '--sleep', '0' ] );
70 
71  $this->maintenance->execute();
72 
73  $changeTagDefRows = [
74  (object)[
75  'ctd_name' => 'One Tag',
76  'ctd_count' => 1,
77  ],
78  (object)[
79  'ctd_name' => 'Two Tags',
80  'ctd_count' => 2,
81  ],
82  (object)[
83  'ctd_name' => 'Three Tags',
84  'ctd_count' => 3,
85  ],
86  ];
87 
88  $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select(
89  [ 'change_tag_def' ],
90  [ 'ctd_name', 'ctd_count' ],
91  [],
92  __METHOD__,
93  [ 'ORDER BY' => 'ctd_count' ]
94  );
95 
96  $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) );
97 
98  // Check if change_tag is also backpopulated
99  $actualChangeTags = wfGetDB( DB_REPLICA )->select(
100  [ 'change_tag', 'change_tag_def' ],
101  [ 'ct_tag', 'ct_tag_id', 'ctd_count' ],
102  [],
103  __METHOD__,
104  [],
105  [ 'change_tag_def' => [ 'LEFT JOIN', 'ct_tag_id=ctd_id' ] ]
106  );
107  $mapping = [
108  'One Tag' => 1,
109  'Two Tags' => 2,
110  'Three Tags' => 3
111  ];
112  foreach ( $actualChangeTags as $row ) {
113  $this->assertNotNull( $row->ct_tag_id );
114  $this->assertEquals( $row->ctd_count, $mapping[$row->ct_tag] );
115  }
116  }
117 
119  $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
120  $changeTagDefBadRows = [
121  [
122  'ctd_name' => 'One Tag',
123  'ctd_user_defined' => 0,
124  'ctd_count' => 50,
125  ],
126  [
127  'ctd_name' => 'Two Tags',
128  'ctd_user_defined' => 0,
129  'ctd_count' => 4,
130  ],
131  [
132  'ctd_name' => 'Three Tags',
133  'ctd_user_defined' => 0,
134  'ctd_count' => 3,
135  ],
136  ];
137  wfGetDB( DB_MASTER )->insert(
138  'change_tag_def',
139  $changeTagDefBadRows
140  );
141 
142  $mapping = [
143  'One Tag' => 1,
144  'Two Tags' => 2,
145  'Three Tags' => 3
146  ];
147  foreach ( $mapping as $tagName => $tagId ) {
148  wfGetDB( DB_MASTER )->update(
149  'change_tag',
150  [ 'ct_tag_id' => $tagId ],
151  [ 'ct_tag' => $tagName ]
152  );
153  }
154 
155  $this->maintenance->loadWithArgv( [ '--sleep', '0' ] );
156 
157  $this->maintenance->execute();
158 
159  $changeTagDefRows = [
160  (object)[
161  'ctd_name' => 'One Tag',
162  'ctd_count' => 1,
163  ],
164  (object)[
165  'ctd_name' => 'Two Tags',
166  'ctd_count' => 2,
167  ],
168  (object)[
169  'ctd_name' => 'Three Tags',
170  'ctd_count' => 3,
171  ],
172  ];
173 
174  $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select(
175  [ 'change_tag_def' ],
176  [ 'ctd_name', 'ctd_count' ],
177  [],
178  __METHOD__,
179  [ 'ORDER BY' => 'ctd_count' ]
180  );
181 
182  $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) );
183  }
184 
186  $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
187  $changeTagDefBadRows = [
188  [
189  'ctd_name' => 'One Tag',
190  'ctd_user_defined' => 0,
191  'ctd_count' => 50,
192  ],
193  [
194  'ctd_name' => 'Two Tags',
195  'ctd_user_defined' => 0,
196  'ctd_count' => 4,
197  ],
198  [
199  'ctd_name' => 'Three Tags',
200  'ctd_user_defined' => 0,
201  'ctd_count' => 3,
202  ],
203  ];
204  wfGetDB( DB_MASTER )->insert(
205  'change_tag_def',
206  $changeTagDefBadRows
207  );
208 
209  $this->maintenance->loadWithArgv( [ '--sleep', '0' ] );
210 
211  $this->maintenance->execute();
212 
213  $changeTagDefRows = [
214  (object)[
215  'ctd_name' => 'One Tag',
216  'ctd_count' => 1,
217  ],
218  (object)[
219  'ctd_name' => 'Two Tags',
220  'ctd_count' => 2,
221  ],
222  (object)[
223  'ctd_name' => 'Three Tags',
224  'ctd_count' => 3,
225  ],
226  ];
227 
228  $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select(
229  [ 'change_tag_def' ],
230  [ 'ctd_name', 'ctd_count' ],
231  [],
232  __METHOD__,
233  [ 'ORDER BY' => 'ctd_count' ]
234  );
235 
236  $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) );
237  }
238 
239  public function testDryRunMigrationNew() {
240  $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
241  $this->maintenance->loadWithArgv( [ '--dry-run', '--sleep', '0' ] );
242 
243  $this->maintenance->execute();
244 
245  $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select(
246  [ 'change_tag_def' ],
247  [ 'ctd_id', 'ctd_name' ]
248  );
249 
250  $this->assertEquals( [], iterator_to_array( $actualChangeTagDefs, false ) );
251 
252  $actualChangeTags = wfGetDB( DB_REPLICA )->select(
253  [ 'change_tag' ],
254  [ 'ct_tag_id', 'ct_tag' ]
255  );
256 
257  foreach ( $actualChangeTags as $row ) {
258  $this->assertNull( $row->ct_tag_id );
259  $this->assertNotNull( $row->ct_tag );
260  }
261  }
262 
263  public function testDryRunMigrationWriteBoth() {
264  $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
265  $this->maintenance->loadWithArgv( [ '--dry-run', '--sleep', '0' ] );
266 
267  $this->maintenance->execute();
268 
269  $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select(
270  [ 'change_tag_def' ],
271  [ 'ctd_id', 'ctd_name' ]
272  );
273 
274  $this->assertEquals( [], iterator_to_array( $actualChangeTagDefs, false ) );
275 
276  $actualChangeTags = wfGetDB( DB_REPLICA )->select(
277  [ 'change_tag' ],
278  [ 'ct_tag_id', 'ct_tag' ]
279  );
280 
281  foreach ( $actualChangeTags as $row ) {
282  $this->assertNull( $row->ct_tag_id );
283  $this->assertNotNull( $row->ct_tag );
284  }
285  }
286 
287 }
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\testDryRunMigrationNew
testDryRunMigrationNew()
Definition: populateChangeTagDefTest.php:239
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:318
MIGRATION_WRITE_BOTH
const MIGRATION_WRITE_BOTH
Definition: Defines.php:316
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:35
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:2693
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:706
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
PopulateChangeTagDef
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: populateChangeTagDef.php:26
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\cleanChangeTagTables
cleanChangeTagTables()
Definition: populateChangeTagDefTest.php:25
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\testRun
testRun()
Definition: populateChangeTagDefTest.php:67
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\setUp
setUp()
Definition: populateChangeTagDefTest.php:17
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\testRunUpdateHitCountMigrationNew
testRunUpdateHitCountMigrationNew()
Definition: populateChangeTagDefTest.php:118
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:9
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\testRunUpdateHitCountMigrationWriteBoth
testRunUpdateHitCountMigrationWriteBoth()
Definition: populateChangeTagDefTest.php:185
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\testDryRunMigrationWriteBoth
testDryRunMigrationWriteBoth()
Definition: populateChangeTagDefTest.php:263
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:52
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 $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:25
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\getMaintenanceClass
getMaintenanceClass()
Definition: populateChangeTagDefTest.php:13
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest\insertChangeTagData
insertChangeTagData()
Definition: populateChangeTagDefTest.php:31
MediaWiki\Tests\Maintenance\PopulateChangeTagDefTest
Database PopulateChangeTagDef.
Definition: populateChangeTagDefTest.php:11