Merge "(bug 19195) Make user IDs more readily available with the API"
[lhc/web/wiklou.git] / tests / phpunit / maintenance / backup_PageTest.php
1 <?php
2 /**
3 * Tests for page dumps of BackupDumper
4 *
5 * @group Database
6 * @group Dump
7 */
8 class BackupDumperPageTest extends DumpTestCase {
9
10 // We'll add several pages, revision and texts. The following variables hold the
11 // corresponding ids.
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;
18
19 function addDBData() {
20 $this->tablesUsed[] = 'page';
21 $this->tablesUsed[] = 'revision';
22 $this->tablesUsed[] = 'text';
23
24 try {
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();
30
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();
43
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 ;)" );
52
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
62 // DumpTestCase
63 $this->exceptionFromAddDBData = $e;
64 }
65
66 }
67
68 protected function setUp() {
69 parent::setUp();
70
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
74 // increasing
75 $this->assertEquals(
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" );
79
80 }
81
82 function testFullTextPlain () {
83 // Preparing the dump
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 );
90
91 // Performing the dump
92 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
93
94 // Checking the dumped data
95 $this->assertDumpStart( $fname );
96
97 // Page 1
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();
103
104 // Page 2
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();
119
120 // Page 3
121 // -> Page is marked deleted. Hence not visible
122
123 // Page 4
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();
129
130 $this->assertDumpEnd();
131 }
132
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 );
141
142 // Performing the dump
143 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
144
145 // Checking the dumped data
146 $this->assertDumpStart( $fname );
147
148 // Page 1
149 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
150 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
151 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
152 $this->assertPageEnd();
153
154 // Page 2
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();
165
166 // Page 3
167 // -> Page is marked deleted. Hence not visible
168
169 // Page 4
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();
174
175 $this->assertDumpEnd();
176 }
177
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 );
186
187 // Performing the dump
188 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
189
190 // Checking the dumped data
191 $this->assertDumpStart( $fname );
192
193 // Page 1
194 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
195 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
196 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
197 $this->assertPageEnd();
198
199 // Page 2
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();
204
205 // Page 3
206 // -> Page is marked deleted. Hence not visible
207
208 // Page 4
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();
213
214 $this->assertDumpEnd();
215 }
216
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 );
225
226 // Performing the dump
227 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
228
229 // Checking the dumped data
230 $this->gunzip( $fname );
231 $this->assertDumpStart( $fname );
232
233 // Page 1
234 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
235 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
236 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
237 $this->assertPageEnd();
238
239 // Page 2
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();
244
245 // Page 3
246 // -> Page is marked deleted. Hence not visible
247
248 // Page 4
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();
253
254 $this->assertDumpEnd();
255 }
256
257
258
259 function testXmlDumpsBackupUseCase () {
260 // xmldumps-backup typically performs a single dump that that writes
261 // out three files
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
265 // (articles)
266 //
267 // We reproduce such a setup with our mini fixture, although we omit
268 // chunks, and all the other gimmicks of xmldumps-backup.
269 //
270 $fnameMetaHistory = $this->getNewTempFile();
271 $fnameMetaCurrent = $this->getNewTempFile();
272 $fnameArticles = $this->getNewTempFile();
273
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 );
282
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" );
290 }
291
292 // Performing the dump
293 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
294
295 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
296
297 // Checking meta-history -------------------------------------------------
298
299 $this->gunzip( $fnameMetaHistory );
300 $this->assertDumpStart( $fnameMetaHistory );
301
302 // Page 1
303 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
304 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
305 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
306 $this->assertPageEnd();
307
308 // Page 2
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();
319
320 // Page 3
321 // -> Page is marked deleted. Hence not visible
322
323 // Page 4
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();
328
329 $this->assertDumpEnd();
330
331 // Checking meta-current -------------------------------------------------
332
333 $this->gunzip( $fnameMetaCurrent );
334 $this->assertDumpStart( $fnameMetaCurrent );
335
336 // Page 1
337 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
338 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
339 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
340 $this->assertPageEnd();
341
342 // Page 2
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();
347
348 // Page 3
349 // -> Page is marked deleted. Hence not visible
350
351 // Page 4
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();
356
357 $this->assertDumpEnd();
358
359 // Checking articles -------------------------------------------------
360
361 $this->gunzip( $fnameArticles );
362 $this->assertDumpStart( $fnameArticles );
363
364 // Page 1
365 $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
366 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
367 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
368 $this->assertPageEnd();
369
370 // Page 2
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();
375
376 // Page 3
377 // -> Page is marked deleted. Hence not visible
378
379 // Page 4
380 // -> Page is not in NS_MAIN. Hence not visible
381
382 $this->assertDumpEnd();
383
384 $this->expectETAOutput();
385 }
386
387
388
389 }