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;
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" );
99 function testFullTextPlain () {
100 // Preparing the dump
101 $fname = $this->getNewTempFile();
102 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
103 $dumper->startId
= $this->pageId1
;
104 $dumper->endId
= $this->pageId4 +
1;
105 $dumper->reporting
= false;
106 $dumper->setDb( $this->db
);
108 // Performing the dump
109 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
111 // Checking the dumped data
112 $this->assertDumpStart( $fname );
115 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
116 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
117 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
118 "BackupDumperTestP1Text1" );
119 $this->assertPageEnd();
122 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
123 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
124 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
125 "BackupDumperTestP2Text1" );
126 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
127 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
128 "BackupDumperTestP2Text2", $this->revId2_1
);
129 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
130 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
131 "BackupDumperTestP2Text3", $this->revId2_2
);
132 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
133 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
134 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
135 $this->assertPageEnd();
138 // -> Page is marked deleted. Hence not visible
141 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
142 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
143 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
144 "Talk about BackupDumperTestP1 Text1" );
145 $this->assertPageEnd();
147 $this->assertDumpEnd();
150 function testFullStubPlain () {
151 // Preparing the dump
152 $fname = $this->getNewTempFile();
153 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
154 $dumper->startId
= $this->pageId1
;
155 $dumper->endId
= $this->pageId4 +
1;
156 $dumper->reporting
= false;
157 $dumper->setDb( $this->db
);
159 // Performing the dump
160 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
162 // Checking the dumped data
163 $this->assertDumpStart( $fname );
166 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
167 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
168 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
169 $this->assertPageEnd();
172 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
173 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
174 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
175 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
176 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
177 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
178 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
179 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
180 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
181 $this->assertPageEnd();
184 // -> Page is marked deleted. Hence not visible
187 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
188 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
189 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
190 $this->assertPageEnd();
192 $this->assertDumpEnd();
195 function testCurrentStubPlain () {
196 // Preparing the dump
197 $fname = $this->getNewTempFile();
198 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
199 $dumper->startId
= $this->pageId1
;
200 $dumper->endId
= $this->pageId4 +
1;
201 $dumper->reporting
= false;
202 $dumper->setDb( $this->db
);
204 // Performing the dump
205 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
207 // Checking the dumped data
208 $this->assertDumpStart( $fname );
211 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
212 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
213 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
214 $this->assertPageEnd();
217 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
218 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
219 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
220 $this->assertPageEnd();
223 // -> Page is marked deleted. Hence not visible
226 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
227 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
228 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
229 $this->assertPageEnd();
231 $this->assertDumpEnd();
234 function testCurrentStubGzip () {
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();
276 function testXmlDumpsBackupUseCase () {
277 // xmldumps-backup typically performs a single dump that that writes
279 // * gzipped stubs of everything (meta-history)
280 // * gzipped stubs of latest revisions of all pages (meta-current)
281 // * gzipped stubs of latest revisions of all pages of namespage 0
284 // We reproduce such a setup with our mini fixture, although we omit
285 // chunks, and all the other gimmicks of xmldumps-backup.
287 $fnameMetaHistory = $this->getNewTempFile();
288 $fnameMetaCurrent = $this->getNewTempFile();
289 $fnameArticles = $this->getNewTempFile();
291 $dumper = new BackupDumper( array ( "--output=gzip:" . $fnameMetaHistory,
292 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
293 "--output=gzip:" . $fnameArticles, "--filter=latest",
294 "--filter=notalk", "--filter=namespace:!NS_USER",
295 "--reporting=1000" ) );
296 $dumper->startId
= $this->pageId1
;
297 $dumper->endId
= $this->pageId4 +
1;
298 $dumper->setDb( $this->db
);
300 // xmldumps-backup uses reporting. We will not check the exact reported
301 // message, as they are dependent on the processing power of the used
302 // computer. We only check that reporting does not crash the dumping
303 // and that something is reported
304 $dumper->stderr
= fopen( 'php://output', 'a' );
305 if ( $dumper->stderr
=== FALSE ) {
306 $this->fail( "Could not open stream for stderr" );
309 // Performing the dump
310 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
312 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
314 // Checking meta-history -------------------------------------------------
316 $this->gunzip( $fnameMetaHistory );
317 $this->assertDumpStart( $fnameMetaHistory );
320 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
321 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
322 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
323 $this->assertPageEnd();
326 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
327 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
328 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
329 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
330 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
331 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
332 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
333 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
334 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
335 $this->assertPageEnd();
338 // -> Page is marked deleted. Hence not visible
341 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
342 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
343 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
344 $this->assertPageEnd();
346 $this->assertDumpEnd();
348 // Checking meta-current -------------------------------------------------
350 $this->gunzip( $fnameMetaCurrent );
351 $this->assertDumpStart( $fnameMetaCurrent );
354 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
355 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
356 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
357 $this->assertPageEnd();
360 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
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( $this->pageId4
, $this->talk_namespace
, $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 articles -------------------------------------------------
378 $this->gunzip( $fnameArticles );
379 $this->assertDumpStart( $fnameArticles );
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 // -> Page is not in $this->namespace. Hence not visible
399 $this->assertDumpEnd();
401 $this->expectETAOutput();