From: Platonides Date: Thu, 16 Jun 2011 21:07:37 +0000 (+0000) Subject: Copy teardownUploadDir(),deleteFiles(),deleteDirs() from parserTest.inc Move down... X-Git-Tag: 1.31.0-rc.0~29490 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=efbd16e8257bfc9fd2d7a1e4415fd450c1679334;p=lhc%2Fweb%2Fwiklou.git Copy teardownUploadDir(),deleteFiles(),deleteDirs() from parserTest.inc Move down teardownGlobals() This almost fixes the issue of hundreds of leaking mwParser-*-images files at temp dir. For some unknown reason, there's still one instance left, though. PS: I thought I had committed this time ago... --- diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 70e8d7753a..b8c2519926 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -335,20 +335,7 @@ class NewParserTest extends MediaWikiTestCase { global $wgUser; $wgUser = new User(); } - - /** - * Restore default values and perform any necessary clean-up - * after each test runs. - */ - protected function teardownGlobals() { - RepoGroup::destroySingleton(); - LinkCache::singleton()->clear(); - foreach ( $this->savedGlobals as $var => $val ) { - $GLOBALS[$var] = $val; - } - } - /** * Create a dummy uploads directory which will contain a couple * of files in order to pass existence tests. @@ -382,6 +369,90 @@ class NewParserTest extends MediaWikiTestCase { return $dir; } + /** + * Restore default values and perform any necessary clean-up + * after each test runs. + */ + protected function teardownGlobals() { + RepoGroup::destroySingleton(); + LinkCache::singleton()->clear(); + + foreach ( $this->savedGlobals as $var => $val ) { + $GLOBALS[$var] = $val; + } + + $this->teardownUploadDir( $this->uploadDir ); + } + + /** + * Remove the dummy uploads directory + */ + private function teardownUploadDir( $dir ) { + if ( $this->keepUploads ) { + return; + } + + // delete the files first, then the dirs. + self::deleteFiles( + array ( + "$dir/3/3a/Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", + + "$dir/0/09/Bad.jpg", + + "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", + ) + ); + + self::deleteDirs( + array ( + "$dir/3/3a", + "$dir/3", + "$dir/thumb/6/65", + "$dir/thumb/6", + "$dir/thumb/3/3a/Foobar.jpg", + "$dir/thumb/3/3a", + "$dir/thumb/3", + + "$dir/0/09/", + "$dir/0/", + "$dir/thumb", + "$dir/math/f/a/5", + "$dir/math/f/a", + "$dir/math/f", + "$dir/math", + "$dir", + ) + ); + } + + /** + * Delete the specified files, if they exist. + * @param $files Array: full paths to files to delete. + */ + private static function deleteFiles( $files ) { + foreach ( $files as $file ) { + if ( file_exists( $file ) ) { + unlink( $file ); + } + } + } + + /** + * Delete the specified directories, if they exist. Must be empty. + * @param $dirs Array: full paths to directories to delete. + */ + private static function deleteDirs( $dirs ) { + foreach ( $dirs as $dir ) { + if ( is_dir( $dir ) ) { + rmdir( $dir ); + } + } + } + public function parserTestProvider() { if ( $this->file === false ) { global $wgParserTestFiles;