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 $revId1_1, $textId1_1;
14 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
15 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
16 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
17 private $revId4_1, $textId4_1;
19 function addDBData() {
20 $this->tablesUsed
[] = 'page';
21 $this->tablesUsed
[] = 'revision';
22 $this->tablesUsed
[] = 'text';
25 $title = Title
::newFromText( 'BackupDumperTestP1' );
26 $page = WikiPage
::factory( $title );
27 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
28 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
29 $this->pageId1
= $page->getId();
31 $title = Title
::newFromText( 'BackupDumperTestP2' );
32 $page = WikiPage
::factory( $title );
33 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
34 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
35 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
36 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
37 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
38 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
39 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
40 "BackupDumperTestP2Text4 some additional Text ",
41 "BackupDumperTestP2Summary4 extra " );
42 $this->pageId2
= $page->getId();
44 $title = Title
::newFromText( 'BackupDumperTestP3' );
45 $page = WikiPage
::factory( $title );
46 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
47 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
48 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
49 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
50 $this->pageId3
= $page->getId();
51 $page->doDeleteArticle( "Testing ;)" );
53 $title = Title
::newFromText( 'BackupDumperTestP1', NS_TALK
);
54 $page = WikiPage
::factory( $title );
55 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
56 "Talk about BackupDumperTestP1 Text1",
57 "Talk BackupDumperTestP1 Summary1" );
58 $this->pageId4
= $page->getId();
59 } catch ( Exception
$e ) {
60 // We'd love to pass $e directly. However, ... see
61 // documentation of exceptionFromAddDBData in
63 $this->exceptionFromAddDBData
= $e;
68 protected function setUp() {
71 // Since we will restrict dumping by page ranges (to allow
72 // working tests, even if the db gets prepopulated by a base
73 // class), we have to assert, that the page id are consecutively
76 array( $this->pageId2
, $this->pageId3
, $this->pageId4
),
77 array( $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ),
78 "Page ids increasing without holes" );
82 function testFullTextPlain () {
84 $fname = $this->getNewTempFile();
85 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
86 $dumper->startId
= $this->pageId1
;
87 $dumper->endId
= $this->pageId4 +
1;
88 $dumper->reporting
= false;
89 $dumper->setDb( $this->db
);
91 // Performing the dump
92 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
94 // Checking the dumped data
95 $this->assertDumpStart( $fname );
98 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
99 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
100 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
101 "BackupDumperTestP1Text1" );
102 $this->assertPageEnd();
105 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
106 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
107 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
108 "BackupDumperTestP2Text1" );
109 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
110 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
111 "BackupDumperTestP2Text2" );
112 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
113 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
114 "BackupDumperTestP2Text3" );
115 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
116 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
117 "BackupDumperTestP2Text4 some additional Text" );
118 $this->assertPageEnd();
121 // -> Page is marked deleted. Hence not visible
124 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
125 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
126 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
127 "Talk about BackupDumperTestP1 Text1" );
128 $this->assertPageEnd();
130 $this->assertDumpEnd();
133 function testFullStubPlain () {
134 // Preparing the dump
135 $fname = $this->getNewTempFile();
136 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
137 $dumper->startId
= $this->pageId1
;
138 $dumper->endId
= $this->pageId4 +
1;
139 $dumper->reporting
= false;
140 $dumper->setDb( $this->db
);
142 // Performing the dump
143 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
145 // Checking the dumped data
146 $this->assertDumpStart( $fname );
149 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
150 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
151 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
152 $this->assertPageEnd();
155 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
156 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
157 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
158 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
159 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95" );
160 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
161 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r" );
162 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
163 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
164 $this->assertPageEnd();
167 // -> Page is marked deleted. Hence not visible
170 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
171 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
172 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
173 $this->assertPageEnd();
175 $this->assertDumpEnd();
178 function testCurrentStubPlain () {
179 // Preparing the dump
180 $fname = $this->getNewTempFile();
181 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
182 $dumper->startId
= $this->pageId1
;
183 $dumper->endId
= $this->pageId4 +
1;
184 $dumper->reporting
= false;
185 $dumper->setDb( $this->db
);
187 // Performing the dump
188 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
190 // Checking the dumped data
191 $this->assertDumpStart( $fname );
194 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
195 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
196 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
197 $this->assertPageEnd();
200 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
201 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
202 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
203 $this->assertPageEnd();
206 // -> Page is marked deleted. Hence not visible
209 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
210 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
211 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
212 $this->assertPageEnd();
214 $this->assertDumpEnd();
217 function testCurrentStubGzip () {
218 // Preparing the dump
219 $fname = $this->getNewTempFile();
220 $dumper = new BackupDumper( array ( "--output=gzip:" . $fname ) );
221 $dumper->startId
= $this->pageId1
;
222 $dumper->endId
= $this->pageId4 +
1;
223 $dumper->reporting
= false;
224 $dumper->setDb( $this->db
);
226 // Performing the dump
227 $dumper->dump( WikiExporter
::CURRENT
, WikiExporter
::STUB
);
229 // Checking the dumped data
230 $this->gunzip( $fname );
231 $this->assertDumpStart( $fname );
234 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
235 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
236 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
237 $this->assertPageEnd();
240 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
241 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
242 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
243 $this->assertPageEnd();
246 // -> Page is marked deleted. Hence not visible
249 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
250 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
251 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
252 $this->assertPageEnd();
254 $this->assertDumpEnd();
259 function testXmlDumpsBackupUseCase () {
260 // xmldumps-backup typically performs a single dump that that writes
262 // * gzipped stubs of everything (meta-history)
263 // * gzipped stubs of latest revisions of all pages (meta-current)
264 // * gzipped stubs of latest revisions of all pages of namespage 0
267 // We reproduce such a setup with our mini fixture, although we omit
268 // chunks, and all the other gimmicks of xmldumps-backup.
270 $fnameMetaHistory = $this->getNewTempFile();
271 $fnameMetaCurrent = $this->getNewTempFile();
272 $fnameArticles = $this->getNewTempFile();
274 $dumper = new BackupDumper( array ( "--output=gzip:" . $fnameMetaHistory,
275 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
276 "--output=gzip:" . $fnameArticles, "--filter=latest",
277 "--filter=notalk", "--filter=namespace:!NS_USER",
278 "--reporting=1000" ) );
279 $dumper->startId
= $this->pageId1
;
280 $dumper->endId
= $this->pageId4 +
1;
281 $dumper->setDb( $this->db
);
283 // xmldumps-backup uses reporting. We will not check the exact reported
284 // message, as they are dependent on the processing power of the used
285 // computer. We only check that reporting does not crash the dumping
286 // and that something is reported
287 $dumper->stderr
= fopen( 'php://output', 'a' );
288 if ( $dumper->stderr
=== FALSE ) {
289 $this->fail( "Could not open stream for stderr" );
292 // Performing the dump
293 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::STUB
);
295 $this->assertTrue( fclose( $dumper->stderr
), "Closing stderr handle" );
297 // Checking meta-history -------------------------------------------------
299 $this->gunzip( $fnameMetaHistory );
300 $this->assertDumpStart( $fnameMetaHistory );
303 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
304 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
305 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
306 $this->assertPageEnd();
309 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
310 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
311 $this->textId2_1
, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
312 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
313 $this->textId2_2
, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95" );
314 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
315 $this->textId2_3
, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r" );
316 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
317 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
318 $this->assertPageEnd();
321 // -> Page is marked deleted. Hence not visible
324 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
325 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
326 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
327 $this->assertPageEnd();
329 $this->assertDumpEnd();
331 // Checking meta-current -------------------------------------------------
333 $this->gunzip( $fnameMetaCurrent );
334 $this->assertDumpStart( $fnameMetaCurrent );
337 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
338 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
339 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
340 $this->assertPageEnd();
343 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
344 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
345 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
346 $this->assertPageEnd();
349 // -> Page is marked deleted. Hence not visible
352 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
353 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
354 $this->textId4_1
, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
355 $this->assertPageEnd();
357 $this->assertDumpEnd();
359 // Checking articles -------------------------------------------------
361 $this->gunzip( $fnameArticles );
362 $this->assertDumpStart( $fnameArticles );
365 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
366 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
367 $this->textId1_1
, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
368 $this->assertPageEnd();
371 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
372 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
373 $this->textId2_4
, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv" );
374 $this->assertPageEnd();
377 // -> Page is marked deleted. Hence not visible
380 // -> Page is not in NS_MAIN. Hence not visible
382 $this->assertDumpEnd();
384 $this->expectETAOutput();