MediaWiki
REL1_21
|
00001 <?php 00002 00003 require_once( dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php' ); 00004 00005 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { 00006 public $savedGlobals = array(); 00007 00008 public static function addTables( &$tables ) { 00009 $tables[] = 'user_properties'; 00010 $tables[] = 'filearchive'; 00011 $tables[] = 'logging'; 00012 $tables[] = 'updatelog'; 00013 $tables[] = 'iwlinks'; 00014 00015 return true; 00016 } 00017 00018 protected function setUp() { 00019 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, 00020 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, 00021 $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc; 00022 00023 $tmpGlobals = array(); 00024 00025 $tmpGlobals['wgScript'] = '/index.php'; 00026 $tmpGlobals['wgScriptPath'] = '/'; 00027 $tmpGlobals['wgArticlePath'] = '/wiki/$1'; 00028 $tmpGlobals['wgStyleSheetPath'] = '/skins'; 00029 $tmpGlobals['wgStylePath'] = '/skins'; 00030 $tmpGlobals['wgThumbnailScriptPath'] = false; 00031 $tmpGlobals['wgLocalFileRepo'] = array( 00032 'class' => 'LocalRepo', 00033 'name' => 'local', 00034 'url' => 'http://example.com/images', 00035 'hashLevels' => 2, 00036 'transformVia404' => false, 00037 'backend' => new FSFileBackend( array( 00038 'name' => 'local-backend', 00039 'lockManager' => 'fsLockManager', 00040 'containerPaths' => array( 00041 'local-public' => wfTempDir() . '/test-repo/public', 00042 'local-thumb' => wfTempDir() . '/test-repo/thumb', 00043 'local-temp' => wfTempDir() . '/test-repo/temp', 00044 'local-deleted' => wfTempDir() . '/test-repo/delete', 00045 ) 00046 ) ), 00047 ); 00048 foreach ( $tmpGlobals as $var => $val ) { 00049 if ( array_key_exists( $var, $GLOBALS ) ) { 00050 $this->savedGlobals[$var] = $GLOBALS[$var]; 00051 } 00052 $GLOBALS[$var] = $val; 00053 } 00054 00055 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; 00056 $wgNamespaceAliases['Image'] = NS_FILE; 00057 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; 00058 00059 00060 $wgEnableParserCache = false; 00061 DeferredUpdates::clearPendingUpdates(); 00062 $wgMemc = wfGetMainCache(); 00063 $messageMemc = wfGetMessageCacheStorage(); 00064 $parserMemc = wfGetParserCacheStorage(); 00065 00066 // $wgContLang = new StubContLang; 00067 $wgUser = new User; 00068 $context = new RequestContext; 00069 $wgLang = $context->getLanguage(); 00070 $wgOut = $context->getOutput(); 00071 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); 00072 $wgRequest = $context->getRequest(); 00073 00074 if ( $wgStyleDirectory === false ) { 00075 $wgStyleDirectory = "$IP/skins"; 00076 } 00077 00078 RepoGroup::destroySingleton(); 00079 FileBackendGroup::destroySingleton(); 00080 } 00081 00082 protected function tearDown() { 00083 foreach ( $this->savedGlobals as $var => $val ) { 00084 $GLOBALS[$var] = $val; 00085 } 00086 // Restore backends 00087 RepoGroup::destroySingleton(); 00088 FileBackendGroup::destroySingleton(); 00089 00090 $this->teardownUploadDir( $this->uploadDir ); 00091 00092 parent::tearDown(); 00093 } 00094 00095 private $uploadDir; 00096 private $keepUploads; 00097 00101 private function teardownUploadDir( $dir ) { 00102 if ( $this->keepUploads ) { 00103 return; 00104 } 00105 00106 // delete the files first, then the dirs. 00107 self::deleteFiles( 00108 array( 00109 "$dir/3/3a/Foobar.jpg", 00110 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", 00111 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", 00112 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg", 00113 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", 00114 00115 "$dir/0/09/Bad.jpg", 00116 ) 00117 ); 00118 00119 self::deleteDirs( 00120 array( 00121 "$dir/3/3a", 00122 "$dir/3", 00123 "$dir/thumb/6/65", 00124 "$dir/thumb/6", 00125 "$dir/thumb/3/3a/Foobar.jpg", 00126 "$dir/thumb/3/3a", 00127 "$dir/thumb/3", 00128 00129 "$dir/0/09/", 00130 "$dir/0/", 00131 00132 "$dir/thumb", 00133 "$dir", 00134 ) 00135 ); 00136 } 00137 00143 private static function deleteFiles( $files ) { 00144 foreach ( $files as $file ) { 00145 if ( file_exists( $file ) ) { 00146 unlink( $file ); 00147 } 00148 } 00149 } 00150 00156 private static function deleteDirs( $dirs ) { 00157 foreach ( $dirs as $dir ) { 00158 if ( is_dir( $dir ) ) { 00159 rmdir( $dir ); 00160 } 00161 } 00162 } 00163 00170 private function setupUploadDir() { 00171 global $IP; 00172 00173 if ( $this->keepUploads ) { 00174 $dir = wfTempDir() . '/mwParser-images'; 00175 00176 if ( is_dir( $dir ) ) { 00177 return $dir; 00178 } 00179 } else { 00180 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; 00181 } 00182 00183 wfDebug( "Creating upload directory $dir\n" ); 00184 00185 if ( file_exists( $dir ) ) { 00186 wfDebug( "Already exists!\n" ); 00187 return $dir; 00188 } 00189 00190 wfMkdirParents( $dir . '/3/3a', null, __METHOD__ ); 00191 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); 00192 00193 wfMkdirParents( $dir . '/0/09', null, __METHOD__ ); 00194 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); 00195 00196 return $dir; 00197 } 00198 00199 public static function suite() { 00200 // Hack to invoke the autoloader required to get phpunit to recognize 00201 // the UploadFromUrlTest class 00202 class_exists( 'UploadFromUrlTest' ); 00203 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' ); 00204 return $suite; 00205 } 00206 }