Merge "CologneBlue rewrite: rework quickbar() once again"
[lhc/web/wiklou.git] / tests / phpunit / suites / UploadFromUrlTestSuite.php
index e9c1963..843aaf9 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 
-require_once( dirname( dirname( __FILE__ ) ) . '/includes/upload/UploadFromUrlTest.php' );
+require_once( dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php' );
 
 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
+       public $savedGlobals = array();
+
        public static function addTables( &$tables ) {
                $tables[] = 'user_properties';
                $tables[] = 'filearchive';
@@ -13,39 +15,43 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
                return true;
        }
 
-       function setUp() {
+       protected function setUp() {
                global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
-                                 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
-                                 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
-                                 $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
-                                 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
-
-               $wgScript = '/index.php';
-               $wgScriptPath = '/';
-               $wgArticlePath = '/wiki/$1';
-               $wgStyleSheetPath = '/skins';
-               $wgStylePath = '/skins';
-               $wgThumbnailScriptPath = false;
-               $backend = new FSFileBackend( array(
-                       'name'        => 'local-backend',
-                       'lockManager' => 'fsLockManager',
-                       'containerPaths' => array(
-                               'media-public'  => wfTempDir() . '/test-repo/public',
-                               'media-thumb'   => wfTempDir() . '/test-repo/thumb',
-                               'media-temp'    => wfTempDir() . '/test-repo/temp',
-                               'media-deleted' => wfTempDir() . '/test-repo/delete',
-                       )
-               ) );
-               $wgLocalFileRepo = array(
+                         $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
+                         $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
+
+               $tmpGlobals = array();
+
+               $tmpGlobals['wgScript'] = '/index.php';
+               $tmpGlobals['wgScriptPath'] = '/';
+               $tmpGlobals['wgArticlePath'] = '/wiki/$1';
+               $tmpGlobals['wgStyleSheetPath'] = '/skins';
+               $tmpGlobals['wgStylePath'] = '/skins';
+               $tmpGlobals['wgThumbnailScriptPath'] = false;
+               $tmpGlobals['wgLocalFileRepo'] = array(
                        'class'           => 'LocalRepo',
                        'name'            => 'local',
                        'url'             => 'http://example.com/images',
                        'hashLevels'      => 2,
                        'transformVia404' => false,
-                       'backend'         => $backend,
-                       'zones'           => array( 'deleted' => array(
-                               'container' => 'media-deleted', 'directory' => '' ) )
+                       'backend'         => new FSFileBackend( array(
+                               'name'        => 'local-backend',
+                               'lockManager' => 'fsLockManager',
+                               'containerPaths' => array(
+                                       'local-public'  => wfTempDir() . '/test-repo/public',
+                                       'local-thumb'   => wfTempDir() . '/test-repo/thumb',
+                                       'local-temp'    => wfTempDir() . '/test-repo/temp',
+                                       'local-deleted' => wfTempDir() . '/test-repo/delete',
+                               )
+                       ) ),
                );
+               foreach ( $tmpGlobals as $var => $val ) {
+                       if ( array_key_exists( $var, $GLOBALS ) ) {
+                               $this->savedGlobals[$var] = $GLOBALS[$var];
+                       }
+                       $GLOBALS[$var] = $val;
+               }
+
                $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
                $wgNamespaceAliases['Image'] = NS_FILE;
                $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
@@ -69,10 +75,18 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
                        $wgStyleDirectory   = "$IP/skins";
                }
 
+               RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
        }
 
-       // @FIXME: restore globals?
-       public function tearDown() {
+       protected function tearDown() {
+               foreach ( $this->savedGlobals as $var => $val ) {
+                       $GLOBALS[$var] = $val;
+               }
+               // Restore backends
+               RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
+
                $this->teardownUploadDir( $this->uploadDir );
        }