Merge "Add pp_propname_page index to page_props"
[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 $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;
20
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' ),
26 ) );
27
28 $this->tablesUsed[] = 'page';
29 $this->tablesUsed[] = 'revision';
30 $this->tablesUsed[] = 'text';
31
32 try {
33 $this->namespace = $this->getDefaultWikitextNS();
34 $this->talk_namespace = NS_TALK;
35
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." );
40 }
41
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();
47
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();
60
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 ;)" );
69
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
79 // DumpTestCase
80 $this->exceptionFromAddDBData = $e;
81 }
82
83 }
84
85 protected function setUp() {
86 parent::setUp();
87
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
91 // increasing
92 $this->assertEquals(
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" );
96
97 }
98
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 );
107
108 // Performing the dump
109 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
110
111 // Checking the dumped data
112 $this->assertDumpStart( $fname );
113
114 // Page 1
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();
120
121 // Page 2
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();
136
137 // Page 3
138 // -> Page is marked deleted. Hence not visible
139
140 // Page 4
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();
146
147 $this->assertDumpEnd();
148 }
149
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 );
158
159 // Performing the dump
160 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
161
162 // Checking the dumped data
163 $this->assertDumpStart( $fname );
164
165 // Page 1
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();
170
171 // Page 2
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();
182
183 // Page 3
184 // -> Page is marked deleted. Hence not visible
185
186 // Page 4
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();
191
192 $this->assertDumpEnd();
193 }
194
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 );
203
204 // Performing the dump
205 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
206
207 // Checking the dumped data
208 $this->assertDumpStart( $fname );
209
210 // Page 1
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();
215
216 // Page 2
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();
221
222 // Page 3
223 // -> Page is marked deleted. Hence not visible
224
225 // Page 4
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();
230
231 $this->assertDumpEnd();
232 }
233
234 function testCurrentStubGzip() {
235 $this->checkHasGzip();
236
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 );
244
245 // Performing the dump
246 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
247
248 // Checking the dumped data
249 $this->gunzip( $fname );
250 $this->assertDumpStart( $fname );
251
252 // Page 1
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();
257
258 // Page 2
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();
263
264 // Page 3
265 // -> Page is marked deleted. Hence not visible
266
267 // Page 4
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();
272
273 $this->assertDumpEnd();
274 }
275
276
277 function testXmlDumpsBackupUseCase() {
278 // xmldumps-backup typically performs a single dump that that writes
279 // out three files
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
283 // (articles)
284 //
285 // We reproduce such a setup with our mini fixture, although we omit
286 // chunks, and all the other gimmicks of xmldumps-backup.
287 //
288 $this->checkHasGzip();
289
290 $fnameMetaHistory = $this->getNewTempFile();
291 $fnameMetaCurrent = $this->getNewTempFile();
292 $fnameArticles = $this->getNewTempFile();
293
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 );
302
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" );
310 }
311
312 // Performing the dump
313 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
314
315 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
316
317 // Checking meta-history -------------------------------------------------
318
319 $this->gunzip( $fnameMetaHistory );
320 $this->assertDumpStart( $fnameMetaHistory );
321
322 // Page 1
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();
327
328 // Page 2
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();
339
340 // Page 3
341 // -> Page is marked deleted. Hence not visible
342
343 // Page 4
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();
348
349 $this->assertDumpEnd();
350
351 // Checking meta-current -------------------------------------------------
352
353 $this->gunzip( $fnameMetaCurrent );
354 $this->assertDumpStart( $fnameMetaCurrent );
355
356 // Page 1
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();
361
362 // Page 2
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();
367
368 // Page 3
369 // -> Page is marked deleted. Hence not visible
370
371 // Page 4
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();
376
377 $this->assertDumpEnd();
378
379 // Checking articles -------------------------------------------------
380
381 $this->gunzip( $fnameArticles );
382 $this->assertDumpStart( $fnameArticles );
383
384 // Page 1
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();
389
390 // Page 2
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();
395
396 // Page 3
397 // -> Page is marked deleted. Hence not visible
398
399 // Page 4
400 // -> Page is not in $this->namespace. Hence not visible
401
402 $this->assertDumpEnd();
403
404 $this->expectETAOutput();
405 }
406
407
408 }