3 namespace MediaWiki\Tests\Maintenance
;
11 * Tests for page dumps of BackupDumper
15 * @covers BackupDumper
17 class BackupDumperPageTest
extends DumpTestCase
{
19 // We'll add several pages, revision and texts. The following variables hold the
21 private $pageId1, $pageId2, $pageId3, $pageId4;
22 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4;
23 private $revId1_1, $textId1_1;
24 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
25 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
26 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
27 private $revId4_1, $textId4_1;
28 private $namespace, $talk_namespace;
30 function addDBData() {
31 // be sure, titles created here using english namespace names
32 $this->setContentLang( 'en' );
34 $this->tablesUsed
[] = 'page';
35 $this->tablesUsed
[] = 'revision';
36 $this->tablesUsed
[] = 'ip_changes';
37 $this->tablesUsed
[] = 'text';
40 $this->namespace = $this->getDefaultWikitextNS();
41 $this->talk_namespace
= NS_TALK
;
43 if ( $this->namespace === $this->talk_namespace
) {
44 // @todo work around this.
45 throw new MWException( "The default wikitext namespace is the talk namespace. "
46 . " We can't currently deal with that." );
49 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
50 $page = WikiPage
::factory( $this->pageTitle1
);
51 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
52 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
53 $this->pageId1
= $page->getId();
55 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
56 $page = WikiPage
::factory( $this->pageTitle2
);
57 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
58 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
59 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
60 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
61 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
62 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
63 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
64 "BackupDumperTestP2Text4 some additional Text ",
65 "BackupDumperTestP2Summary4 extra " );
66 $this->pageId2
= $page->getId();
68 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
69 $page = WikiPage
::factory( $this->pageTitle3
);
70 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
71 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
72 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
73 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
74 $this->pageId3
= $page->getId();
75 $page->doDeleteArticle( "Testing ;)" );
77 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
78 $page = WikiPage
::factory( $this->pageTitle4
);
79 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
80 "Talk about BackupDumperTestP1 Text1",
81 "Talk BackupDumperTestP1 Summary1" );
82 $this->pageId4
= $page->getId();
83 } catch ( Exception
$e ) {
84 // We'd love to pass $e directly. However, ... see
85 // documentation of exceptionFromAddDBData in
87 $this->exceptionFromAddDBData
= $e;
91 protected function setUp() {
94 // Since we will restrict dumping by page ranges (to allow
95 // working tests, even if the db gets prepopulated by a base
96 // class), we have to assert, that the page id are consecutively
99 [ $this->pageId2
, $this->pageId3
, $this->pageId4
],
100 [ $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ],
101 "Page ids increasing without holes" );
104 function testFullTextPlain() {
105 // Preparing the dump
106 $fname = $this->getNewTempFile();
108 $dumper = new DumpBackup();
109 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname ] );
110 $dumper->startId
= $this->pageId1
;
111 $dumper->endId
= $this->pageId4 +
1;
112 $dumper->setDB( $this->db
);
114 // Performing the dump
117 // Checking the dumped data
118 $this->assertDumpStart( $fname );
121 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
122 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
123 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
124 "BackupDumperTestP1Text1" );
125 $this->assertPageEnd();
128 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
129 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
130 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
131 "BackupDumperTestP2Text1" );
132 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
133 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
134 "BackupDumperTestP2Text2", $this->revId2_1
);
135 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
136 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
137 "BackupDumperTestP2Text3", $this->revId2_2
);
138 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
139 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
140 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
141 $this->assertPageEnd();
144 // -> Page is marked deleted. Hence not visible
147 $this->assertPageStart(
149 $this->talk_namespace
,
150 $this->pageTitle4
->getPrefixedText()
152 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
153 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
154 "Talk about BackupDumperTestP1 Text1" );
155 $this->assertPageEnd();
157 $this->assertDumpEnd();
160 function testFullStubPlain() {
161 // Preparing the dump
162 $fname = $this->getNewTempFile();
164 $dumper = new DumpBackup();
165 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname, '--stub' ] );
166 $dumper->startId
= $this->pageId1
;
167 $dumper->endId
= $this->pageId4 +
1;
168 $dumper->setDB( $this->db
);
170 // Performing the dump
173 // Checking the dumped data
174 $this->assertDumpStart( $fname );
177 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
178 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
179 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
180 $this->assertPageEnd();
183 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
184 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
185 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
186 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
187 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
188 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
189 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
190 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
191 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
192 $this->assertPageEnd();
195 // -> Page is marked deleted. Hence not visible
198 $this->assertPageStart(
200 $this->talk_namespace
,
201 $this->pageTitle4
->getPrefixedText()
203 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
204 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
205 $this->assertPageEnd();
207 $this->assertDumpEnd();
210 function testCurrentStubPlain() {
211 // Preparing the dump
212 $fname = $this->getNewTempFile();
214 $dumper = new DumpBackup( [ '--output', 'file:' . $fname ] );
215 $dumper->startId
= $this->pageId1
;
216 $dumper->endId
= $this->pageId4 +
1;
217 $dumper->reporting
= false;
218 $dumper->setDB( $this->db
);
220 // Performing the dump
221 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
223 // Checking the dumped data
224 $this->assertDumpStart( $fname );
227 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
228 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
229 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
230 $this->assertPageEnd();
233 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
234 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
235 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
236 $this->assertPageEnd();
239 // -> Page is marked deleted. Hence not visible
242 $this->assertPageStart(
244 $this->talk_namespace
,
245 $this->pageTitle4
->getPrefixedText()
247 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
248 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
249 $this->assertPageEnd();
251 $this->assertDumpEnd();
254 function testCurrentStubGzip() {
255 $this->checkHasGzip();
257 // Preparing the dump
258 $fname = $this->getNewTempFile();
260 $dumper = new DumpBackup( [ '--output', 'gzip:' . $fname ] );
261 $dumper->startId
= $this->pageId1
;
262 $dumper->endId
= $this->pageId4 +
1;
263 $dumper->reporting
= false;
264 $dumper->setDB( $this->db
);
266 // Performing the dump
267 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
269 // Checking the dumped data
270 $this->gunzip( $fname );
271 $this->assertDumpStart( $fname );
274 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
275 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
276 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
277 $this->assertPageEnd();
280 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
281 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
282 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
283 $this->assertPageEnd();
286 // -> Page is marked deleted. Hence not visible
289 $this->assertPageStart(
291 $this->talk_namespace
,
292 $this->pageTitle4
->getPrefixedText()
294 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
295 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
296 $this->assertPageEnd();
298 $this->assertDumpEnd();
302 * xmldumps-backup typically performs a single dump that that writes
304 * - gzipped stubs of everything (meta-history)
305 * - gzipped stubs of latest revisions of all pages (meta-current)
306 * - gzipped stubs of latest revisions of all pages of namespage 0
309 * We reproduce such a setup with our mini fixture, although we omit
310 * chunks, and all the other gimmicks of xmldumps-backup.
312 function testXmlDumpsBackupUseCase() {
313 $this->checkHasGzip();
315 $fnameMetaHistory = $this->getNewTempFile();
316 $fnameMetaCurrent = $this->getNewTempFile();
317 $fnameArticles = $this->getNewTempFile();
319 $dumper = new DumpBackup( [ "--full", "--stub", "--output=gzip:" . $fnameMetaHistory,
320 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
321 "--output=gzip:" . $fnameArticles, "--filter=latest",
322 "--filter=notalk", "--filter=namespace:!NS_USER",
323 "--reporting=1000" ] );
324 $dumper->startId
= $this->pageId1
;
325 $dumper->endId
= $this->pageId4 +
1;
326 $dumper->setDB( $this->db
);
328 // xmldumps-backup uses reporting. We will not check the exact reported
329 // message, as they are dependent on the processing power of the used
330 // computer. We only check that reporting does not crash the dumping
331 // and that something is reported
332 $dumper->stderr
= fopen( 'php://output', 'a' );
333 if ( $dumper->stderr
=== false ) {
334 $this->fail( "Could not open stream for stderr" );
337 // Performing the dump
338 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
340 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
342 // Checking meta-history -------------------------------------------------
344 $this->gunzip( $fnameMetaHistory );
345 $this->assertDumpStart( $fnameMetaHistory );
348 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
349 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
350 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
351 $this->assertPageEnd();
354 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
355 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
356 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
357 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
358 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
359 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
360 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
361 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
362 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
363 $this->assertPageEnd();
366 // -> Page is marked deleted. Hence not visible
369 $this->assertPageStart(
371 $this->talk_namespace
,
372 $this->pageTitle4
->getPrefixedText()
374 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
375 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
376 $this->assertPageEnd();
378 $this->assertDumpEnd();
380 // Checking meta-current -------------------------------------------------
382 $this->gunzip( $fnameMetaCurrent );
383 $this->assertDumpStart( $fnameMetaCurrent );
386 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
387 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
388 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
389 $this->assertPageEnd();
392 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
393 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
394 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
395 $this->assertPageEnd();
398 // -> Page is marked deleted. Hence not visible
401 $this->assertPageStart(
403 $this->talk_namespace
,
404 $this->pageTitle4
->getPrefixedText()
406 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
407 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
408 $this->assertPageEnd();
410 $this->assertDumpEnd();
412 // Checking articles -------------------------------------------------
414 $this->gunzip( $fnameArticles );
415 $this->assertDumpStart( $fnameArticles );
418 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
419 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
420 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
421 $this->assertPageEnd();
424 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
425 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
426 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
427 $this->assertPageEnd();
430 // -> Page is marked deleted. Hence not visible
433 // -> Page is not in $this->namespace. Hence not visible
435 $this->assertDumpEnd();
437 $this->expectETAOutput();