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 // Since we will restrict dumping by page ranges (to allow
83 // working tests, even if the db gets prepopulated by a base
84 // class), we have to assert, that the page id are consecutively
87 array( $this->pageId2
, $this->pageId3
, $this->pageId4
),
88 array( $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ),
89 "Page ids increasing without holes" );
93 function testFullTextPlain () {
95 $fname = $this->getNewTempFile();
96 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
97 $dumper->startId
= $this->pageId1
;
98 $dumper->endId
= $this->pageId4 +
1;
99 $dumper->reporting
= false;
100 $dumper->setDb( $this->db
);
102 // Performing the dump
103 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
105 // Checking the dumped data
106 $this->assertDumpStart( $fname );
109 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
110 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
111 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
112 "BackupDumperTestP1Text1" );
113 $this->assertPageEnd();
116 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
117 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
118 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
119 "BackupDumperTestP2Text1" );
120 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
121 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
122 "BackupDumperTestP2Text2", $this->revId2_1
);
123 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
124 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
125 "BackupDumperTestP2Text3", $this->revId2_2
);
126 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
127 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
128 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
129 $this->assertPageEnd();
132 // -> Page is marked deleted. Hence not visible
135 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
136 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
137 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
138 "Talk about BackupDumperTestP1 Text1" );
139 $this->assertPageEnd();
141 $this->assertDumpEnd();
144 function testFullStubPlain () {
145 // Preparing the dump
146 $fname = $this->getNewTempFile();
147 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
148 $dumper->startId
= $this->pageId1
;
149 $dumper->endId
= $this->pageId4 +
1;
150 $dumper->reporting
= false;
151 $dumper->setDb( $this->db
);
153 // Performing the dump
154 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
156 // Checking the dumped data
157 $this->assertDumpStart( $fname );
160 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
161 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
162 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
163 $this->assertPageEnd();
166 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
167 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
168 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
169 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
170 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
171 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
172 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
173 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
174 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
175 $this->assertPageEnd();
178 // -> Page is marked deleted. Hence not visible
181 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
182 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
183 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
184 $this->assertPageEnd();
186 $this->assertDumpEnd();
189 function testCurrentStubPlain () {
190 // Preparing the dump
191 $fname = $this->getNewTempFile();
192 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
193 $dumper->startId
= $this->pageId1
;
194 $dumper->endId
= $this->pageId4 +
1;
195 $dumper->reporting
= false;
196 $dumper->setDb( $this->db
);
198 // Performing the dump
199 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
201 // Checking the dumped data
202 $this->assertDumpStart( $fname );
205 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
206 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
207 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
208 $this->assertPageEnd();
211 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
212 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
213 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
214 $this->assertPageEnd();
217 // -> Page is marked deleted. Hence not visible
220 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
221 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
222 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
223 $this->assertPageEnd();
225 $this->assertDumpEnd();
228 function testCurrentStubGzip () {
229 // Preparing the dump
230 $fname = $this->getNewTempFile();
231 $dumper = new BackupDumper( array ( "--output=gzip:" . $fname ) );
232 $dumper->startId
= $this->pageId1
;
233 $dumper->endId
= $this->pageId4 +
1;
234 $dumper->reporting
= false;
235 $dumper->setDb( $this->db
);
237 // Performing the dump
238 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
240 // Checking the dumped data
241 $this->gunzip( $fname );
242 $this->assertDumpStart( $fname );
245 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
246 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
247 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
248 $this->assertPageEnd();
251 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
252 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
253 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
254 $this->assertPageEnd();
257 // -> Page is marked deleted. Hence not visible
260 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
261 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
262 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
263 $this->assertPageEnd();
265 $this->assertDumpEnd();
270 function testXmlDumpsBackupUseCase () {
271 // xmldumps-backup typically performs a single dump that that writes
273 // * gzipped stubs of everything (meta-history)
274 // * gzipped stubs of latest revisions of all pages (meta-current)
275 // * gzipped stubs of latest revisions of all pages of namespage 0
278 // We reproduce such a setup with our mini fixture, although we omit
279 // chunks, and all the other gimmicks of xmldumps-backup.
281 $fnameMetaHistory = $this->getNewTempFile();
282 $fnameMetaCurrent = $this->getNewTempFile();
283 $fnameArticles = $this->getNewTempFile();
285 $dumper = new BackupDumper( array ( "--output=gzip:" . $fnameMetaHistory,
286 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
287 "--output=gzip:" . $fnameArticles, "--filter=latest",
288 "--filter=notalk", "--filter=namespace:!NS_USER",
289 "--reporting=1000" ) );
290 $dumper->startId
= $this->pageId1
;
291 $dumper->endId
= $this->pageId4 +
1;
292 $dumper->setDb( $this->db
);
294 // xmldumps-backup uses reporting. We will not check the exact reported
295 // message, as they are dependent on the processing power of the used
296 // computer. We only check that reporting does not crash the dumping
297 // and that something is reported
298 $dumper->stderr
= fopen( 'php://output', 'a' );
299 if ( $dumper->stderr
=== FALSE ) {
300 $this->fail( "Could not open stream for stderr" );
303 // Performing the dump
304 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
306 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
308 // Checking meta-history -------------------------------------------------
310 $this->gunzip( $fnameMetaHistory );
311 $this->assertDumpStart( $fnameMetaHistory );
314 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
315 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
316 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
317 $this->assertPageEnd();
320 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
321 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
322 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
323 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
324 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
325 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
326 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
327 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
328 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
329 $this->assertPageEnd();
332 // -> Page is marked deleted. Hence not visible
335 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
336 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
337 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
338 $this->assertPageEnd();
340 $this->assertDumpEnd();
342 // Checking meta-current -------------------------------------------------
344 $this->gunzip( $fnameMetaCurrent );
345 $this->assertDumpStart( $fnameMetaCurrent );
348 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
349 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
350 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
351 $this->assertPageEnd();
354 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
355 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
356 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
357 $this->assertPageEnd();
360 // -> Page is marked deleted. Hence not visible
363 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
364 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
365 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
366 $this->assertPageEnd();
368 $this->assertDumpEnd();
370 // Checking articles -------------------------------------------------
372 $this->gunzip( $fnameArticles );
373 $this->assertDumpStart( $fnameArticles );
376 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
377 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
378 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
379 $this->assertPageEnd();
382 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
383 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
384 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
385 $this->assertPageEnd();
388 // -> Page is marked deleted. Hence not visible
391 // -> Page is not in $this->namespace. Hence not visible
393 $this->assertDumpEnd();
395 $this->expectETAOutput();