MediaWiki REL1_30
backup_PageTest.php
Go to the documentation of this file.
1<?php
11
12 // We'll add several pages, revision and texts. The following variables hold the
13 // corresponding ids.
22
23 function addDBData() {
24 // be sure, titles created here using english namespace names
25 $this->setMwGlobals( [
26 'wgLanguageCode' => 'en',
27 'wgContLang' => Language::factory( 'en' ),
28 ] );
29
30 $this->tablesUsed[] = 'page';
31 $this->tablesUsed[] = 'revision';
32 $this->tablesUsed[] = 'ip_changes';
33 $this->tablesUsed[] = 'text';
34
35 try {
36 $this->namespace = $this->getDefaultWikitextNS();
37 $this->talk_namespace = NS_TALK;
38
39 if ( $this->namespace === $this->talk_namespace ) {
40 // @todo work around this.
41 throw new MWException( "The default wikitext namespace is the talk namespace. "
42 . " We can't currently deal with that." );
43 }
44
45 $this->pageTitle1 = Title::newFromText( 'BackupDumperTestP1', $this->namespace );
46 $page = WikiPage::factory( $this->pageTitle1 );
47 list( $this->revId1_1, $this->textId1_1 ) = $this->addRevision( $page,
48 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
49 $this->pageId1 = $page->getId();
50
51 $this->pageTitle2 = Title::newFromText( 'BackupDumperTestP2', $this->namespace );
52 $page = WikiPage::factory( $this->pageTitle2 );
53 list( $this->revId2_1, $this->textId2_1 ) = $this->addRevision( $page,
54 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
55 list( $this->revId2_2, $this->textId2_2 ) = $this->addRevision( $page,
56 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
57 list( $this->revId2_3, $this->textId2_3 ) = $this->addRevision( $page,
58 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
59 list( $this->revId2_4, $this->textId2_4 ) = $this->addRevision( $page,
60 "BackupDumperTestP2Text4 some additional Text ",
61 "BackupDumperTestP2Summary4 extra " );
62 $this->pageId2 = $page->getId();
63
64 $this->pageTitle3 = Title::newFromText( 'BackupDumperTestP3', $this->namespace );
65 $page = WikiPage::factory( $this->pageTitle3 );
66 list( $this->revId3_1, $this->textId3_1 ) = $this->addRevision( $page,
67 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
68 list( $this->revId3_2, $this->textId3_2 ) = $this->addRevision( $page,
69 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
70 $this->pageId3 = $page->getId();
71 $page->doDeleteArticle( "Testing ;)" );
72
73 $this->pageTitle4 = Title::newFromText( 'BackupDumperTestP1', $this->talk_namespace );
74 $page = WikiPage::factory( $this->pageTitle4 );
75 list( $this->revId4_1, $this->textId4_1 ) = $this->addRevision( $page,
76 "Talk about BackupDumperTestP1 Text1",
77 "Talk BackupDumperTestP1 Summary1" );
78 $this->pageId4 = $page->getId();
79 } catch ( Exception $e ) {
80 // We'd love to pass $e directly. However, ... see
81 // documentation of exceptionFromAddDBData in
82 // DumpTestCase
83 $this->exceptionFromAddDBData = $e;
84 }
85 }
86
87 protected function setUp() {
88 parent::setUp();
89
90 // Since we will restrict dumping by page ranges (to allow
91 // working tests, even if the db gets prepopulated by a base
92 // class), we have to assert, that the page id are consecutively
93 // increasing
94 $this->assertEquals(
95 [ $this->pageId2, $this->pageId3, $this->pageId4 ],
96 [ $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ],
97 "Page ids increasing without holes" );
98 }
99
100 function testFullTextPlain() {
101 // Preparing the dump
102 $fname = $this->getNewTempFile();
103
104 $dumper = new DumpBackup();
105 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname ] );
106 $dumper->startId = $this->pageId1;
107 $dumper->endId = $this->pageId4 + 1;
108 $dumper->setDB( $this->db );
109
110 // Performing the dump
111 $dumper->execute();
112
113 // Checking the dumped data
114 $this->assertDumpStart( $fname );
115
116 // Page 1
117 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
118 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
119 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
120 "BackupDumperTestP1Text1" );
121 $this->assertPageEnd();
122
123 // Page 2
124 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
125 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
126 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
127 "BackupDumperTestP2Text1" );
128 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
129 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
130 "BackupDumperTestP2Text2", $this->revId2_1 );
131 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
132 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
133 "BackupDumperTestP2Text3", $this->revId2_2 );
134 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
135 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
136 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
137 $this->assertPageEnd();
138
139 // Page 3
140 // -> Page is marked deleted. Hence not visible
141
142 // Page 4
143 $this->assertPageStart(
144 $this->pageId4,
145 $this->talk_namespace,
146 $this->pageTitle4->getPrefixedText()
147 );
148 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
149 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
150 "Talk about BackupDumperTestP1 Text1" );
151 $this->assertPageEnd();
152
153 $this->assertDumpEnd();
154 }
155
156 function testFullStubPlain() {
157 // Preparing the dump
158 $fname = $this->getNewTempFile();
159
160 $dumper = new DumpBackup();
161 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname, '--stub' ] );
162 $dumper->startId = $this->pageId1;
163 $dumper->endId = $this->pageId4 + 1;
164 $dumper->setDB( $this->db );
165
166 // Performing the dump
167 $dumper->execute();
168
169 // Checking the dumped data
170 $this->assertDumpStart( $fname );
171
172 // Page 1
173 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
174 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
175 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
176 $this->assertPageEnd();
177
178 // Page 2
179 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
180 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
181 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
182 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
183 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
184 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
185 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
186 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
187 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
188 $this->assertPageEnd();
189
190 // Page 3
191 // -> Page is marked deleted. Hence not visible
192
193 // Page 4
194 $this->assertPageStart(
195 $this->pageId4,
196 $this->talk_namespace,
197 $this->pageTitle4->getPrefixedText()
198 );
199 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
200 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
201 $this->assertPageEnd();
202
203 $this->assertDumpEnd();
204 }
205
207 // Preparing the dump
208 $fname = $this->getNewTempFile();
209
210 $dumper = new DumpBackup( [ '--output', 'file:' . $fname ] );
211 $dumper->startId = $this->pageId1;
212 $dumper->endId = $this->pageId4 + 1;
213 $dumper->reporting = false;
214 $dumper->setDB( $this->db );
215
216 // Performing the dump
218
219 // Checking the dumped data
220 $this->assertDumpStart( $fname );
221
222 // Page 1
223 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
224 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
225 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
226 $this->assertPageEnd();
227
228 // Page 2
229 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
230 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
231 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
232 $this->assertPageEnd();
233
234 // Page 3
235 // -> Page is marked deleted. Hence not visible
236
237 // Page 4
238 $this->assertPageStart(
239 $this->pageId4,
240 $this->talk_namespace,
241 $this->pageTitle4->getPrefixedText()
242 );
243 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
244 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
245 $this->assertPageEnd();
246
247 $this->assertDumpEnd();
248 }
249
251 $this->checkHasGzip();
252
253 // Preparing the dump
254 $fname = $this->getNewTempFile();
255
256 $dumper = new DumpBackup( [ '--output', 'gzip:' . $fname ] );
257 $dumper->startId = $this->pageId1;
258 $dumper->endId = $this->pageId4 + 1;
259 $dumper->reporting = false;
260 $dumper->setDB( $this->db );
261
262 // Performing the dump
264
265 // Checking the dumped data
266 $this->gunzip( $fname );
267 $this->assertDumpStart( $fname );
268
269 // Page 1
270 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
271 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
272 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
273 $this->assertPageEnd();
274
275 // Page 2
276 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
277 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
278 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
279 $this->assertPageEnd();
280
281 // Page 3
282 // -> Page is marked deleted. Hence not visible
283
284 // Page 4
285 $this->assertPageStart(
286 $this->pageId4,
287 $this->talk_namespace,
288 $this->pageTitle4->getPrefixedText()
289 );
290 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
291 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
292 $this->assertPageEnd();
293
294 $this->assertDumpEnd();
295 }
296
309 $this->checkHasGzip();
310
311 $fnameMetaHistory = $this->getNewTempFile();
312 $fnameMetaCurrent = $this->getNewTempFile();
313 $fnameArticles = $this->getNewTempFile();
314
315 $dumper = new DumpBackup( [ "--full", "--stub", "--output=gzip:" . $fnameMetaHistory,
316 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
317 "--output=gzip:" . $fnameArticles, "--filter=latest",
318 "--filter=notalk", "--filter=namespace:!NS_USER",
319 "--reporting=1000" ] );
320 $dumper->startId = $this->pageId1;
321 $dumper->endId = $this->pageId4 + 1;
322 $dumper->setDB( $this->db );
323
324 // xmldumps-backup uses reporting. We will not check the exact reported
325 // message, as they are dependent on the processing power of the used
326 // computer. We only check that reporting does not crash the dumping
327 // and that something is reported
328 $dumper->stderr = fopen( 'php://output', 'a' );
329 if ( $dumper->stderr === false ) {
330 $this->fail( "Could not open stream for stderr" );
331 }
332
333 // Performing the dump
334 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
335
336 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
337
338 // Checking meta-history -------------------------------------------------
339
340 $this->gunzip( $fnameMetaHistory );
341 $this->assertDumpStart( $fnameMetaHistory );
342
343 // Page 1
344 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
345 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
346 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
347 $this->assertPageEnd();
348
349 // Page 2
350 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
351 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
352 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
353 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
354 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
355 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
356 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
357 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
358 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
359 $this->assertPageEnd();
360
361 // Page 3
362 // -> Page is marked deleted. Hence not visible
363
364 // Page 4
365 $this->assertPageStart(
366 $this->pageId4,
367 $this->talk_namespace,
368 $this->pageTitle4->getPrefixedText()
369 );
370 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
371 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
372 $this->assertPageEnd();
373
374 $this->assertDumpEnd();
375
376 // Checking meta-current -------------------------------------------------
377
378 $this->gunzip( $fnameMetaCurrent );
379 $this->assertDumpStart( $fnameMetaCurrent );
380
381 // Page 1
382 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
383 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
384 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
385 $this->assertPageEnd();
386
387 // Page 2
388 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
389 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
390 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
391 $this->assertPageEnd();
392
393 // Page 3
394 // -> Page is marked deleted. Hence not visible
395
396 // Page 4
397 $this->assertPageStart(
398 $this->pageId4,
399 $this->talk_namespace,
400 $this->pageTitle4->getPrefixedText()
401 );
402 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
403 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
404 $this->assertPageEnd();
405
406 $this->assertDumpEnd();
407
408 // Checking articles -------------------------------------------------
409
410 $this->gunzip( $fnameArticles );
411 $this->assertDumpStart( $fnameArticles );
412
413 // Page 1
414 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
415 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
416 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
417 $this->assertPageEnd();
418
419 // Page 2
420 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
421 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
422 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
423 $this->assertPageEnd();
424
425 // Page 3
426 // -> Page is marked deleted. Hence not visible
427
428 // Page 4
429 // -> Page is not in $this->namespace. Hence not visible
430
431 $this->assertDumpEnd();
432
433 $this->expectETAOutput();
434 }
435}
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:36
Tests for page dumps of BackupDumper.
testXmlDumpsBackupUseCase()
xmldumps-backup typically performs a single dump that that writes out three files
setUp()
Default set up function.
Base TestCase for dumps.
assertPageStart( $id, $ns, $name)
Asserts that the xml reader is at the start of a page element and skips over the first tags,...
assertDumpStart( $fname, $skip_siteinfo=true)
Opens an XML file to analyze and optionally skips past siteinfo.
expectETAOutput()
Checks for test output consisting only of lines containing ETA announcements.
assertPageEnd()
Asserts that the xml reader is at the page's closing element and skips to the next element.
assertDumpEnd( $name="mediawiki")
Asserts that the xml reader is at the final closing tag of an xml file and closes the reader.
addRevision(Page $page, $text, $summary, $model=CONTENT_MODEL_WIKITEXT)
Adds a revision to a page, while returning the resuting revision's id.
gunzip( $fname)
gunzips the given file and stores the result in the original file name
checkHasGzip()
Skip the test if 'gzip' is not in $PATH.
assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text=false, $parentid=false, $model=CONTENT_MODEL_WIKITEXT, $format=CONTENT_FORMAT_WIKITEXT)
Asserts that the xml reader is at a revision and checks its representation before skipping over it.
MediaWiki exception.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
getNewTempFile()
Obtains a new temporary file name.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
returning false will NOT prevent logging $e
Definition hooks.txt:2146
const NS_TALK
Definition Defines.php:66