r110037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110036‎ | r110037 | r110038 >
Date:23:11, 25 January 2012
Author:aaron
Status:ok
Tags:
Comment:
* In NewParserTest, refactored code to use FileBackend (bug 31737). Also made some speed improvements and made regex= not flood the output with 600 items of crap.
* In FileBackendTest, call clean() on the dirs *after* deleting all the files first.
* Speed improvements to MediaWikiTestCase.
Modified paths:
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -87,6 +87,10 @@
8888 function addDBData() {}
8989
9090 private function addCoreDBData() {
 91+ # disabled for performance
 92+ #$this->tablesUsed[] = 'page';
 93+ #$this->tablesUsed[] = 'revision';
 94+
9195 if ( $this->db->getType() == 'oracle' ) {
9296
9397 # Insert 0 user to prevent FK violations
@@ -129,11 +133,13 @@
130134
131135 //Make 1 page with 1 revision
132136 $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
133 - $page->doEdit( 'UTContent',
134 - 'UTPageSummary',
135 - EDIT_NEW,
136 - false,
137 - User::newFromName( 'UTSysop' ) );
 137+ if ( !$page->getId() == 0 ) {
 138+ $page->doEdit( 'UTContent',
 139+ 'UTPageSummary',
 140+ EDIT_NEW,
 141+ false,
 142+ User::newFromName( 'UTSysop' ) );
 143+ }
138144 }
139145
140146 private function initDB() {
Index: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
@@ -109,8 +109,8 @@
110110 }
111111
112112 public function tearDown() {
113 - $this->repo->cleanupBatch( $this->createdFiles );
114 - foreach ( $this->createdFiles as $tmp ) {
 113+ $this->repo->cleanupBatch( $this->createdFiles ); // delete files
 114+ foreach ( $this->createdFiles as $tmp ) { // delete dirs
115115 $tmp = $this->repo->resolveVirtualUrl( $tmp );
116116 while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
117117 $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php
@@ -1062,8 +1062,10 @@
10631063 $base = $this->baseStorePath();
10641064 $iter = $backend->getFileList( array( 'dir' => "$base/$container" ) );
10651065 if ( $iter ) {
1066 - foreach ( $iter as $file ) {
1067 - $backend->delete( array( 'src' => "$base/$container/$file", 'ignoreMissingSource' => 1 ) );
 1066+ foreach ( $iter as $file ) { // delete files
 1067+ $backend->delete( array( 'src' => "$base/$container/$file" ), array( 'force' => 1 ) );
 1068+ }
 1069+ foreach ( $iter as $file ) { // delete dirs
10681070 $tmp = $file;
10691071 while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
10701072 $backend->clean( array( 'dir' => $tmp ) );
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -14,7 +14,6 @@
1515 * When running tests from several files, all tests will see all articles.
1616 */
1717
18 - public $uploadDir;
1918 public $keepUploads = false;
2019 public $runDisabled = false;
2120 public $regex = '';
@@ -118,7 +117,11 @@
119118 }
120119
121120 function addDBData() {
122 - $this->tablesUsed[] = 'image';
 121+ $this->tablesUsed[] = 'site_stats';
 122+ $this->tablesUsed[] = 'interwiki';
 123+ # disabled for performance
 124+ #$this->tablesUsed[] = 'image';
 125+
123126 # Hack: insert a few Wikipedia in-project interwiki prefixes,
124127 # for testing inter-language links
125128 $this->db->insert( 'interwiki', array(
@@ -156,13 +159,15 @@
157160 * @todo Fixme! Why are we inserting duplicate data here? Shouldn't
158161 * need this IGNORE or shouldn't need the insert at all.
159162 */
160 - ), __METHOD__, array( 'IGNORE' ) );
 163+ ), __METHOD__, array( 'IGNORE' )
 164+ );
161165
162166
163167 # Update certain things in site_stats
164168 $this->db->insert( 'site_stats',
165169 array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
166 - __METHOD__, array( 'IGNORE' ) );
 170+ __METHOD__
 171+ );
167172
168173 # Reinitialise the LocalisationCache to match the database state
169174 Language::getLocalisationCache()->unloadAll();
@@ -170,38 +175,53 @@
171176 # Clear the message cache
172177 MessageCache::singleton()->clear();
173178
174 - $this->uploadDir = $this->setupUploadDir();
175 -
176179 $user = User::newFromId( 0 );
177180 LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
178181
 182+ # Upload DB table entries for files.
 183+ # We will upload the actual files later. Note that if anything causes LocalFile::load()
 184+ # to be triggered before then, it will break via maybeUpgrade() setting the fileExists
 185+ # member to false and storing it in cache.
179186 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
180 - $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
181 - 'size' => 12345,
182 - 'width' => 1941,
183 - 'height' => 220,
184 - 'bits' => 24,
185 - 'media_type' => MEDIATYPE_BITMAP,
186 - 'mime' => 'image/jpeg',
187 - 'metadata' => serialize( array() ),
188 - 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
189 - 'fileExists' => true
190 - ), $this->db->timestamp( '20010115123500' ), $user );
 187+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
 188+ $image->recordUpload2(
 189+ '', // archive name
 190+ 'Upload of some lame file',
 191+ 'Some lame file',
 192+ array(
 193+ 'size' => 12345,
 194+ 'width' => 1941,
 195+ 'height' => 220,
 196+ 'bits' => 24,
 197+ 'media_type' => MEDIATYPE_BITMAP,
 198+ 'mime' => 'image/jpeg',
 199+ 'metadata' => serialize( array() ),
 200+ 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
 201+ 'fileExists' => true ),
 202+ $this->db->timestamp( '20010115123500' ), $user
 203+ );
 204+ }
191205
192206 # This image will be blacklisted in [[MediaWiki:Bad image list]]
193207 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
194 - $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array(
195 - 'size' => 12345,
196 - 'width' => 320,
197 - 'height' => 240,
198 - 'bits' => 24,
199 - 'media_type' => MEDIATYPE_BITMAP,
200 - 'mime' => 'image/jpeg',
201 - 'metadata' => serialize( array() ),
202 - 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
203 - 'fileExists' => true
204 - ), $this->db->timestamp( '20010115123500' ), $user );
205 -
 208+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
 209+ $image->recordUpload2(
 210+ '', // archive name
 211+ 'zomgnotcensored',
 212+ 'Borderline image',
 213+ array(
 214+ 'size' => 12345,
 215+ 'width' => 320,
 216+ 'height' => 240,
 217+ 'bits' => 24,
 218+ 'media_type' => MEDIATYPE_BITMAP,
 219+ 'mime' => 'image/jpeg',
 220+ 'metadata' => serialize( array() ),
 221+ 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
 222+ 'fileExists' => true ),
 223+ $this->db->timestamp( '20010115123500' ), $user
 224+ );
 225+ }
