3 * Tests for page dumps of BackupDumper
10 class BackupDumperPageTest
extends DumpTestCase
{
12 // We'll add several pages, revision and texts. The following variables hold the
14 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5;
15 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5;
16 private $revId1_1, $textId1_1;
17 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
18 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
19 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
20 private $revId4_1, $textId4_1;
21 private $namespace, $talk_namespace;
23 function addDBData() {
24 // be sure, titles created here using english namespace names
25 $this->setMwGlobals( [
26 'wgLanguageCode' => 'en',
27 'wgContLang' => Language
::factory( 'en' ),
30 $this->tablesUsed
[] = 'page';
31 $this->tablesUsed
[] = 'revision';
32 $this->tablesUsed
[] = 'ip_changes';
33 $this->tablesUsed
[] = 'text';
36 $this->namespace = $this->getDefaultWikitextNS();
37 $this->talk_namespace
= NS_TALK
;
39 if ( $this->namespace === $this->talk_namespace
) {
40 // @todo work around this.
41 throw new MWException( "The default wikitext namespace is the talk namespace. "
42 . " We can't currently deal with that." );
45 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
46 $page = WikiPage
::factory( $this->pageTitle1
);
47 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
48 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
49 $this->pageId1
= $page->getId();
51 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
52 $page = WikiPage
::factory( $this->pageTitle2
);
53 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
54 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
55 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
56 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
57 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
58 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
59 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
60 "BackupDumperTestP2Text4 some additional Text ",
61 "BackupDumperTestP2Summary4 extra " );
62 $this->pageId2
= $page->getId();
64 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
65 $page = WikiPage
::factory( $this->pageTitle3
);
66 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
67 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
68 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
69 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
70 $this->pageId3
= $page->getId();
71 $page->doDeleteArticle( "Testing ;)" );
73 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
74 $page = WikiPage
::factory( $this->pageTitle4
);
75 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
76 "Talk about BackupDumperTestP1 Text1",
77 "Talk BackupDumperTestP1 Summary1" );
78 $this->pageId4
= $page->getId();
79 } catch ( Exception
$e ) {
80 // We'd love to pass $e directly. However, ... see
81 // documentation of exceptionFromAddDBData in
83 $this->exceptionFromAddDBData
= $e;
87 protected function setUp() {
90 // Since we will restrict dumping by page ranges (to allow
91 // working tests, even if the db gets prepopulated by a base
92 // class), we have to assert, that the page id are consecutively
95 [ $this->pageId2
, $this->pageId3
, $this->pageId4
],
96 [ $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ],
97 "Page ids increasing without holes" );
100 function testFullTextPlain() {
101 // Preparing the dump
102 $fname = $this->getNewTempFile();
104 $dumper = new DumpBackup();
105 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname ] );
106 $dumper->startId
= $this->pageId1
;
107 $dumper->endId
= $this->pageId4 +
1;
108 $dumper->setDB( $this->db
);
110 // Performing the dump
113 // Checking the dumped data
114 $this->assertDumpStart( $fname );
117 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
118 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
119 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
120 "BackupDumperTestP1Text1" );
121 $this->assertPageEnd();
124 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
125 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
126 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
127 "BackupDumperTestP2Text1" );
128 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
129 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
130 "BackupDumperTestP2Text2", $this->revId2_1
);
131 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
132 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
133 "BackupDumperTestP2Text3", $this->revId2_2
);
134 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
135 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
136 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
137 $this->assertPageEnd();
140 // -> Page is marked deleted. Hence not visible
143 $this->assertPageStart(
145 $this->talk_namespace
,
146 $this->pageTitle4
->getPrefixedText()
148 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
149 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
150 "Talk about BackupDumperTestP1 Text1" );
151 $this->assertPageEnd();
153 $this->assertDumpEnd();
156 function testFullStubPlain() {
157 // Preparing the dump
158 $fname = $this->getNewTempFile();
160 $dumper = new DumpBackup();
161 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname, '--stub' ] );
162 $dumper->startId
= $this->pageId1
;
163 $dumper->endId
= $this->pageId4 +
1;
164 $dumper->setDB( $this->db
);
166 // Performing the dump
169 // Checking the dumped data
170 $this->assertDumpStart( $fname );
173 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
174 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
175 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
176 $this->assertPageEnd();
179 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
180 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
181 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
182 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
183 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
184 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
185 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
186 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
187 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
188 $this->assertPageEnd();
191 // -> Page is marked deleted. Hence not visible
194 $this->assertPageStart(
196 $this->talk_namespace
,
197 $this->pageTitle4
->getPrefixedText()
199 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
200 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
201 $this->assertPageEnd();
203 $this->assertDumpEnd();
206 function testCurrentStubPlain() {
207 // Preparing the dump
208 $fname = $this->getNewTempFile();
210 $dumper = new DumpBackup( [ '--output', 'file:' . $fname ] );
211 $dumper->startId
= $this->pageId1
;
212 $dumper->endId
= $this->pageId4 +
1;
213 $dumper->reporting
= false;
214 $dumper->setDB( $this->db
);
216 // Performing the dump
217 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
219 // Checking the dumped data
220 $this->assertDumpStart( $fname );
223 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
224 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
225 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
226 $this->assertPageEnd();
229 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
230 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
231 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
232 $this->assertPageEnd();
235 // -> Page is marked deleted. Hence not visible
238 $this->assertPageStart(
240 $this->talk_namespace
,
241 $this->pageTitle4
->getPrefixedText()
243 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
244 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
245 $this->assertPageEnd();
247 $this->assertDumpEnd();
250 function testCurrentStubGzip() {
251 $this->checkHasGzip();
253 // Preparing the dump
254 $fname = $this->getNewTempFile();
256 $dumper = new DumpBackup( [ '--output', 'gzip:' . $fname ] );
257 $dumper->startId
= $this->pageId1
;
258 $dumper->endId
= $this->pageId4 +
1;
259 $dumper->reporting
= false;
260 $dumper->setDB( $this->db
);
262 // Performing the dump
263 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
265 // Checking the dumped data
266 $this->gunzip( $fname );
267 $this->assertDumpStart( $fname );
270 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
271 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
272 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
273 $this->assertPageEnd();
276 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
277 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
278 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
279 $this->assertPageEnd();
282 // -> Page is marked deleted. Hence not visible
285 $this->assertPageStart(
287 $this->talk_namespace
,
288 $this->pageTitle4
->getPrefixedText()
290 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
291 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
292 $this->assertPageEnd();
294 $this->assertDumpEnd();
298 * xmldumps-backup typically performs a single dump that that writes
300 * - gzipped stubs of everything (meta-history)
301 * - gzipped stubs of latest revisions of all pages (meta-current)
302 * - gzipped stubs of latest revisions of all pages of namespage 0
305 * We reproduce such a setup with our mini fixture, although we omit
306 * chunks, and all the other gimmicks of xmldumps-backup.
308 function testXmlDumpsBackupUseCase() {
309 $this->checkHasGzip();
311 $fnameMetaHistory = $this->getNewTempFile();
312 $fnameMetaCurrent = $this->getNewTempFile();
313 $fnameArticles = $this->getNewTempFile();
315 $dumper = new DumpBackup( [ "--full", "--stub", "--output=gzip:" . $fnameMetaHistory,
316 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
317 "--output=gzip:" . $fnameArticles, "--filter=latest",
318 "--filter=notalk", "--filter=namespace:!NS_USER",
319 "--reporting=1000" ] );
320 $dumper->startId
= $this->pageId1
;
321 $dumper->endId
= $this->pageId4 +
1;
322 $dumper->setDB( $this->db
);
324 // xmldumps-backup uses reporting. We will not check the exact reported
325 // message, as they are dependent on the processing power of the used
326 // computer. We only check that reporting does not crash the dumping
327 // and that something is reported
328 $dumper->stderr
= fopen( 'php://output', 'a' );
329 if ( $dumper->stderr
=== false ) {
330 $this->fail( "Could not open stream for stderr" );
333 // Performing the dump
334 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
336 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
338 // Checking meta-history -------------------------------------------------
340 $this->gunzip( $fnameMetaHistory );
341 $this->assertDumpStart( $fnameMetaHistory );
344 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
345 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
346 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
347 $this->assertPageEnd();
350 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
351 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
352 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
353 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
354 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
355 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
356 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
357 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
358 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
359 $this->assertPageEnd();
362 // -> Page is marked deleted. Hence not visible
365 $this->assertPageStart(
367 $this->talk_namespace
,
368 $this->pageTitle4
->getPrefixedText()
370 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
371 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
372 $this->assertPageEnd();
374 $this->assertDumpEnd();
376 // Checking meta-current -------------------------------------------------
378 $this->gunzip( $fnameMetaCurrent );
379 $this->assertDumpStart( $fnameMetaCurrent );
382 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
383 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
384 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
385 $this->assertPageEnd();
388 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
389 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
390 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
391 $this->assertPageEnd();
394 // -> Page is marked deleted. Hence not visible
397 $this->assertPageStart(
399 $this->talk_namespace
,
400 $this->pageTitle4
->getPrefixedText()
402 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
403 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
404 $this->assertPageEnd();
406 $this->assertDumpEnd();
408 // Checking articles -------------------------------------------------
410 $this->gunzip( $fnameArticles );
411 $this->assertDumpStart( $fnameArticles );
414 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
415 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
416 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
417 $this->assertPageEnd();
420 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
421 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
422 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
423 $this->assertPageEnd();
426 // -> Page is marked deleted. Hence not visible
429 // -> Page is not in $this->namespace. Hence not visible
431 $this->assertDumpEnd();
433 $this->expectETAOutput();