3 * Tests for page dumps of BackupDumper
8 class BackupDumperPageTest
extends DumpTestCase
{
10 // We'll add several pages, revision and texts. The following variables hold the
12 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5;
13 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5;
14 private $revId1_1, $textId1_1;
15 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
16 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
17 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
18 private $revId4_1, $textId4_1;
19 private $namespace, $talk_namespace;
21 function addDBData() {
22 // be sure, titles created here using english namespace names
23 $this->setMwGlobals( array(
24 'wgLanguageCode' => 'en',
25 'wgContLang' => Language
::factory( 'en' ),
28 $this->tablesUsed
[] = 'page';
29 $this->tablesUsed
[] = 'revision';
30 $this->tablesUsed
[] = 'text';
33 $this->namespace = $this->getDefaultWikitextNS();
34 $this->talk_namespace
= NS_TALK
;
36 if ( $this->namespace === $this->talk_namespace
) {
37 // @todo work around this.
38 throw new MWException( "The default wikitext namespace is the talk namespace. "
39 . " We can't currently deal with that." );
42 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
43 $page = WikiPage
::factory( $this->pageTitle1
);
44 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
45 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
46 $this->pageId1
= $page->getId();
48 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
49 $page = WikiPage
::factory( $this->pageTitle2
);
50 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
51 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
52 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
53 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
54 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
55 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
56 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
57 "BackupDumperTestP2Text4 some additional Text ",
58 "BackupDumperTestP2Summary4 extra " );
59 $this->pageId2
= $page->getId();
61 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
62 $page = WikiPage
::factory( $this->pageTitle3
);
63 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
64 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
65 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
66 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
67 $this->pageId3
= $page->getId();
68 $page->doDeleteArticle( "Testing ;)" );
70 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
71 $page = WikiPage
::factory( $this->pageTitle4
);
72 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
73 "Talk about BackupDumperTestP1 Text1",
74 "Talk BackupDumperTestP1 Summary1" );
75 $this->pageId4
= $page->getId();
76 } catch ( Exception
$e ) {
77 // We'd love to pass $e directly. However, ... see
78 // documentation of exceptionFromAddDBData in
80 $this->exceptionFromAddDBData
= $e;
84 protected function setUp() {
87 // Since we will restrict dumping by page ranges (to allow
88 // working tests, even if the db gets prepopulated by a base
89 // class), we have to assert, that the page id are consecutively
92 array( $this->pageId2
, $this->pageId3
, $this->pageId4
),
93 array( $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ),
94 "Page ids increasing without holes" );
97 function testFullTextPlain() {
99 $fname = $this->getNewTempFile();
100 $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
101 $dumper->startId
= $this->pageId1
;
102 $dumper->endId
= $this->pageId4 +
1;
103 $dumper->reporting
= false;
104 $dumper->setDb( $this->db
);
106 // Performing the dump
107 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
109 // Checking the dumped data
110 $this->assertDumpStart( $fname );
113 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
114 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
115 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
116 "BackupDumperTestP1Text1" );
117 $this->assertPageEnd();
120 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
121 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
122 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
123 "BackupDumperTestP2Text1" );
124 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
125 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
126 "BackupDumperTestP2Text2", $this->revId2_1
);
127 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
128 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
129 "BackupDumperTestP2Text3", $this->revId2_2
);
130 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
131 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
132 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
133 $this->assertPageEnd();
136 // -> Page is marked deleted. Hence not visible
139 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
140 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
141 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
142 "Talk about BackupDumperTestP1 Text1" );
143 $this->assertPageEnd();
145 $this->assertDumpEnd();
148 function testFullStubPlain() {
149 // Preparing the dump
150 $fname = $this->getNewTempFile();
151 $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
152 $dumper->startId
= $this->pageId1
;
153 $dumper->endId
= $this->pageId4 +
1;
154 $dumper->reporting
= false;
155 $dumper->setDb( $this->db
);
157 // Performing the dump
158 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
160 // Checking the dumped data
161 $this->assertDumpStart( $fname );
164 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
165 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
166 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
167 $this->assertPageEnd();
170 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
171 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
172 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
173 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
174 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
175 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
176 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
177 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
178 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
179 $this->assertPageEnd();
182 // -> Page is marked deleted. Hence not visible
185 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
186 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
187 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
188 $this->assertPageEnd();
190 $this->assertDumpEnd();
193 function testCurrentStubPlain() {
194 // Preparing the dump
195 $fname = $this->getNewTempFile();
196 $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
197 $dumper->startId
= $this->pageId1
;
198 $dumper->endId
= $this->pageId4 +
1;
199 $dumper->reporting
= false;
200 $dumper->setDb( $this->db
);
202 // Performing the dump
203 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
205 // Checking the dumped data
206 $this->assertDumpStart( $fname );
209 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
210 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
211 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
212 $this->assertPageEnd();
215 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
216 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
217 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
218 $this->assertPageEnd();
221 // -> Page is marked deleted. Hence not visible
224 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
225 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
226 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
227 $this->assertPageEnd();
229 $this->assertDumpEnd();
232 function testCurrentStubGzip() {
233 $this->checkHasGzip();
235 // Preparing the dump
236 $fname = $this->getNewTempFile();
237 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) );
238 $dumper->startId
= $this->pageId1
;
239 $dumper->endId
= $this->pageId4 +
1;
240 $dumper->reporting
= false;
241 $dumper->setDb( $this->db
);
243 // Performing the dump
244 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
246 // Checking the dumped data
247 $this->gunzip( $fname );
248 $this->assertDumpStart( $fname );
251 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
252 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
253 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
254 $this->assertPageEnd();
257 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
258 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
259 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
260 $this->assertPageEnd();
263 // -> Page is marked deleted. Hence not visible
266 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
267 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
268 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
269 $this->assertPageEnd();
271 $this->assertDumpEnd();
275 function testXmlDumpsBackupUseCase() {
276 // xmldumps-backup typically performs a single dump that that writes
278 // * gzipped stubs of everything (meta-history)
279 // * gzipped stubs of latest revisions of all pages (meta-current)
280 // * gzipped stubs of latest revisions of all pages of namespage 0
283 // We reproduce such a setup with our mini fixture, although we omit
284 // chunks, and all the other gimmicks of xmldumps-backup.
286 $this->checkHasGzip();
288 $fnameMetaHistory = $this->getNewTempFile();
289 $fnameMetaCurrent = $this->getNewTempFile();
290 $fnameArticles = $this->getNewTempFile();
292 $dumper = new BackupDumper( array( "--output=gzip:" . $fnameMetaHistory,
293 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
294 "--output=gzip:" . $fnameArticles, "--filter=latest",
295 "--filter=notalk", "--filter=namespace:!NS_USER",
296 "--reporting=1000" ) );
297 $dumper->startId
= $this->pageId1
;
298 $dumper->endId
= $this->pageId4 +
1;
299 $dumper->setDb( $this->db
);
301 // xmldumps-backup uses reporting. We will not check the exact reported
302 // message, as they are dependent on the processing power of the used
303 // computer. We only check that reporting does not crash the dumping
304 // and that something is reported
305 $dumper->stderr
= fopen( 'php://output', 'a' );
306 if ( $dumper->stderr
=== false ) {
307 $this->fail( "Could not open stream for stderr" );
310 // Performing the dump
311 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
313 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
315 // Checking meta-history -------------------------------------------------
317 $this->gunzip( $fnameMetaHistory );
318 $this->assertDumpStart( $fnameMetaHistory );
321 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
322 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
323 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
324 $this->assertPageEnd();
327 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
328 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
329 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
330 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
331 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
332 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
333 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
334 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
335 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
336 $this->assertPageEnd();
339 // -> Page is marked deleted. Hence not visible
342 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
343 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
344 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
345 $this->assertPageEnd();
347 $this->assertDumpEnd();
349 // Checking meta-current -------------------------------------------------
351 $this->gunzip( $fnameMetaCurrent );
352 $this->assertDumpStart( $fnameMetaCurrent );
355 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
356 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
357 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
358 $this->assertPageEnd();
361 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
362 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
363 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
364 $this->assertPageEnd();
367 // -> Page is marked deleted. Hence not visible
370 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
371 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
372 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
373 $this->assertPageEnd();
375 $this->assertDumpEnd();
377 // Checking articles -------------------------------------------------
379 $this->gunzip( $fnameArticles );
380 $this->assertDumpStart( $fnameArticles );
383 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
384 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
385 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
386 $this->assertPageEnd();
389 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
390 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
391 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
392 $this->assertPageEnd();
395 // -> Page is marked deleted. Hence not visible
398 // -> Page is not in $this->namespace. Hence not visible
400 $this->assertDumpEnd();
402 $this->expectETAOutput();