3 * Tests for page dumps of BackupDumper
9 class BackupDumperPageTest
extends DumpTestCase
{
11 // We'll add several pages, revision and texts. The following variables hold the
13 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5;
14 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5;
15 private $revId1_1, $textId1_1;
16 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
17 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
18 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
19 private $revId4_1, $textId4_1;
20 private $namespace, $talk_namespace;
22 function addDBData() {
23 // be sure, titles created here using english namespace names
24 $this->setMwGlobals( array(
25 'wgLanguageCode' => 'en',
26 'wgContLang' => Language
::factory( 'en' ),
29 $this->tablesUsed
[] = 'page';
30 $this->tablesUsed
[] = 'revision';
31 $this->tablesUsed
[] = 'text';
34 $this->namespace = $this->getDefaultWikitextNS();
35 $this->talk_namespace
= NS_TALK
;
37 if ( $this->namespace === $this->talk_namespace
) {
38 // @todo work around this.
39 throw new MWException( "The default wikitext namespace is the talk namespace. "
40 . " We can't currently deal with that." );
43 $this->pageTitle1
= Title
::newFromText( 'BackupDumperTestP1', $this->namespace );
44 $page = WikiPage
::factory( $this->pageTitle1
);
45 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
46 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
47 $this->pageId1
= $page->getId();
49 $this->pageTitle2
= Title
::newFromText( 'BackupDumperTestP2', $this->namespace );
50 $page = WikiPage
::factory( $this->pageTitle2
);
51 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
52 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
53 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
54 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
55 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
56 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
57 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
58 "BackupDumperTestP2Text4 some additional Text ",
59 "BackupDumperTestP2Summary4 extra " );
60 $this->pageId2
= $page->getId();
62 $this->pageTitle3
= Title
::newFromText( 'BackupDumperTestP3', $this->namespace );
63 $page = WikiPage
::factory( $this->pageTitle3
);
64 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
65 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
66 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
67 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
68 $this->pageId3
= $page->getId();
69 $page->doDeleteArticle( "Testing ;)" );
71 $this->pageTitle4
= Title
::newFromText( 'BackupDumperTestP1', $this->talk_namespace
);
72 $page = WikiPage
::factory( $this->pageTitle4
);
73 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
74 "Talk about BackupDumperTestP1 Text1",
75 "Talk BackupDumperTestP1 Summary1" );
76 $this->pageId4
= $page->getId();
77 } catch ( Exception
$e ) {
78 // We'd love to pass $e directly. However, ... see
79 // documentation of exceptionFromAddDBData in
81 $this->exceptionFromAddDBData
= $e;
85 protected function setUp() {
88 // Since we will restrict dumping by page ranges (to allow
89 // working tests, even if the db gets prepopulated by a base
90 // class), we have to assert, that the page id are consecutively
93 array( $this->pageId2
, $this->pageId3
, $this->pageId4
),
94 array( $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ),
95 "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 $this->checkHasGzip();
236 // Preparing the dump
237 $fname = $this->getNewTempFile();
238 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) );
239 $dumper->startId
= $this->pageId1
;
240 $dumper->endId
= $this->pageId4 +
1;
241 $dumper->reporting
= false;
242 $dumper->setDb( $this->db
);
244 // Performing the dump
245 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
247 // Checking the dumped data
248 $this->gunzip( $fname );
249 $this->assertDumpStart( $fname );
252 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
253 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
254 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
255 $this->assertPageEnd();
258 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
259 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
260 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
261 $this->assertPageEnd();
264 // -> Page is marked deleted. Hence not visible
267 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
268 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
269 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
270 $this->assertPageEnd();
272 $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();