MediaWiki REL1_32
backup_PageTest.php
Go to the documentation of this file.
1<?php
2
4
9
18
19 // We'll add several pages, revision and texts. The following variables hold the
20 // corresponding ids.
29
30 function addDBData() {
31 // be sure, titles created here using english namespace names
32 $this->setContentLang( 'en' );
33
34 $this->tablesUsed[] = 'page';
35 $this->tablesUsed[] = 'revision';
36 $this->tablesUsed[] = 'ip_changes';
37 $this->tablesUsed[] = 'text';
38
39 try {
40 $this->namespace = $this->getDefaultWikitextNS();
41 $this->talk_namespace = NS_TALK;
42
43 if ( $this->namespace === $this->talk_namespace ) {
44 // @todo work around this.
45 throw new MWException( "The default wikitext namespace is the talk namespace. "
46 . " We can't currently deal with that." );
47 }
48
49 $this->pageTitle1 = Title::newFromText( 'BackupDumperTestP1', $this->namespace );
50 $page = WikiPage::factory( $this->pageTitle1 );
51 list( $this->revId1_1, $this->textId1_1 ) = $this->addRevision( $page,
52 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
53 $this->pageId1 = $page->getId();
54
55 $this->pageTitle2 = Title::newFromText( 'BackupDumperTestP2', $this->namespace );
56 $page = WikiPage::factory( $this->pageTitle2 );
57 list( $this->revId2_1, $this->textId2_1 ) = $this->addRevision( $page,
58 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
59 list( $this->revId2_2, $this->textId2_2 ) = $this->addRevision( $page,
60 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
61 list( $this->revId2_3, $this->textId2_3 ) = $this->addRevision( $page,
62 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
63 list( $this->revId2_4, $this->textId2_4 ) = $this->addRevision( $page,
64 "BackupDumperTestP2Text4 some additional Text ",
65 "BackupDumperTestP2Summary4 extra " );
66 $this->pageId2 = $page->getId();
67
68 $this->pageTitle3 = Title::newFromText( 'BackupDumperTestP3', $this->namespace );
69 $page = WikiPage::factory( $this->pageTitle3 );
70 list( $this->revId3_1, $this->textId3_1 ) = $this->addRevision( $page,
71 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
72 list( $this->revId3_2, $this->textId3_2 ) = $this->addRevision( $page,
73 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
74 $this->pageId3 = $page->getId();
75 $page->doDeleteArticle( "Testing ;)" );
76
77 $this->pageTitle4 = Title::newFromText( 'BackupDumperTestP1', $this->talk_namespace );
78 $page = WikiPage::factory( $this->pageTitle4 );
79 list( $this->revId4_1, $this->textId4_1 ) = $this->addRevision( $page,
80 "Talk about BackupDumperTestP1 Text1",
81 "Talk BackupDumperTestP1 Summary1" );
82 $this->pageId4 = $page->getId();
83 } catch ( Exception $e ) {
84 // We'd love to pass $e directly. However, ... see
85 // documentation of exceptionFromAddDBData in
86 // DumpTestCase
87 $this->exceptionFromAddDBData = $e;
88 }
89 }
90
91 protected function setUp() {
92 parent::setUp();
93
94 // Since we will restrict dumping by page ranges (to allow
95 // working tests, even if the db gets prepopulated by a base
96 // class), we have to assert, that the page id are consecutively
97 // increasing
98 $this->assertEquals(
99 [ $this->pageId2, $this->pageId3, $this->pageId4 ],
100 [ $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ],
101 "Page ids increasing without holes" );
102 }
103
104 function testFullTextPlain() {
105 // Preparing the dump
106 $fname = $this->getNewTempFile();
107
108 $dumper = new DumpBackup();
109 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname ] );
110 $dumper->startId = $this->pageId1;
111 $dumper->endId = $this->pageId4 + 1;
112 $dumper->setDB( $this->db );
113
114 // Performing the dump
115 $dumper->execute();
116
117 // Checking the dumped data
118 $this->assertDumpStart( $fname );
119
120 // Page 1
121 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
122 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
123 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
124 "BackupDumperTestP1Text1" );
125 $this->assertPageEnd();
126
127 // Page 2
128 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
129 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
130 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2",
131 "BackupDumperTestP2Text1" );
132 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
133 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
134 "BackupDumperTestP2Text2", $this->revId2_1 );
135 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
136 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r",
137 "BackupDumperTestP2Text3", $this->revId2_2 );
138 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
139 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv",
140 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
141 $this->assertPageEnd();
142
143 // Page 3
144 // -> Page is marked deleted. Hence not visible
145
146 // Page 4
147 $this->assertPageStart(
148 $this->pageId4,
149 $this->talk_namespace,
150 $this->pageTitle4->getPrefixedText()
151 );
152 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
153 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
154 "Talk about BackupDumperTestP1 Text1" );
155 $this->assertPageEnd();
156
157 $this->assertDumpEnd();
158 }
159
160 function testFullStubPlain() {
161 // Preparing the dump
162 $fname = $this->getNewTempFile();
163
164 $dumper = new DumpBackup();
165 $dumper->loadWithArgv( [ '--full', '--quiet', '--output', 'file:' . $fname, '--stub' ] );
166 $dumper->startId = $this->pageId1;
167 $dumper->endId = $this->pageId4 + 1;
168 $dumper->setDB( $this->db );
169
170 // Performing the dump
171 $dumper->execute();
172
173 // Checking the dumped data
174 $this->assertDumpStart( $fname );
175
176 // Page 1
177 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
178 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
179 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
180 $this->assertPageEnd();
181
182 // Page 2
183 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
184 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
185 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
186 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
187 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
188 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
189 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
190 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
191 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
192 $this->assertPageEnd();
193
194 // Page 3
195 // -> Page is marked deleted. Hence not visible
196
197 // Page 4
198 $this->assertPageStart(
199 $this->pageId4,
200 $this->talk_namespace,
201 $this->pageTitle4->getPrefixedText()
202 );
203 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
204 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
205 $this->assertPageEnd();
206
207 $this->assertDumpEnd();
208 }
209
211 // Preparing the dump
212 $fname = $this->getNewTempFile();
213
214 $dumper = new DumpBackup( [ '--output', 'file:' . $fname ] );
215 $dumper->startId = $this->pageId1;
216 $dumper->endId = $this->pageId4 + 1;
217 $dumper->reporting = false;
218 $dumper->setDB( $this->db );
219
220 // Performing the dump
221 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
222
223 // Checking the dumped data
224 $this->assertDumpStart( $fname );
225
226 // Page 1
227 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
228 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
229 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
230 $this->assertPageEnd();
231
232 // Page 2
233 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
234 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
235 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
236 $this->assertPageEnd();
237
238 // Page 3
239 // -> Page is marked deleted. Hence not visible
240
241 // Page 4
242 $this->assertPageStart(
243 $this->pageId4,
244 $this->talk_namespace,
245 $this->pageTitle4->getPrefixedText()
246 );
247 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
248 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
249 $this->assertPageEnd();
250
251 $this->assertDumpEnd();
252 }
253
255 $this->checkHasGzip();
256
257 // Preparing the dump
258 $fname = $this->getNewTempFile();
259
260 $dumper = new DumpBackup( [ '--output', 'gzip:' . $fname ] );
261 $dumper->startId = $this->pageId1;
262 $dumper->endId = $this->pageId4 + 1;
263 $dumper->reporting = false;
264 $dumper->setDB( $this->db );
265
266 // Performing the dump
267 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
268
269 // Checking the dumped data
270 $this->gunzip( $fname );
271 $this->assertDumpStart( $fname );
272
273 // Page 1
274 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
275 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
276 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
277 $this->assertPageEnd();
278
279 // Page 2
280 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
281 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
282 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
283 $this->assertPageEnd();
284
285 // Page 3
286 // -> Page is marked deleted. Hence not visible
287
288 // Page 4
289 $this->assertPageStart(
290 $this->pageId4,
291 $this->talk_namespace,
292 $this->pageTitle4->getPrefixedText()
293 );
294 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
295 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
296 $this->assertPageEnd();
297
298 $this->assertDumpEnd();
299 }
300
313 $this->checkHasGzip();
314
315 $fnameMetaHistory = $this->getNewTempFile();
316 $fnameMetaCurrent = $this->getNewTempFile();
317 $fnameArticles = $this->getNewTempFile();
318
319 $dumper = new DumpBackup( [ "--full", "--stub", "--output=gzip:" . $fnameMetaHistory,
320 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
321 "--output=gzip:" . $fnameArticles, "--filter=latest",
322 "--filter=notalk", "--filter=namespace:!NS_USER",
323 "--reporting=1000" ] );
324 $dumper->startId = $this->pageId1;
325 $dumper->endId = $this->pageId4 + 1;
326 $dumper->setDB( $this->db );
327
328 // xmldumps-backup uses reporting. We will not check the exact reported
329 // message, as they are dependent on the processing power of the used
330 // computer. We only check that reporting does not crash the dumping
331 // and that something is reported
332 $dumper->stderr = fopen( 'php://output', 'a' );
333 if ( $dumper->stderr === false ) {
334 $this->fail( "Could not open stream for stderr" );
335 }
336
337 // Performing the dump
338 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
339
340 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
341
342 // Checking meta-history -------------------------------------------------
343
344 $this->gunzip( $fnameMetaHistory );
345 $this->assertDumpStart( $fnameMetaHistory );
346
347 // Page 1
348 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
349 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
350 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
351 $this->assertPageEnd();
352
353 // Page 2
354 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
355 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
356 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
357 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
358 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
359 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
360 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
361 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
362 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
363 $this->assertPageEnd();
364
365 // Page 3
366 // -> Page is marked deleted. Hence not visible
367
368 // Page 4
369 $this->assertPageStart(
370 $this->pageId4,
371 $this->talk_namespace,
372 $this->pageTitle4->getPrefixedText()
373 );
374 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
375 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
376 $this->assertPageEnd();
377
378 $this->assertDumpEnd();
379
380 // Checking meta-current -------------------------------------------------
381
382 $this->gunzip( $fnameMetaCurrent );
383 $this->assertDumpStart( $fnameMetaCurrent );
384
385 // Page 1
386 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
387 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
388 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
389 $this->assertPageEnd();
390
391 // Page 2
392 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
393 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
394 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
395 $this->assertPageEnd();
396
397 // Page 3
398 // -> Page is marked deleted. Hence not visible
399
400 // Page 4
401 $this->assertPageStart(
402 $this->pageId4,
403 $this->talk_namespace,
404 $this->pageTitle4->getPrefixedText()
405 );
406 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
407 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
408 $this->assertPageEnd();
409
410 $this->assertDumpEnd();
411
412 // Checking articles -------------------------------------------------
413
414 $this->gunzip( $fnameArticles );
415 $this->assertDumpStart( $fnameArticles );
416
417 // Page 1
418 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
419 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
420 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
421 $this->assertPageEnd();
422
423 // Page 2
424 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
425 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
426 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
427 $this->assertPageEnd();
428
429 // Page 3
430 // -> Page is marked deleted. Hence not visible
431
432 // Page 4
433 // -> Page is not in $this->namespace. Hence not visible
434
435 $this->assertDumpEnd();
436
437 $this->expectETAOutput();
438 }
439}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:121
MediaWiki exception.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
getNewTempFile()
Obtains a new temporary file name.
Tests for page dumps of BackupDumper.
testXmlDumpsBackupUseCase()
xmldumps-backup typically performs a single dump that that writes out three files
gunzip( $fname)
gunzips the given file and stores the result in the original file name
assertDumpStart( $fname, $skip_siteinfo=true)
Opens an XML file to analyze and optionally skips past siteinfo.
assertPageEnd()
Asserts that the xml reader is at the page's closing element and skips to the next element.
addRevision(Page $page, $text, $summary, $model=CONTENT_MODEL_WIKITEXT)
Adds a revision to a page, while returning the resuting revision's id.
assertDumpEnd( $name="mediawiki")
Asserts that the xml reader is at the final closing tag of an xml file and closes the reader.
expectETAOutput()
Checks for test output consisting only of lines containing ETA announcements.
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.
assertPageStart( $id, $ns, $name)
Asserts that the xml reader is at the start of a page element and skips over the first tags,...
Represents a title within MediaWiki.
Definition Title.php:39
Class representing a MediaWiki article and history.
Definition WikiPage.php:44
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
const NS_TALK
Definition Defines.php:65
returning false will NOT prevent logging $e
Definition hooks.txt:2226
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37