3 namespace MediaWiki\Tests\Maintenance
;
12 * Tests for page dumps of BackupDumper
16 * @covers BackupDumper
18 class BackupDumperPageTest
extends DumpTestCase
{
20 // We'll add several pages, revision and texts. The following variables hold the
22 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5;
23 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5;
24 private $revId1_1, $textId1_1;
25 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
26 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
27 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
28 private $revId4_1, $textId4_1;
29 private $namespace, $talk_namespace;
31 function addDBData() {
32 // be sure, titles created here using english namespace names
33 $this->setMwGlobals( [
34 'wgLanguageCode' => 'en',
35 'wgContLang' => Language
::factory( 'en' ),
38 $this->tablesUsed
[] = 'page';
39 $this->tablesUsed
[] = 'revision';
40 $this->tablesUsed
[] = 'ip_changes';
41 $this->tablesUsed
[] = 'text';
44 $this->namespace = $this->getDefaultWikitextNS();
45 $this->talk_namespace
= NS_TALK
;
47 if ( $this->namespace === $this->talk_namespace
) {
48 // @todo work around this.
49 throw new MWException( "The default wikitext namespace is the talk namespace. "
50 . " We can't currently deal with that." );
53 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
54 $page = WikiPage
::factory( $this->pageTitle1
);
55 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
56 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
57 $this->pageId1
= $page->getId();
59 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
60 $page = WikiPage
::factory( $this->pageTitle2
);
61 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
62 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
63 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
64 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
65 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
66 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
67 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
68 "BackupDumperTestP2Text4 some additional Text ",
69 "BackupDumperTestP2Summary4 extra " );
70 $this->pageId2
= $page->getId();
72 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
73 $page = WikiPage
::factory( $this->pageTitle3
);
74 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
75 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
76 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
77 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
78 $this->pageId3
= $page->getId();
79 $page->doDeleteArticle( "Testing ;)" );
81 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
82 $page = WikiPage
::factory( $this->pageTitle4
);
83 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
84 "Talk about BackupDumperTestP1 Text1",
85 "Talk BackupDumperTestP1 Summary1" );
86 $this->pageId4
= $page->getId();
87 } catch ( Exception
$e ) {
88 // We'd love to pass $e directly. However, ... see
89 // documentation of exceptionFromAddDBData in
91 $this->exceptionFromAddDBData
= $e;
95 protected function setUp() {
98 // Since we will restrict dumping by page ranges (to allow
99 // working tests, even if the db gets prepopulated by a base
100 // class), we have to assert, that the page id are consecutively
103 [ $this->pageId2
, $this->pageId3
, $this->pageId4
],
104 [ $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ],
105 "Page ids increasing without holes" );
108 function testFullTextPlain() {
109 // Preparing the dump
110 $fname = $this->getNewTempFile();
112 $dumper = new DumpBackup();
113 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname ] );
114 $dumper->startId
= $this->pageId1
;
115 $dumper->endId
= $this->pageId4 +
1;
116 $dumper->setDB( $this->db
);
118 // Performing the dump
121 // Checking the dumped data
122 $this->assertDumpStart( $fname );
125 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
126 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
127 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
128 "BackupDumperTestP1Text1" );
129 $this->assertPageEnd();
132 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
133 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
134 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
135 "BackupDumperTestP2Text1" );
136 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
137 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
138 "BackupDumperTestP2Text2", $this->revId2_1
);
139 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
140 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
141 "BackupDumperTestP2Text3", $this->revId2_2
);
142 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
143 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
144 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
145 $this->assertPageEnd();
148 // -> Page is marked deleted. Hence not visible
151 $this->assertPageStart(
153 $this->talk_namespace
,
154 $this->pageTitle4
->getPrefixedText()
156 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
157 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
158 "Talk about BackupDumperTestP1 Text1" );
159 $this->assertPageEnd();
161 $this->assertDumpEnd();
164 function testFullStubPlain() {
165 // Preparing the dump
166 $fname = $this->getNewTempFile();
168 $dumper = new DumpBackup();
169 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname, '--stub' ] );
170 $dumper->startId
= $this->pageId1
;
171 $dumper->endId
= $this->pageId4 +
1;
172 $dumper->setDB( $this->db
);
174 // Performing the dump
177 // Checking the dumped data
178 $this->assertDumpStart( $fname );
181 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
182 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
183 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
184 $this->assertPageEnd();
187 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
188 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
189 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
190 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
191 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
192 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
193 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
194 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
195 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
196 $this->assertPageEnd();
199 // -> Page is marked deleted. Hence not visible
202 $this->assertPageStart(
204 $this->talk_namespace
,
205 $this->pageTitle4
->getPrefixedText()
207 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
208 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
209 $this->assertPageEnd();
211 $this->assertDumpEnd();
214 function testCurrentStubPlain() {
215 // Preparing the dump
216 $fname = $this->getNewTempFile();
218 $dumper = new DumpBackup( [ '--output', 'file:' . $fname ] );
219 $dumper->startId
= $this->pageId1
;
220 $dumper->endId
= $this->pageId4 +
1;
221 $dumper->reporting
= false;
222 $dumper->setDB( $this->db
);
224 // Performing the dump
225 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
227 // Checking the dumped data
228 $this->assertDumpStart( $fname );
231 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
232 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
233 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
234 $this->assertPageEnd();
237 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
238 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
239 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
240 $this->assertPageEnd();
243 // -> Page is marked deleted. Hence not visible
246 $this->assertPageStart(
248 $this->talk_namespace
,
249 $this->pageTitle4
->getPrefixedText()
251 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
252 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
253 $this->assertPageEnd();
255 $this->assertDumpEnd();
258 function testCurrentStubGzip() {
259 $this->checkHasGzip();
261 // Preparing the dump
262 $fname = $this->getNewTempFile();
264 $dumper = new DumpBackup( [ '--output', 'gzip:' . $fname ] );
265 $dumper->startId
= $this->pageId1
;
266 $dumper->endId
= $this->pageId4 +
1;
267 $dumper->reporting
= false;
268 $dumper->setDB( $this->db
);
270 // Performing the dump
271 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
273 // Checking the dumped data
274 $this->gunzip( $fname );
275 $this->assertDumpStart( $fname );
278 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
279 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
280 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
281 $this->assertPageEnd();
284 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
285 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
286 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
287 $this->assertPageEnd();
290 // -> Page is marked deleted. Hence not visible
293 $this->assertPageStart(
295 $this->talk_namespace
,
296 $this->pageTitle4
->getPrefixedText()
298 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
299 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
300 $this->assertPageEnd();
302 $this->assertDumpEnd();
306 * xmldumps-backup typically performs a single dump that that writes
308 * - gzipped stubs of everything (meta-history)
309 * - gzipped stubs of latest revisions of all pages (meta-current)
310 * - gzipped stubs of latest revisions of all pages of namespage 0
313 * We reproduce such a setup with our mini fixture, although we omit
314 * chunks, and all the other gimmicks of xmldumps-backup.
316 function testXmlDumpsBackupUseCase() {
317 $this->checkHasGzip();
319 $fnameMetaHistory = $this->getNewTempFile();
320 $fnameMetaCurrent = $this->getNewTempFile();
321 $fnameArticles = $this->getNewTempFile();
323 $dumper = new DumpBackup( [ "--full", "--stub", "--output=gzip:" . $fnameMetaHistory,
324 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
325 "--output=gzip:" . $fnameArticles, "--filter=latest",
326 "--filter=notalk", "--filter=namespace:!NS_USER",
327 "--reporting=1000" ] );
328 $dumper->startId
= $this->pageId1
;
329 $dumper->endId
= $this->pageId4 +
1;
330 $dumper->setDB( $this->db
);
332 // xmldumps-backup uses reporting. We will not check the exact reported
333 // message, as they are dependent on the processing power of the used
334 // computer. We only check that reporting does not crash the dumping
335 // and that something is reported
336 $dumper->stderr
= fopen( 'php://output', 'a' );
337 if ( $dumper->stderr
=== false ) {
338 $this->fail( "Could not open stream for stderr" );
341 // Performing the dump
342 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
344 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
346 // Checking meta-history -------------------------------------------------
348 $this->gunzip( $fnameMetaHistory );
349 $this->assertDumpStart( $fnameMetaHistory );
352 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
353 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
354 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
355 $this->assertPageEnd();
358 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
359 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
360 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
361 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
362 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
363 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
364 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
365 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
366 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
367 $this->assertPageEnd();
370 // -> Page is marked deleted. Hence not visible
373 $this->assertPageStart(
375 $this->talk_namespace
,
376 $this->pageTitle4
->getPrefixedText()
378 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
379 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
380 $this->assertPageEnd();
382 $this->assertDumpEnd();
384 // Checking meta-current -------------------------------------------------
386 $this->gunzip( $fnameMetaCurrent );
387 $this->assertDumpStart( $fnameMetaCurrent );
390 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
391 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
392 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
393 $this->assertPageEnd();
396 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
397 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
398 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
399 $this->assertPageEnd();
402 // -> Page is marked deleted. Hence not visible
405 $this->assertPageStart(
407 $this->talk_namespace
,
408 $this->pageTitle4
->getPrefixedText()
410 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
411 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
412 $this->assertPageEnd();
414 $this->assertDumpEnd();
416 // Checking articles -------------------------------------------------
418 $this->gunzip( $fnameArticles );
419 $this->assertDumpStart( $fnameArticles );
422 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
423 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
424 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
425 $this->assertPageEnd();
428 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
429 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
430 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
431 $this->assertPageEnd();
434 // -> Page is marked deleted. Hence not visible
437 // -> Page is not in $this->namespace. Hence not visible
439 $this->assertDumpEnd();
441 $this->expectETAOutput();