Copy teardownUploadDir(),deleteFiles(),deleteDirs() from parserTest.inc Move down...
authorPlatonides <platonides@users.mediawiki.org>
Thu, 16 Jun 2011 21:07:37 +0000 (21:07 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 16 Jun 2011 21:07:37 +0000 (21:07 +0000)
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...

tests/phpunit/includes/parser/NewParserTest.php

index 70e8d77..b8c2519 100644 (file)
@@ -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;