3 require_once __DIR__
. "/../../../maintenance/backupTextPass.inc";
6 * Tests for TextPassDumper that rely on the database
10 * @covers TextPassDumper
12 class TextPassDumperDatabaseTest
extends DumpTestCase
{
14 // We'll add several pages, revision and texts. The following variables hold the
16 private $pageId1, $pageId2, $pageId3, $pageId4;
17 private static $numOfPages = 4;
18 private $revId1_1, $textId1_1;
19 private $revId2_1, $textId2_1, $revId2_2, $textId2_2;
20 private $revId2_3, $textId2_3, $revId2_4, $textId2_4;
21 private $revId3_1, $textId3_1, $revId3_2, $textId3_2;
22 private $revId4_1, $textId4_1;
23 private static $numOfRevs = 8;
25 function addDBData() {
26 $this->tablesUsed
[] = 'page';
27 $this->tablesUsed
[] = 'revision';
28 $this->tablesUsed
[] = 'text';
30 $this->mergeMwGlobalArrayValue( 'wgContentHandlers', array(
31 "BackupTextPassTestModel" => "BackupTextPassTestModelHandler"
34 $ns = $this->getDefaultWikitextNS();
38 $title = Title
::newFromText( 'BackupDumperTestP1', $ns );
39 $page = WikiPage
::factory( $title );
40 list( $this->revId1_1
, $this->textId1_1
) = $this->addRevision( $page,
41 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" );
42 $this->pageId1
= $page->getId();
44 // Page with more than one revision
45 $title = Title
::newFromText( 'BackupDumperTestP2', $ns );
46 $page = WikiPage
::factory( $title );
47 list( $this->revId2_1
, $this->textId2_1
) = $this->addRevision( $page,
48 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" );
49 list( $this->revId2_2
, $this->textId2_2
) = $this->addRevision( $page,
50 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" );
51 list( $this->revId2_3
, $this->textId2_3
) = $this->addRevision( $page,
52 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" );
53 list( $this->revId2_4
, $this->textId2_4
) = $this->addRevision( $page,
54 "BackupDumperTestP2Text4 some additional Text ",
55 "BackupDumperTestP2Summary4 extra " );
56 $this->pageId2
= $page->getId();
59 $title = Title
::newFromText( 'BackupDumperTestP3', $ns );
60 $page = WikiPage
::factory( $title );
61 list( $this->revId3_1
, $this->textId3_1
) = $this->addRevision( $page,
62 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" );
63 list( $this->revId3_2
, $this->textId3_2
) = $this->addRevision( $page,
64 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" );
65 $this->pageId3
= $page->getId();
66 $page->doDeleteArticle( "Testing ;)" );
68 // Page from non-default namespace and model.
69 // ExportTransform applies.
71 if ( $ns === NS_TALK
) {
72 // @todo work around this.
73 throw new MWException( "The default wikitext namespace is the talk namespace. "
74 . " We can't currently deal with that." );
77 $title = Title
::newFromText( 'BackupDumperTestP1', NS_TALK
);
78 $page = WikiPage
::factory( $title );
79 list( $this->revId4_1
, $this->textId4_1
) = $this->addRevision( $page,
80 "Talk about BackupDumperTestP1 Text1",
81 "Talk BackupDumperTestP1 Summary1",
82 "BackupTextPassTestModel" );
83 $this->pageId4
= $page->getId();
84 } catch ( Exception
$e ) {
85 // We'd love to pass $e directly. However, ... see
86 // documentation of exceptionFromAddDBData in
88 $this->exceptionFromAddDBData
= $e;
92 protected function setUp() {
95 // Since we will restrict dumping by page ranges (to allow
96 // working tests, even if the db gets prepopulated by a base
97 // class), we have to assert, that the page id are consecutively
100 array( $this->pageId2
, $this->pageId3
, $this->pageId4
),
101 array( $this->pageId1 +
1, $this->pageId2 +
1, $this->pageId3 +
1 ),
102 "Page ids increasing without holes" );
105 function testPlain() {
106 // Setting up the dump
107 $nameStub = $this->setUpStub();
108 $nameFull = $this->getNewTempFile();
109 $dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
110 "--output=file:" . $nameFull ) );
111 $dumper->reporting
= false;
112 $dumper->setDb( $this->db
);
114 // Performing the dump
115 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
117 // Checking for correctness of the dumped data
118 $this->assertDumpStart( $nameFull );
121 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
122 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
123 $this->textId1_1
, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
124 "BackupDumperTestP1Text1" );
125 $this->assertPageEnd();
128 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
129 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
130 $this->textId2_1
, false, "jprywrymfhysqllua29tj3sc7z39dl2",
131 "BackupDumperTestP2Text1" );
132 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
133 $this->textId2_2
, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
134 "BackupDumperTestP2Text2", $this->revId2_1
);
135 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
136 $this->textId2_3
, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
137 "BackupDumperTestP2Text3", $this->revId2_2
);
138 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
139 $this->textId2_4
, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
140 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
141 $this->assertPageEnd();
144 // -> Page is marked deleted. Hence not visible
147 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
148 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
149 $this->textId4_1
, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
150 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
152 "BackupTextPassTestModel",
154 $this->assertPageEnd();
156 $this->assertDumpEnd();
159 function testPrefetchPlain() {
160 // The mapping between ids and text, for the hits of the prefetch mock
161 $prefetchMap = array(
162 array( $this->pageId1
, $this->revId1_1
, "Prefetch_________1Text1" ),
163 array( $this->pageId2
, $this->revId2_3
, "Prefetch_________2Text3" )
167 $prefetchMock = $this->getMock( 'BaseDump', array( 'prefetch' ), array(), '', false );
168 $prefetchMock->expects( $this->exactly( 6 ) )
169 ->method( 'prefetch' )
170 ->will( $this->returnValueMap( $prefetchMap ) );
172 // Setting up of the dump
173 $nameStub = $this->setUpStub();
174 $nameFull = $this->getNewTempFile();
175 $dumper = new TextPassDumper( array( "--stub=file:"
176 . $nameStub, "--output=file:" . $nameFull ) );
177 $dumper->prefetch
= $prefetchMock;
178 $dumper->reporting
= false;
179 $dumper->setDb( $this->db
);
181 // Performing the dump
182 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
184 // Checking for correctness of the dumped data
185 $this->assertDumpStart( $nameFull );
188 $this->assertPageStart( $this->pageId1
, NS_MAIN
, "BackupDumperTestP1" );
189 // Prefetch kicks in. This is still the SHA-1 of the original text,
190 // But the actual text (with different SHA-1) comes from prefetch.
191 $this->assertRevision( $this->revId1_1
, "BackupDumperTestP1Summary1",
192 $this->textId1_1
, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
193 "Prefetch_________1Text1" );
194 $this->assertPageEnd();
197 $this->assertPageStart( $this->pageId2
, NS_MAIN
, "BackupDumperTestP2" );
198 $this->assertRevision( $this->revId2_1
, "BackupDumperTestP2Summary1",
199 $this->textId2_1
, false, "jprywrymfhysqllua29tj3sc7z39dl2",
200 "BackupDumperTestP2Text1" );
201 $this->assertRevision( $this->revId2_2
, "BackupDumperTestP2Summary2",
202 $this->textId2_2
, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
203 "BackupDumperTestP2Text2", $this->revId2_1
);
204 // Prefetch kicks in. This is still the SHA-1 of the original text,
205 // But the actual text (with different SHA-1) comes from prefetch.
206 $this->assertRevision( $this->revId2_3
, "BackupDumperTestP2Summary3",
207 $this->textId2_3
, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
208 "Prefetch_________2Text3", $this->revId2_2
);
209 $this->assertRevision( $this->revId2_4
, "BackupDumperTestP2Summary4 extra",
210 $this->textId2_4
, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
211 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3
);
212 $this->assertPageEnd();
215 // -> Page is marked deleted. Hence not visible
218 $this->assertPageStart( $this->pageId4
, NS_TALK
, "Talk:BackupDumperTestP1" );
219 $this->assertRevision( $this->revId4_1
, "Talk BackupDumperTestP1 Summary1",
220 $this->textId4_1
, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
221 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
223 "BackupTextPassTestModel",
225 $this->assertPageEnd();
227 $this->assertDumpEnd();
231 * Ensures that checkpoint dumps are used and written, by successively increasing the
232 * stub size and dumping until the duration crosses a threshold.
234 * @param string $checkpointFormat Either "file" for plain text or "gzip" for gzipped
237 private function checkpointHelper( $checkpointFormat = "file" ) {
238 // Getting temporary names
239 $nameStub = $this->getNewTempFile();
240 $nameOutputDir = $this->getNewTempDirectory();
242 $stderr = fopen( 'php://output', 'a' );
243 if ( $stderr === false ) {
244 $this->fail( "Could not open stream for stderr" );
247 $iterations = 32; // We'll start with that many iterations of revisions in stub
249 $minDuration = 2; // We want the dump to take at least this many seconds
250 $checkpointAfter = 0.5; // Generate checkpoint after this many seconds
252 // Until a dump takes at least $minDuration seconds, perform a dump and check
253 // duration. If the dump did not take long enough increase the iteration
254 // count, to generate a bigger stub file next time.
255 while ( $lastDuration < $minDuration ) {
257 // Setting up the dump
258 wfRecursiveRemoveDir( $nameOutputDir );
259 $this->assertTrue( wfMkdirParents( $nameOutputDir ),
260 "Creating temporary output directory " );
261 $this->setUpStub( $nameStub, $iterations );
262 $dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
263 "--output=" . $checkpointFormat . ":" . $nameOutputDir . "/full",
264 "--maxtime=1" /*This is in minutes. Fixup is below*/,
265 "--checkpointfile=checkpoint-%s-%s.xml.gz" ) );
266 $dumper->setDb( $this->db
);
267 $dumper->maxTimeAllowed
= $checkpointAfter; // Patching maxTime from 1 minute
268 $dumper->stderr
= $stderr;
270 // The actual dump and taking time
271 $ts_before = microtime( true );
272 $dumper->dump( WikiExporter
::FULL
, WikiExporter
::TEXT
);
273 $ts_after = microtime( true );
274 $lastDuration = $ts_after - $ts_before;
276 // Handling increasing the iteration count for the stubs
277 if ( $lastDuration < $minDuration ) {
278 $old_iterations = $iterations;
279 if ( $lastDuration > 0.2 ) {
280 // lastDuration is big enough, to allow an educated guess
281 $factor = ( $minDuration +
0.5 ) / $lastDuration;
282 if ( ( $factor > 1.1 ) && ( $factor < 100 ) ) {
283 // educated guess is reasonable
284 $iterations = (int)( $iterations * $factor );
288 if ( $old_iterations == $iterations ) {
289 // Heuristics were not applied, so we just *2.
293 $this->assertLessThan( 50000, $iterations,
294 "Emergency stop against infinitely increasing iteration "
295 . "count ( last duration: $lastDuration )" );
299 // The dump (hopefully) did take long enough to produce more than one
302 // We now check all the checkpoint files for validity.
304 $files = scandir( $nameOutputDir );
305 $this->assertTrue( asort( $files ), "Sorting files in temporary directory" );
308 $checkpointFiles = 0;
310 // Each run of the following loop body tries to handle exactly 1 /page/ (not
311 // iteration of stub content). $i is only increased after having treated page 4.
312 for ( $i = 0; $i < $iterations; ) {
314 // 1. Assuring a file is opened and ready. Skipping across header if
316 if ( !$fileOpened ) {
317 $this->assertNotEmpty( $files, "No more existing dump files, "
318 . "but not yet all pages found" );
319 $fname = array_shift( $files );
320 while ( $fname == "." ||
$fname == ".." ) {
321 $this->assertNotEmpty( $files, "No more existing dump"
322 . " files, but not yet all pages found" );
323 $fname = array_shift( $files );
325 if ( $checkpointFormat == "gzip" ) {
326 $this->gunzip( $nameOutputDir . "/" . $fname );
328 $this->assertDumpStart( $nameOutputDir . "/" . $fname );
333 // 2. Performing a single page check
334 switch ( $lookingForPage ) {
337 $this->assertPageStart( $this->pageId1 +
$i * self
::$numOfPages, NS_MAIN
,
338 "BackupDumperTestP1" );
339 $this->assertRevision( $this->revId1_1 +
$i * self
::$numOfRevs, "BackupDumperTestP1Summary1",
340 $this->textId1_1
, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
341 "BackupDumperTestP1Text1" );
342 $this->assertPageEnd();
349 $this->assertPageStart( $this->pageId2 +
$i * self
::$numOfPages, NS_MAIN
,
350 "BackupDumperTestP2" );
351 $this->assertRevision( $this->revId2_1 +
$i * self
::$numOfRevs, "BackupDumperTestP2Summary1",
352 $this->textId2_1
, false, "jprywrymfhysqllua29tj3sc7z39dl2",
353 "BackupDumperTestP2Text1" );
354 $this->assertRevision( $this->revId2_2 +
$i * self
::$numOfRevs, "BackupDumperTestP2Summary2",
355 $this->textId2_2
, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
356 "BackupDumperTestP2Text2", $this->revId2_1 +
$i * self
::$numOfRevs );
357 $this->assertRevision( $this->revId2_3 +
$i * self
::$numOfRevs, "BackupDumperTestP2Summary3",
358 $this->textId2_3
, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
359 "BackupDumperTestP2Text3", $this->revId2_2 +
$i * self
::$numOfRevs );
360 $this->assertRevision( $this->revId2_4 +
$i * self
::$numOfRevs,
361 "BackupDumperTestP2Summary4 extra",
362 $this->textId2_4
, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
363 "BackupDumperTestP2Text4 some additional Text",
364 $this->revId2_3 +
$i * self
::$numOfRevs );
365 $this->assertPageEnd();
372 $this->assertPageStart( $this->pageId4 +
$i * self
::$numOfPages, NS_TALK
,
373 "Talk:BackupDumperTestP1" );
374 $this->assertRevision( $this->revId4_1 +
$i * self
::$numOfRevs,
375 "Talk BackupDumperTestP1 Summary1",
376 $this->textId4_1
, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
377 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
379 "BackupTextPassTestModel",
381 $this->assertPageEnd();
385 // We dealt with the whole iteration.
390 $this->fail( "Bad setting for lookingForPage ($lookingForPage)" );
393 // 3. Checking for the end of the current checkpoint file
394 if ( $this->xml
->nodeType
== XMLReader
::END_ELEMENT
395 && $this->xml
->name
== "mediawiki"
397 $this->assertDumpEnd();
402 // Assuring we completely read all files ...
403 $this->assertFalse( $fileOpened, "Currently read file still open?" );
404 $this->assertEmpty( $files, "Remaining unchecked files" );
406 // ... and have dealt with more than one checkpoint file
407 $this->assertGreaterThan(
410 "expected more than 1 checkpoint to have been created. "
411 . "Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?"
414 $this->expectETAOutput();
423 function testCheckpointPlain() {
424 $this->checkpointHelper();
428 * tests for working checkpoint generation in gzip format work.
430 * We keep this test in addition to the simpler self::testCheckpointPlain, as there
431 * were once problems when the used sinks were DumpPipeOutputs.
433 * xmldumps-backup typically uses bzip2 instead of gzip. However, as bzip2 requires
434 * PHP extensions, we go for gzip instead, which triggers the same relevant code
435 * paths while still being testable on more systems.
442 function testCheckpointGzip() {
443 $this->checkHasGzip();
444 $this->checkpointHelper( "gzip" );
448 * Creates a stub file that is used for testing the text pass of dumps
450 * @param string $fname (Optional) Absolute name of the file to write
451 * the stub into. If this parameter is null, a new temporary
452 * file is generated that is automatically removed upon tearDown.
453 * @param int $iterations (Optional) specifies how often the block
454 * of 3 pages should go into the stub file. The page and
455 * revision id increase further and further, while the text
456 * id of the first iteration is reused. The pages and revision
457 * of iteration > 1 have no corresponding representation in the database.
458 * @return string Absolute filename of the stub
460 private function setUpStub( $fname = null, $iterations = 1 ) {
461 if ( $fname === null ) {
462 $fname = $this->getNewTempFile();
464 $header = '<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" '
465 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
466 . 'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ '
467 . 'http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
469 <sitename>wikisvn</sitename>
470 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
471 <generator>MediaWiki 1.21alpha</generator>
472 <case>first-letter</case>
474 <namespace key="-2" case="first-letter">Media</namespace>
475 <namespace key="-1" case="first-letter">Special</namespace>
476 <namespace key="0" case="first-letter" />
477 <namespace key="1" case="first-letter">Talk</namespace>
478 <namespace key="2" case="first-letter">User</namespace>
479 <namespace key="3" case="first-letter">User talk</namespace>
480 <namespace key="4" case="first-letter">Wikisvn</namespace>
481 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
482 <namespace key="6" case="first-letter">File</namespace>
483 <namespace key="7" case="first-letter">File talk</namespace>
484 <namespace key="8" case="first-letter">MediaWiki</namespace>
485 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
486 <namespace key="10" case="first-letter">Template</namespace>
487 <namespace key="11" case="first-letter">Template talk</namespace>
488 <namespace key="12" case="first-letter">Help</namespace>
489 <namespace key="13" case="first-letter">Help talk</namespace>
490 <namespace key="14" case="first-letter">Category</namespace>
491 <namespace key="15" case="first-letter">Category talk</namespace>
495 $tail = '</mediawiki>
499 $iterations = intval( $iterations );
500 for ( $i = 0; $i < $iterations; $i++
) {
503 <title>BackupDumperTestP1</title>
505 <id>' . ( $this->pageId1 +
$i * self
::$numOfPages ) . '</id>
507 <id>' . ( $this->revId1_1 +
$i * self
::$numOfRevs ) . '</id>
508 <timestamp>2012-04-01T16:46:05Z</timestamp>
512 <comment>BackupDumperTestP1Summary1</comment>
513 <model>wikitext</model>
514 <format>text/x-wiki</format>
515 <text id="' . $this->textId1_1
. '" bytes="23" />
516 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
521 <title>BackupDumperTestP2</title>
523 <id>' . ( $this->pageId2 +
$i * self
::$numOfPages ) . '</id>
525 <id>' . ( $this->revId2_1 +
$i * self
::$numOfRevs ) . '</id>
526 <timestamp>2012-04-01T16:46:05Z</timestamp>
530 <comment>BackupDumperTestP2Summary1</comment>
531 <model>wikitext</model>
532 <format>text/x-wiki</format>
533 <text id="' . $this->textId2_1
. '" bytes="23" />
534 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
537 <id>' . ( $this->revId2_2 +
$i * self
::$numOfRevs ) . '</id>
538 <parentid>' . ( $this->revId2_1 +
$i * self
::$numOfRevs ) . '</parentid>
539 <timestamp>2012-04-01T16:46:05Z</timestamp>
543 <comment>BackupDumperTestP2Summary2</comment>
544 <model>wikitext</model>
545 <format>text/x-wiki</format>
546 <text id="' . $this->textId2_2
. '" bytes="23" />
547 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
550 <id>' . ( $this->revId2_3 +
$i * self
::$numOfRevs ) . '</id>
551 <parentid>' . ( $this->revId2_2 +
$i * self
::$numOfRevs ) . '</parentid>
552 <timestamp>2012-04-01T16:46:05Z</timestamp>
556 <comment>BackupDumperTestP2Summary3</comment>
557 <model>wikitext</model>
558 <format>text/x-wiki</format>
559 <text id="' . $this->textId2_3
. '" bytes="23" />
560 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
563 <id>' . ( $this->revId2_4 +
$i * self
::$numOfRevs ) . '</id>
564 <parentid>' . ( $this->revId2_3 +
$i * self
::$numOfRevs ) . '</parentid>
565 <timestamp>2012-04-01T16:46:05Z</timestamp>
569 <comment>BackupDumperTestP2Summary4 extra</comment>
570 <model>wikitext</model>
571 <format>text/x-wiki</format>
572 <text id="' . $this->textId2_4
. '" bytes="44" />
573 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
577 // page 3 not in stub
580 <title>Talk:BackupDumperTestP1</title>
582 <id>' . ( $this->pageId4 +
$i * self
::$numOfPages ) . '</id>
584 <id>' . ( $this->revId4_1 +
$i * self
::$numOfRevs ) . '</id>
585 <timestamp>2012-04-01T16:46:05Z</timestamp>
589 <comment>Talk BackupDumperTestP1 Summary1</comment>
590 <model>BackupTextPassTestModel</model>
591 <format>text/plain</format>
592 <text id="' . $this->textId4_1
. '" bytes="35" />
593 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
597 $content .= $page1 . $page2 . $page4;
600 $this->assertEquals( strlen( $content ), file_put_contents(
601 $fname, $content ), "Length of prepared stub" );
607 class BackupTextPassTestModelHandler
extends TextContentHandler
{
609 public function __construct() {
610 parent
::__construct( 'BackupTextPassTestModel' );
613 public function exportTransform( $text, $format = null ) {
614 return strtoupper( $text );
620 * Tests for TextPassDumper that do not rely on the database
622 * (As the Database group is only detected at class level (not method level), we
623 * cannot bring this test case's tests into the above main test case.)
626 * @covers TextPassDumper
628 class TextPassDumperDatabaselessTest
extends MediaWikiLangTestCase
{
630 * Ensures that setting the buffer size is effective.
632 * @dataProvider bufferSizeProvider
634 function testBufferSizeSetting( $expected, $size, $msg ) {
635 $dumper = new TextPassDumperAccessor( array( "--buffersize=" . $size ) );
636 $this->assertEquals( $expected, $dumper->getBufferSize(), $msg);
640 * Ensures that setting the buffer size is effective.
642 * @dataProvider bufferSizeProvider
644 function bufferSizeProvider() {
645 // expected, bufferSize to initialize with, message
647 array( 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ),
648 array( 8192, 8192, "Setting 8KB is not effective" ),
649 array( 4096, 2048, "Could set buffer size below lower bound" )
655 * Accessor for internal state of TextPassDumper
657 * Do not warrentless add getters here.
659 class TextPassDumperAccessor
extends TextPassDumper
{
661 * Gets the bufferSize.
663 * If bufferSize setting does not work correctly, testCheckpoint... tests
664 * fail and point in the wrong direction. To aid in troubleshooting when
665 * testCheckpoint... tests break at some point in the future, we test the
666 * bufferSize setting, hence need this accessor.
668 * (Yes, bufferSize is internal state of the TextPassDumper, but aiding
669 * debugging of testCheckpoint... in the future seems to be worth testing
670 * against it nonetheless.)
672 public function getBufferSize() {
673 return $this->bufferSize
;