Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php |
— | — | @@ -335,20 +335,7 @@ |
336 | 336 | global $wgUser; |
337 | 337 | $wgUser = new User(); |
338 | 338 | } |
339 | | - |
340 | | - /** |
341 | | - * Restore default values and perform any necessary clean-up |
342 | | - * after each test runs. |
343 | | - */ |
344 | | - protected function teardownGlobals() { |
345 | | - RepoGroup::destroySingleton(); |
346 | | - LinkCache::singleton()->clear(); |
347 | 339 | |
348 | | - foreach ( $this->savedGlobals as $var => $val ) { |
349 | | - $GLOBALS[$var] = $val; |
350 | | - } |
351 | | - } |
352 | | - |
353 | 340 | /** |
354 | 341 | * Create a dummy uploads directory which will contain a couple |
355 | 342 | * of files in order to pass existence tests. |
— | — | @@ -382,6 +369,90 @@ |
383 | 370 | return $dir; |
384 | 371 | } |
385 | 372 | |
| 373 | + /** |
| 374 | + * Restore default values and perform any necessary clean-up |
| 375 | + * after each test runs. |
| 376 | + */ |
| 377 | + protected function teardownGlobals() { |
| 378 | + RepoGroup::destroySingleton(); |
| 379 | + LinkCache::singleton()->clear(); |
| 380 | + |
| 381 | + foreach ( $this->savedGlobals as $var => $val ) { |
| 382 | + $GLOBALS[$var] = $val; |
| 383 | + } |
| 384 | + |
| 385 | + $this->teardownUploadDir( $this->uploadDir ); |
| 386 | + } |
| 387 | + |
| 388 | + /** |
| 389 | + * Remove the dummy uploads directory |
| 390 | + */ |
| 391 | + private function teardownUploadDir( $dir ) { |
| 392 | + if ( $this->keepUploads ) { |
| 393 | + return; |
| 394 | + } |
| 395 | + |
| 396 | + // delete the files first, then the dirs. |
| 397 | + self::deleteFiles( |
| 398 | + array ( |
| 399 | + "$dir/3/3a/Foobar.jpg", |
| 400 | + "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", |
| 401 | + "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", |
| 402 | + "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg", |
| 403 | + "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", |
| 404 | + |
| 405 | + "$dir/0/09/Bad.jpg", |
| 406 | + |
| 407 | + "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", |
| 408 | + ) |
| 409 | + ); |
| 410 | + |
| 411 | + self::deleteDirs( |
| 412 | + array ( |
| 413 | + "$dir/3/3a", |
| 414 | + "$dir/3", |
| 415 | + "$dir/thumb/6/65", |
| 416 | + "$dir/thumb/6", |
| 417 | + "$dir/thumb/3/3a/Foobar.jpg", |
| 418 | + "$dir/thumb/3/3a", |
| 419 | + "$dir/thumb/3", |
| 420 | + |
| 421 | + "$dir/0/09/", |
| 422 | + "$dir/0/", |
| 423 | + "$dir/thumb", |
| 424 | + "$dir/math/f/a/5", |
| 425 | + "$dir/math/f/a", |
| 426 | + "$dir/math/f", |
| 427 | + "$dir/math", |
| 428 | + "$dir", |
| 429 | + ) |
| 430 | + ); |
| 431 | + } |
| 432 | + |
| 433 | + /** |
| 434 | + * Delete the specified files, if they exist. |
| 435 | + * @param $files Array: full paths to files to delete. |
| 436 | + */ |
| 437 | + private static function deleteFiles( $files ) { |
| 438 | + foreach ( $files as $file ) { |
| 439 | + if ( file_exists( $file ) ) { |
| 440 | + unlink( $file ); |
| 441 | + } |
| 442 | + } |
| 443 | + } |
| 444 | + |
| 445 | + /** |
| 446 | + * Delete the specified directories, if they exist. Must be empty. |
| 447 | + * @param $dirs Array: full paths to directories to delete. |
| 448 | + */ |
| 449 | + private static function deleteDirs( $dirs ) { |
| 450 | + foreach ( $dirs as $dir ) { |
| 451 | + if ( is_dir( $dir ) ) { |
| 452 | + rmdir( $dir ); |
| 453 | + } |
| 454 | + } |
| 455 | + } |
| 456 | + |
386 | 457 | public function parserTestProvider() { |
387 | 458 | if ( $this->file === false ) { |
388 | 459 | global $wgParserTestFiles; |