206226 }
207227
208228
@@ -224,6 +244,16 @@
225245 $linkHolderBatchSize =
226246 self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
227247
 248+ $uploadDir = $this->getUploadDir();
 249+ $backend = new FSFileBackend( array(
 250+ 'name' => 'local-backend',
 251+ 'lockManager' => 'nullLockManager',
 252+ 'containerPaths' => array(
 253+ 'local-public' => "$uploadDir",
 254+ 'local-thumb' => "$uploadDir/thumb",
 255+ )
 256+ ) );
 257+
228258 $settings = array(
229259 'wgServer' => 'http://Britney-Spears',
230260 'wgScript' => '/index.php',
@@ -237,14 +267,7 @@
238268 'url' => 'http://example.com/images',
239269 'hashLevels' => 2,
240270 'transformVia404' => false,
241 - 'backend' => new FSFileBackend( array(
242 - 'name' => 'local-backend',
243 - 'lockManager' => 'nullLockManager',
244 - 'containerPaths' => array(
245 - 'local-public' => "$this->uploadDir",
246 - 'local-thumb' => "$this->uploadDir/thumb",
247 - )
248 - ) )
 271+ 'backend' => $backend
249272 ),
250273 'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
251274 'wgStylePath' => '/skins',
@@ -263,7 +286,7 @@
264287 'wgThumbnailScriptPath' => false,
265288 'wgUseImageResize' => false,
266289 'wgUseTeX' => isset( $opts['math'] ),
267 - 'wgMathDirectory' => $this->uploadDir . '/math',
 290+ 'wgMathDirectory' => $uploadDir . '/math',
268291 'wgLocaltimezone' => 'UTC',
269292 'wgAllowExternalImages' => true,
270293 'wgUseTidy' => false,
@@ -329,6 +352,9 @@
330353 RepoGroup::destroySingleton();
331354 FileBackendGroup::destroySingleton();
332355
 356+ # Create dummy files in storage
 357+ $this->setupUploads();
 358+
