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 $this->checkHasGzip();
237 // Preparing the dump
238 $fname = $this->getNewTempFile();
239 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) );
240 $dumper->startId
= $this->pageId1
;
241 $dumper->endId
= $this->pageId4 +
1;
242 $dumper->reporting
= false;
243 $dumper->setDb( $this->db
);
245 // Performing the dump
246 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
248 // Checking the dumped data
249 $this->gunzip( $fname );
250 $this->assertDumpStart( $fname );
253 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
254 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
255 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
256 $this->assertPageEnd();
259 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
260 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
261 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
262 $this->assertPageEnd();
265 // -> Page is marked deleted. Hence not visible
268 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
269 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
270 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
271 $this->assertPageEnd();
273 $this->assertDumpEnd();
277 function testXmlDumpsBackupUseCase() {
278 // xmldumps-backup typically performs a single dump that that writes
280 // * gzipped stubs of everything (meta-history)
281 // * gzipped stubs of latest revisions of all pages (meta-current)
282 // * gzipped stubs of latest revisions of all pages of namespage 0
285 // We reproduce such a setup with our mini fixture, although we omit
286 // chunks, and all the other gimmicks of xmldumps-backup.
288 $this->checkHasGzip();
290 $fnameMetaHistory = $this->getNewTempFile();
291 $fnameMetaCurrent = $this->getNewTempFile();
292 $fnameArticles = $this->getNewTempFile();
294 $dumper = new BackupDumper( array( "--output=gzip:" . $fnameMetaHistory,
295 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
296 "--output=gzip:" . $fnameArticles, "--filter=latest",
297 "--filter=notalk", "--filter=namespace:!NS_USER",
298 "--reporting=1000" ) );
299 $dumper->startId
= $this->pageId1
;
300 $dumper->endId
= $this->pageId4 +
1;
301 $dumper->setDb( $this->db
);
303 // xmldumps-backup uses reporting. We will not check the exact reported
304 // message, as they are dependent on the processing power of the used
305 // computer. We only check that reporting does not crash the dumping
306 // and that something is reported
307 $dumper->stderr
= fopen( 'php://output', 'a' );
308 if ( $dumper->stderr
=== false ) {
309 $this->fail( "Could not open stream for stderr" );
312 // Performing the dump
313 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
315 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
317 // Checking meta-history -------------------------------------------------
319 $this->gunzip( $fnameMetaHistory );
320 $this->assertDumpStart( $fnameMetaHistory );
323 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
324 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
325 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
326 $this->assertPageEnd();
329 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
330 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
331 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
332 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
333 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1
);
334 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
335 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2
);
336 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
337 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
338 $this->assertPageEnd();
341 // -> Page is marked deleted. Hence not visible
344 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
345 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
346 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
347 $this->assertPageEnd();
349 $this->assertDumpEnd();
351 // Checking meta-current -------------------------------------------------
353 $this->gunzip( $fnameMetaCurrent );
354 $this->assertDumpStart( $fnameMetaCurrent );
357 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
358 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
359 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
360 $this->assertPageEnd();
363 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
364 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
365 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
366 $this->assertPageEnd();
369 // -> Page is marked deleted. Hence not visible
372 $this->assertPageStart( $this->pageId4
, $this->talk_namespace
, $this->pageTitle4
->getPrefixedText() );
373 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
374 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
375 $this->assertPageEnd();
377 $this->assertDumpEnd();
379 // Checking articles -------------------------------------------------
381 $this->gunzip( $fnameArticles );
382 $this->assertDumpStart( $fnameArticles );
385 $this->assertPageStart( $this->pageId1
, $this->namespace, $this->pageTitle1
->getPrefixedText() );
386 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
387 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
388 $this->assertPageEnd();
391 $this->assertPageStart( $this->pageId2
, $this->namespace, $this->pageTitle2
->getPrefixedText() );
392 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
393 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3
);
394 $this->assertPageEnd();
397 // -> Page is marked deleted. Hence not visible
400 // -> Page is not in $this->namespace. Hence not visible
402 $this->assertDumpEnd();
404 $this->expectETAOutput();