Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php |
— | — | @@ -87,6 +87,10 @@ |
88 | 88 | function addDBData() {} |
89 | 89 | |
90 | 90 | private function addCoreDBData() { |
| 91 | + # disabled for performance |
| 92 | + #$this->tablesUsed[] = 'page'; |
| 93 | + #$this->tablesUsed[] = 'revision'; |
| 94 | + |
91 | 95 | if ( $this->db->getType() == 'oracle' ) { |
92 | 96 | |
93 | 97 | # Insert 0 user to prevent FK violations |
— | — | @@ -129,11 +133,13 @@ |
130 | 134 | |
131 | 135 | //Make 1 page with 1 revision |
132 | 136 | $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 | + } |
138 | 144 | } |
139 | 145 | |
140 | 146 | private function initDB() { |
Index: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php |
— | — | @@ -109,8 +109,8 @@ |
110 | 110 | } |
111 | 111 | |
112 | 112 | 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 |
115 | 115 | $tmp = $this->repo->resolveVirtualUrl( $tmp ); |
116 | 116 | while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { |
117 | 117 | $this->repo->getBackend()->clean( array( 'dir' => $tmp ) ); |
Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -1062,8 +1062,10 @@ |
1063 | 1063 | $base = $this->baseStorePath(); |
1064 | 1064 | $iter = $backend->getFileList( array( 'dir' => "$base/$container" ) ); |
1065 | 1065 | 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 |
1068 | 1070 | $tmp = $file; |
1069 | 1071 | while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { |
1070 | 1072 | $backend->clean( array( 'dir' => $tmp ) ); |
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php |
— | — | @@ -14,7 +14,6 @@ |
15 | 15 | * When running tests from several files, all tests will see all articles. |
16 | 16 | */ |
17 | 17 | |
18 | | - public $uploadDir; |
19 | 18 | public $keepUploads = false; |
20 | 19 | public $runDisabled = false; |
21 | 20 | public $regex = ''; |
— | — | @@ -118,7 +117,11 @@ |
119 | 118 | } |
120 | 119 | |
121 | 120 | function addDBData() { |
122 | | - $this->tablesUsed[] = 'image'; |
| 121 | + $this->tablesUsed[] = 'site_stats'; |
| 122 | + $this->tablesUsed[] = 'interwiki'; |
| 123 | + # disabled for performance |
| 124 | + #$this->tablesUsed[] = 'image'; |
| 125 | + |
123 | 126 | # Hack: insert a few Wikipedia in-project interwiki prefixes, |
124 | 127 | # for testing inter-language links |
125 | 128 | $this->db->insert( 'interwiki', array( |
— | — | @@ -156,13 +159,15 @@ |
157 | 160 | * @todo Fixme! Why are we inserting duplicate data here? Shouldn't |
158 | 161 | * need this IGNORE or shouldn't need the insert at all. |
159 | 162 | */ |
160 | | - ), __METHOD__, array( 'IGNORE' ) ); |
| 163 | + ), __METHOD__, array( 'IGNORE' ) |
| 164 | + ); |
161 | 165 | |
162 | 166 | |
163 | 167 | # Update certain things in site_stats |
164 | 168 | $this->db->insert( 'site_stats', |
165 | 169 | array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ), |
166 | | - __METHOD__, array( 'IGNORE' ) ); |
| 170 | + __METHOD__ |
| 171 | + ); |
167 | 172 | |
168 | 173 | # Reinitialise the LocalisationCache to match the database state |
169 | 174 | Language::getLocalisationCache()->unloadAll(); |
— | — | @@ -170,38 +175,53 @@ |
171 | 176 | # Clear the message cache |
172 | 177 | MessageCache::singleton()->clear(); |
173 | 178 | |
174 | | - $this->uploadDir = $this->setupUploadDir(); |
175 | | - |
176 | 179 | $user = User::newFromId( 0 ); |
177 | 180 | LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision |
178 | 181 | |
| 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. |
179 | 186 | $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 | + } |
191 | 205 | |
192 | 206 | # This image will be blacklisted in [[MediaWiki:Bad image list]] |
193 | 207 | $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 | + } |
206 | 226 | } |
207 | 227 | |
208 | 228 | |
— | — | @@ -224,6 +244,16 @@ |
225 | 245 | $linkHolderBatchSize = |
226 | 246 | self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 ); |
227 | 247 | |
| 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 | + |
228 | 258 | $settings = array( |
229 | 259 | 'wgServer' => 'http://Britney-Spears', |
230 | 260 | 'wgScript' => '/index.php', |
— | — | @@ -237,14 +267,7 @@ |
238 | 268 | 'url' => 'http://example.com/images', |
239 | 269 | 'hashLevels' => 2, |
240 | 270 | '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 |
249 | 272 | ), |
250 | 273 | 'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ), |
251 | 274 | 'wgStylePath' => '/skins', |
— | — | @@ -263,7 +286,7 @@ |
264 | 287 | 'wgThumbnailScriptPath' => false, |
265 | 288 | 'wgUseImageResize' => false, |
266 | 289 | 'wgUseTeX' => isset( $opts['math'] ), |
267 | | - 'wgMathDirectory' => $this->uploadDir . '/math', |
| 290 | + 'wgMathDirectory' => $uploadDir . '/math', |
268 | 291 | 'wgLocaltimezone' => 'UTC', |
269 | 292 | 'wgAllowExternalImages' => true, |
270 | 293 | 'wgUseTidy' => false, |
— | — | @@ -329,6 +352,9 @@ |
330 | 353 | RepoGroup::destroySingleton(); |
331 | 354 | FileBackendGroup::destroySingleton(); |
332 | 355 | |
| 356 | + # Create dummy files in storage |
| 357 | + $this->setupUploads(); |
| 358 | + |
333 | 359 | # Publish the articles after we have the final language set |
334 | 360 | $this->publishTestArticles(); |
335 | 361 | |
— | — | @@ -341,14 +367,11 @@ |
342 | 368 | } |
343 | 369 | |
344 | 370 | /** |
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) |
347 | 372 | * |
348 | 373 | * @return String: the directory |
349 | 374 | */ |
350 | | - protected function setupUploadDir() { |
351 | | - global $IP; |
352 | | - |
| 375 | + protected function getUploadDir() { |
353 | 376 | if ( $this->keepUploads ) { |
354 | 377 | $dir = wfTempDir() . '/mwParser-images'; |
355 | 378 | |
— | — | @@ -365,72 +388,68 @@ |
366 | 389 | return $dir; |
367 | 390 | } |
368 | 391 | |
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 | | - |
374 | 392 | return $dir; |
375 | 393 | } |
376 | 394 | |
377 | 395 | /** |
| 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 | + /** |
378 | 417 | * Restore default values and perform any necessary clean-up |
379 | 418 | * after each test runs. |
380 | 419 | */ |
381 | 420 | protected function teardownGlobals() { |
| 421 | + $this->teardownUploads(); |
| 422 | + |
382 | 423 | foreach ( $this->savedGlobals as $var => $val ) { |
383 | 424 | $GLOBALS[$var] = $val; |
384 | 425 | } |
385 | 426 | |
386 | 427 | RepoGroup::destroySingleton(); |
387 | 428 | LinkCache::singleton()->clear(); |
388 | | - |
389 | | - $this->teardownUploadDir( $this->uploadDir ); |
390 | 429 | } |
391 | 430 | |
392 | 431 | /** |
393 | 432 | * Remove the dummy uploads directory |
394 | 433 | */ |
395 | | - private function teardownUploadDir( $dir ) { |
| 434 | + private function teardownUploads() { |
396 | 435 | if ( $this->keepUploads ) { |
397 | 436 | return; |
398 | 437 | } |
399 | 438 | |
| 439 | + $base = $this->getBaseDir(); |
400 | 440 | // delete the files first, then the dirs. |
401 | 441 | self::deleteFiles( |
402 | 442 | 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", |
408 | 448 | |
409 | | - "$dir/0/09/Bad.jpg", |
| 449 | + "$base/local-thumb/0/09/Bad.jpg", |
410 | 450 | |
411 | | - "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", |
| 451 | + "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", |
412 | 452 | ) |
413 | 453 | ); |
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 | | - ); |
435 | 454 | } |
436 | 455 | |
437 | 456 | /** |
— | — | @@ -438,23 +457,20 @@ |
439 | 458 | * @param $files Array: full paths to files to delete. |
440 | 459 | */ |
441 | 460 | private static function deleteFiles( $files ) { |
| 461 | + $backend = RepoGroup::singleton()->getLocalRepo()->getBackend(); |
442 | 462 | 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 ) ); |
445 | 469 | } |
446 | 470 | } |
447 | 471 | } |
448 | 472 | |
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'; |
459 | 475 | } |
460 | 476 | |
461 | 477 | public function parserTestProvider() { |
— | — | @@ -474,7 +490,11 @@ |
475 | 491 | |
476 | 492 | /** @dataProvider parserTestProvider */ |
477 | 493 | 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 | + } |
479 | 499 | |
480 | 500 | wfDebug( "Running parser test: $desc\n" ); |
481 | 501 | |