333359 # Publish the articles after we have the final language set
334360 $this->publishTestArticles();
335361
@@ -341,14 +367,11 @@
342368 }
343369
344370 /**
345 - * Create a dummy uploads directory which will contain a couple
346 - * of files in order to pass existence tests.
 371+ * Get an FS upload directory (only applies to FSFileBackend)
347372 *
348373 * @return String: the directory
349374 */
350 - protected function setupUploadDir() {
351 - global $IP;
352 -
 375+ protected function getUploadDir() {
353376 if ( $this->keepUploads ) {
354377 $dir = wfTempDir() . '/mwParser-images';
355378
@@ -365,72 +388,68 @@
366389 return $dir;
367390 }
368391
369 - wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
370 - copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
371 - wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
372 - copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
373 -
374392 return $dir;
375393 }
376394
377395 /**
 396+ * Create a dummy uploads directory which will contain a couple
 397+ * of files in order to pass existence tests.
 398+ *
 399+ * @return String: the directory
 400+ */
 401+ protected function setupUploads() {
 402+ global $IP;
 403+
 404+ $base = $this->getBaseDir();
 405+ $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
 406+ $backend->prepare( array( 'dir' => "$base/local-public/3/3a" ) );
 407+ $backend->store( array(
 408+ 'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/3/3a/Foobar.jpg"
 409+ ) );
 410+ $backend->prepare( array( 'dir' => "$base/local-public/0/09" ) );
 411+ $backend->store( array(
 412+ 'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg"
 413+ ) );
 414+ }
 415+
 416+ /**
378417 * Restore default values and perform any necessary clean-up
379418 * after each test runs.
380419 */
381420 protected function teardownGlobals() {
 421+ $this->teardownUploads();
 422+
382423 foreach ( $this->savedGlobals as $var => $val ) {
383424 $GLOBALS[$var] = $val;
384425 }
385426
386427 RepoGroup::destroySingleton();
387428 LinkCache::singleton()->clear();
388 -
389 - $this->teardownUploadDir( $this->uploadDir );
390429 }
391430
392431 /**
393432 * Remove the dummy uploads directory
394433 */
395 - private function teardownUploadDir( $dir ) {
 434+ private function teardownUploads() {
396435 if ( $this->keepUploads ) {
397436 return;
398437 }
399438
 439+ $base = $this->getBaseDir();
400440 // delete the files first, then the dirs.
401441 self::deleteFiles(
402442 array (
403 - "$dir/3/3a/Foobar.jpg",
404 - "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
405 - "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
406 - "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
407 - "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
 443+ "$base/local-public/3/3a/Foobar.jpg",
 444+ "$base/local-thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
 445+ "$base/local-thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
 446+ "$base/local-thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
 447+ "$base/local-thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
408448
409 - "$dir/0/09/Bad.jpg",
 449+ "$base/local-thumb/0/09/Bad.jpg",
410450
411 - "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
 451+ "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
412452 )
413453 );
414 -
415 - self::deleteDirs(
416 - array (
417 - "$dir/3/3a",
418 - "$dir/3",
419 - "$dir/thumb/6/65",
420 - "$dir/thumb/6",
421 - "$dir/thumb/3/3a/Foobar.jpg",
422 - "$dir/thumb/3/3a",
423 - "$dir/thumb/3",
424 -
425 - "$dir/0/09/",
426 - "$dir/0/",
427 - "$dir/thumb",
428 - "$dir/math/f/a/5",
429 - "$dir/math/f/a",
430 - "$dir/math/f",
431 - "$dir/math",
432 - "$dir",
433 - )
434 - );
435454 }
436455
437456 /**
@@ -438,23 +457,20 @@
439458 * @param $files Array: full paths to files to delete.
440459 */
441460 private static function deleteFiles( $files ) {
 461+ $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
442462 foreach ( $files as $file ) {
443 - if ( file_exists( $file ) ) {
444 - unlink( $file );
 463+ $backend->delete( array( 'src' => $file ), array( 'force' => 1 ) );
 464+ }
 465+ foreach ( $files as $file ) {
 466+ $tmp = $file;
 467+ while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
 468+ $backend->clean( array( 'dir' => $tmp ) );
445469 }
446470 }
447471 }
448472
449 - /**
450 - * Delete the specified directories, if they exist. Must be empty.
451 - * @param $dirs Array: full paths to directories to delete.
452 - */
453 - private static function deleteDirs( $dirs ) {
454 - foreach ( $dirs as $dir ) {
455 - if ( is_dir( $dir ) ) {
456 - rmdir( $dir );
457 - }
458 - }
 473+ protected function getBaseDir() {
 474+ return 'mwstore://local-backend';
459475 }
460476
461477 public function parserTestProvider() {
@@ -474,7 +490,11 @@
475491
476492 /** @dataProvider parserTestProvider */
477493 public function testParserTest( $desc, $input, $result, $opts, $config ) {
478 - if ( !preg_match( '/' . $this->regex . '/', $desc ) ) return; //$this->markTestSkipped( 'Filtered out by the user' );
 494+ if ( $this->regex != '' && !preg_match( '/' . $this->regex . '/', $desc ) ) {
 495+ $this->assertTrue( true ); // XXX: don't flood output with "test made no assertions"
 496+ //$this->markTestSkipped( 'Filtered out by the user' );
 497+ return;
 498+ }
479499
480500 wfDebug( "Running parser test: $desc\n" );
481501

Status & tagging log