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 $this->tablesUsed
[] = 'page';
23 $this->tablesUsed
[] = 'revision';
24 $this->tablesUsed
[] = 'text';
27 $this->namespace = $this->getDefaultWikitextNS();
28 $this->talk_namespace
= NS_TALK
;
30 if ( $this->namespace === $this->talk_namespace
) {
31 //@todo: work around this.
32 throw new MWException( "The default wikitext namespace is the talk namespace. "
33 . " We can't currently deal with that.");
36 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
37 $page = WikiPage
::factory( $this->pageTitle1
);
38 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
39 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
40 $this->pageId1
= $page->getId();
42 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
43 $page = WikiPage
::factory( $this->pageTitle2
);
44 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
45 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
46 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
47 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
48 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
49 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
50 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
51 "BackupDumperTestP2Text4 some additional Text ",
52 "BackupDumperTestP2Summary4 extra " );
53 $this->pageId2
= $page->getId();
55 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
56 $page = WikiPage
::factory( $this->pageTitle3
);
57 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
58 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
59 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
60 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
61 $this->pageId3
= $page->getId();
62 $page->doDeleteArticle( "Testing ;)" );
64 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
65 $page = WikiPage
::factory( $this->pageTitle4
);
66 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
67 "Talk about BackupDumperTestP1 Text1",
68 "Talk BackupDumperTestP1 Summary1" );
69 $this->pageId4
= $page->getId();
70 } catch ( Exception
$e ) {
71 // We'd love to pass $e directly. However, ... see
72 // documentation of exceptionFromAddDBData in
74 $this->exceptionFromAddDBData
= $e;
79 protected function setUp() {
82 $this->setMwGlobals( array(
83 'wgLanguageCode' => 'en',
84 'wgContLang' => Language
::factory( 'en' ),
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" );
98 function testFullTextPlain () {
100 $fname = $this->getNewTempFile();
101 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
102 $dumper->startId
= $this->pageId1
;
103 $dumper->endId
= $this->pageId4 +
1;
104 $dumper->reporting
= false;
105 $dumper->setDb( $this->db
);
107 // Performing the dump
108 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
110 // Checking the dumped data
111 $this->assertDumpStart( $fname );
114 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
115 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
116 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
117 "BackupDumperTestP1Text1" );
118 $this->assertPageEnd();
121 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
122 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
123 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
124 "BackupDumperTestP2Text1" );
125 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
126 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
127 "BackupDumperTestP2Text2", $this->revId2_1
);
128 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
129 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
130 "BackupDumperTestP2Text3", $this->revId2_2
);
131 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
132 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
133 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
134 $this->assertPageEnd();
137 // -> Page is marked deleted. Hence not visible
140 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
141 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
142 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
143 "Talk about BackupDumperTestP1 Text1" );
144 $this->assertPageEnd();
146 $this->assertDumpEnd();
149 function testFullStubPlain () {
150 // Preparing the dump
151 $fname = $this->getNewTempFile();
152 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
153 $dumper->startId
= $this->pageId1
;
154 $dumper->endId
= $this->pageId4 +
1;
155 $dumper->reporting
= false;
156 $dumper->setDb( $this->db
);
158 // Performing the dump
159 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
161 // Checking the dumped data
162 $this->assertDumpStart( $fname );
165 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
166 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
167 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
168 $this->assertPageEnd();
171 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
172 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
173 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
174 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
175 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
176 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
177 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
178 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
179 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
180 $this->assertPageEnd();
183 // -> Page is marked deleted. Hence not visible
186 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
187 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
188 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
189 $this->assertPageEnd();
191 $this->assertDumpEnd();
194 function testCurrentStubPlain () {
195 // Preparing the dump
196 $fname = $this->getNewTempFile();
197 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
198 $dumper->startId
= $this->pageId1
;
199 $dumper->endId
= $this->pageId4 +
1;
200 $dumper->reporting
= false;
201 $dumper->setDb( $this->db
);
203 // Performing the dump
204 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
206 // Checking the dumped data
207 $this->assertDumpStart( $fname );
210 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
211 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
212 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
213 $this->assertPageEnd();
216 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
217 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
218 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
219 $this->assertPageEnd();
222 // -> Page is marked deleted. Hence not visible
225 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
226 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
227 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
228 $this->assertPageEnd();
230 $this->assertDumpEnd();
233 function testCurrentStubGzip () {
234 // Preparing the dump
235 $fname = $this->getNewTempFile();
236 $dumper = new BackupDumper( array ( "--output=gzip:" . $fname ) );
237 $dumper->startId
= $this->pageId1
;
238 $dumper->endId
= $this->pageId4 +
1;
239 $dumper->reporting
= false;
240 $dumper->setDb( $this->db
);
242 // Performing the dump
243 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
245 // Checking the dumped data
246 $this->gunzip( $fname );
247 $this->assertDumpStart( $fname );
250 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
251 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
252 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
253 $this->assertPageEnd();
256 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
257 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
258 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
259 $this->assertPageEnd();
262 // -> Page is marked deleted. Hence not visible
265 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
266 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
267 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
268 $this->assertPageEnd();
270 $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 $fnameMetaHistory = $this->getNewTempFile();
287 $fnameMetaCurrent = $this->getNewTempFile();
288 $fnameArticles = $this->getNewTempFile();
290 $dumper = new BackupDumper( array ( "--output=gzip:" . $fnameMetaHistory,
291 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
292 "--output=gzip:" . $fnameArticles, "--filter=latest",
293 "--filter=notalk", "--filter=namespace:!NS_USER",
294 "--reporting=1000" ) );
295 $dumper->startId
= $this->pageId1
;
296 $dumper->endId
= $this->pageId4 +
1;
297 $dumper->setDb( $this->db
);
299 // xmldumps-backup uses reporting. We will not check the exact reported
300 // message, as they are dependent on the processing power of the used
301 // computer. We only check that reporting does not crash the dumping
302 // and that something is reported
303 $dumper->stderr
= fopen( 'php://output', 'a' );
304 if ( $dumper->stderr
=== FALSE ) {
305 $this->fail( "Could not open stream for stderr" );
308 // Performing the dump
309 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
311 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
313 // Checking meta-history -------------------------------------------------
315 $this->gunzip( $fnameMetaHistory );
316 $this->assertDumpStart( $fnameMetaHistory );
319 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
320 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
321 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
322 $this->assertPageEnd();
325 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
326 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
327 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
328 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
329 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
330 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
331 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
332 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
333 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
334 $this->assertPageEnd();
337 // -> Page is marked deleted. Hence not visible
340 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
341 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
342 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
343 $this->assertPageEnd();
345 $this->assertDumpEnd();
347 // Checking meta-current -------------------------------------------------
349 $this->gunzip( $fnameMetaCurrent );
350 $this->assertDumpStart( $fnameMetaCurrent );
353 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
354 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
355 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
356 $this->assertPageEnd();
359 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
360 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
361 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
362 $this->assertPageEnd();
365 // -> Page is marked deleted. Hence not visible
368 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
369 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
370 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
371 $this->assertPageEnd();
373 $this->assertDumpEnd();
375 // Checking articles -------------------------------------------------
377 $this->gunzip( $fnameArticles );
378 $this->assertDumpStart( $fnameArticles );
381 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
382 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
383 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
384 $this->assertPageEnd();
387 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
388 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
389 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
390 $this->assertPageEnd();
393 // -> Page is marked deleted. Hence not visible
396 // -> Page is not in $this->namespace. Hence not visible
398 $this->assertDumpEnd();
400 $this->expectETAOutput();