Set wgLanguageCode/wgContLang for backup_PageTest.php
[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 $this->tablesUsed[] = 'page';
23 $this->tablesUsed[] = 'revision';
24 $this->tablesUsed[] = 'text';
25
26 try {
27 $this->namespace = $this->getDefaultWikitextNS();
28 $this->talk_namespace = NS_TALK;
29
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.");
34 }
35
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();
41
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();
54
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 ;)" );
63
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
73 // DumpTestCase
74 $this->exceptionFromAddDBData = $e;
75 }
76
77 }
78
79 protected function setUp() {
80 parent::setUp();
81
82 $this->setMwGlobals( array(
83 'wgLanguageCode' => 'en',
84 'wgContLang' => Language::factory( 'en' ),
85 ));
86
87 // Since we will restrict dumping by page ranges (to allow
88 // working tests, even if the db gets prepopulated by a base
89 // class), we have to assert, that the page id are consecutively
90 // increasing
91 $this->assertEquals(
92 array( $this->pageId2, $this->pageId3, $this->pageId4 ),
93 array( $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ),
94 "Page ids increasing without holes" );
95
96 }
97
98 function testFullTextPlain () {
99 // Preparing the dump
100 $fname = $this->getNewTempFile();
101 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
102 $dumper->startId = $this->pageId1;
103 $dumper->endId = $this->pageId4 + 1;
104 $dumper->reporting = false;
105 $dumper->setDb( $this->db );
106
107 // Performing the dump
108 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
109
110 // Checking the dumped data
111 $this->assertDumpStart( $fname );
112
113 // Page 1
114 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
115 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
116 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
117 "BackupDumperTestP1Text1" );
118 $this->assertPageEnd();
119
120 // Page 2
121 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
122 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
123 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
124 "BackupDumperTestP2Text1" );
125 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
126 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
127 "BackupDumperTestP2Text2", $this->revId2_1 );
128 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
129 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
130 "BackupDumperTestP2Text3", $this->revId2_2 );
131 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
132 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
133 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
134 $this->assertPageEnd();
135
136 // Page 3
137 // -> Page is marked deleted. Hence not visible
138
139 // Page 4
140 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
141 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
142 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
143 "Talk about BackupDumperTestP1 Text1" );
144 $this->assertPageEnd();
145
146 $this->assertDumpEnd();
147 }
148
149 function testFullStubPlain () {
150 // Preparing the dump
151 $fname = $this->getNewTempFile();
152 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
153 $dumper->startId = $this->pageId1;
154 $dumper->endId = $this->pageId4 + 1;
155 $dumper->reporting = false;
156 $dumper->setDb( $this->db );
157
158 // Performing the dump
159 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
160
161 // Checking the dumped data
162 $this->assertDumpStart( $fname );
163
164 // Page 1
165 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
166 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
167 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
168 $this->assertPageEnd();
169
170 // Page 2
171 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
172 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
173 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
174 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
175 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
176 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
177 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
178 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
179 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
180 $this->assertPageEnd();
181
182 // Page 3
183 // -> Page is marked deleted. Hence not visible
184
185 // Page 4
186 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
187 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
188 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
189 $this->assertPageEnd();
190
191 $this->assertDumpEnd();
192 }
193
194 function testCurrentStubPlain () {
195 // Preparing the dump
196 $fname = $this->getNewTempFile();
197 $dumper = new BackupDumper( array ( "--output=file:" . $fname ) );
198 $dumper->startId = $this->pageId1;
199 $dumper->endId = $this->pageId4 + 1;
200 $dumper->reporting = false;
201 $dumper->setDb( $this->db );
202
203 // Performing the dump
204 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
205
206 // Checking the dumped data
207 $this->assertDumpStart( $fname );
208
209 // Page 1
210 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
211 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
212 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
213 $this->assertPageEnd();
214
215 // Page 2
216 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
217 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
218 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
219 $this->assertPageEnd();
220
221 // Page 3
222 // -> Page is marked deleted. Hence not visible
223
224 // Page 4
225 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
226 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
227 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
228 $this->assertPageEnd();
229
230 $this->assertDumpEnd();
231 }
232
233 function testCurrentStubGzip () {
234 // Preparing the dump
235 $fname = $this->getNewTempFile();
236 $dumper = new BackupDumper( array ( "--output=gzip:" . $fname ) );
237 $dumper->startId = $this->pageId1;
238 $dumper->endId = $this->pageId4 + 1;
239 $dumper->reporting = false;
240 $dumper->setDb( $this->db );
241
242 // Performing the dump
243 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
244
245 // Checking the dumped data
246 $this->gunzip( $fname );
247 $this->assertDumpStart( $fname );
248
249 // Page 1
250 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
251 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
252 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
253 $this->assertPageEnd();
254
255 // Page 2
256 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
257 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
258 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
259 $this->assertPageEnd();
260
261 // Page 3
262 // -> Page is marked deleted. Hence not visible
263
264 // Page 4
265 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
266 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
267 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
268 $this->assertPageEnd();
269
270 $this->assertDumpEnd();
271 }
272
273
274
275 function testXmlDumpsBackupUseCase () {
276 // xmldumps-backup typically performs a single dump that that writes
277 // out three files
278 // * gzipped stubs of everything (meta-history)
279 // * gzipped stubs of latest revisions of all pages (meta-current)
280 // * gzipped stubs of latest revisions of all pages of namespage 0
281 // (articles)
282 //
283 // We reproduce such a setup with our mini fixture, although we omit
284 // chunks, and all the other gimmicks of xmldumps-backup.
285 //
286 $fnameMetaHistory = $this->getNewTempFile();
287 $fnameMetaCurrent = $this->getNewTempFile();
288 $fnameArticles = $this->getNewTempFile();
289
290 $dumper = new BackupDumper( array ( "--output=gzip:" . $fnameMetaHistory,
291 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
292 "--output=gzip:" . $fnameArticles, "--filter=latest",
293 "--filter=notalk", "--filter=namespace:!NS_USER",
294 "--reporting=1000" ) );
295 $dumper->startId = $this->pageId1;
296 $dumper->endId = $this->pageId4 + 1;
297 $dumper->setDb( $this->db );
298
299 // xmldumps-backup uses reporting. We will not check the exact reported
300 // message, as they are dependent on the processing power of the used
301 // computer. We only check that reporting does not crash the dumping
302 // and that something is reported
303 $dumper->stderr = fopen( 'php://output', 'a' );
304 if ( $dumper->stderr === FALSE ) {
305 $this->fail( "Could not open stream for stderr" );
306 }
307
308 // Performing the dump
309 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
310
311 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
312
313 // Checking meta-history -------------------------------------------------
314
315 $this->gunzip( $fnameMetaHistory );
316 $this->assertDumpStart( $fnameMetaHistory );
317
318 // Page 1
319 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
320 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
321 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
322 $this->assertPageEnd();
323
324 // Page 2
325 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
326 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
327 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
328 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
329 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
330 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
331 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
332 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
333 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
334 $this->assertPageEnd();
335
336 // Page 3
337 // -> Page is marked deleted. Hence not visible
338
339 // Page 4
340 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
341 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
342 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
343 $this->assertPageEnd();
344
345 $this->assertDumpEnd();
346
347 // Checking meta-current -------------------------------------------------
348
349 $this->gunzip( $fnameMetaCurrent );
350 $this->assertDumpStart( $fnameMetaCurrent );
351
352 // Page 1
353 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
354 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
355 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
356 $this->assertPageEnd();
357
358 // Page 2
359 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
360 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
361 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
362 $this->assertPageEnd();
363
364 // Page 3
365 // -> Page is marked deleted. Hence not visible
366
367 // Page 4
368 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() );
369 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
370 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
371 $this->assertPageEnd();
372
373 $this->assertDumpEnd();
374
375 // Checking articles -------------------------------------------------
376
377 $this->gunzip( $fnameArticles );
378 $this->assertDumpStart( $fnameArticles );
379
380 // Page 1
381 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
382 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
383 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
384 $this->assertPageEnd();
385
386 // Page 2
387 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
388 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
389 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
390 $this->assertPageEnd();
391
392 // Page 3
393 // -> Page is marked deleted. Hence not visible
394
395 // Page 4
396 // -> Page is not in $this->namespace. Hence not visible
397
398 $this->assertDumpEnd();
399
400 $this->expectETAOutput();
401 }
402
403
404
405 }