Merge "CologneBlue rewrite: rework quickbar() once again"
[lhc/web/wiklou.git] / tests / phpunit / suites / UploadFromUrlTestSuite.php
index 3f5b1fe..843aaf9 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 
-require_once( dirname( dirname( __FILE__ ) ) . '/includes/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,57 +15,78 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
                return true;
        }
 
-       function setUp() {
-               global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
-                                 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
-                                 $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
-                                 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
-                                 $wgThumbnailScriptPath, $wgScriptPath,
-                                 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
-
-               $wgScript = '/index.php';
-               $wgScriptPath = '/';
-               $wgArticlePath = '/wiki/$1';
-               $wgStyleSheetPath = '/skins';
-               $wgStylePath = '/skins';
-               $wgThumbnailScriptPath = false;
-               $wgLocalFileRepo = array(
-                       'class' => 'LocalRepo',
-                       'name' => 'local',
-                       'directory' => wfTempDir() . '/test-repo',
-                       'url' => 'http://example.com/images',
-                       'deletedDir' => wfTempDir() . '/test-repo/delete',
-                       'hashLevels' => 2,
+       protected function setUp() {
+               global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
+                         $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'         => 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;
 
 
                $wgEnableParserCache = false;
-               $wgDeferredUpdateList = array();
-               $wgMemc = &wfGetMainCache();
-               $messageMemc = &wfGetMessageCacheStorage();
-               $parserMemc = &wfGetParserCacheStorage();
+               DeferredUpdates::clearPendingUpdates();
+               $wgMemc = wfGetMainCache();
+               $messageMemc = wfGetMessageCacheStorage();
+               $parserMemc = wfGetParserCacheStorage();
 
                // $wgContLang = new StubContLang;
                $wgUser = new User;
-               $wgLang = new StubUserLang;
-               $wgOut = new StubObject( 'wgOut', 'OutputPage' );
+               $context = new RequestContext;
+               $wgLang = $context->getLanguage();
+               $wgOut = $context->getOutput();
                $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
-               $wgRequest = new WebRequest;
+               $wgRequest = $context->getRequest();
 
-               $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
-                                                                                 array( $messageMemc, $wgUseDatabaseMessages,
-                                                                                                $wgMsgCacheExpiry ) );
                if ( $wgStyleDirectory === false ) {
                        $wgStyleDirectory   = "$IP/skins";
                }
 
+               RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
        }
 
-       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 );
        }
 
@@ -162,10 +185,10 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
                        return $dir;
                }
 
-               wfMkdirParents( $dir . '/3/3a' );
+               wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
                copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
 
-               wfMkdirParents( $dir . '/0/09' );
+               wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
                copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 
                return $dir;
@@ -173,7 +196,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
 
        public static function suite() {
                // Hack to invoke the autoloader required to get phpunit to recognize
-               // the UploadFromUrlTest class 
+               // the UploadFromUrlTest class
                class_exists( 'UploadFromUrlTest' );
                $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
                return $suite;