3 require_once( dirname( __DIR__
) . '/includes/upload/UploadFromUrlTest.php' );
5 class UploadFromUrlTestSuite
extends PHPUnit_Framework_TestSuite
{
6 public $savedGlobals = array();
8 public static function addTables( &$tables ) {
9 $tables[] = 'user_properties';
10 $tables[] = 'filearchive';
11 $tables[] = 'logging';
12 $tables[] = 'updatelog';
13 $tables[] = 'iwlinks';
18 protected function setUp() {
19 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
20 $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
21 $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection,
24 $tmpGlobals = array();
26 $tmpGlobals['wgScript'] = '/index.php';
27 $tmpGlobals['wgScriptPath'] = '/';
28 $tmpGlobals['wgArticlePath'] = '/wiki/$1';
29 $tmpGlobals['wgStyleSheetPath'] = '/skins';
30 $tmpGlobals['wgStylePath'] = '/skins';
31 $tmpGlobals['wgThumbnailScriptPath'] = false;
32 $tmpGlobals['wgLocalFileRepo'] = array(
33 'class' => 'LocalRepo',
35 'url' => 'http://example.com/images',
37 'transformVia404' => false,
38 'backend' => new FSFileBackend( array(
39 'name' => 'local-backend',
40 'lockManager' => 'fsLockManager',
41 'containerPaths' => array(
42 'local-public' => wfTempDir() . '/test-repo/public',
43 'local-thumb' => wfTempDir() . '/test-repo/thumb',
44 'local-temp' => wfTempDir() . '/test-repo/temp',
45 'local-deleted' => wfTempDir() . '/test-repo/delete',
49 foreach ( $tmpGlobals as $var => $val ) {
50 if ( array_key_exists( $var, $GLOBALS ) ) {
51 $this->savedGlobals
[$var] = $GLOBALS[$var];
53 $GLOBALS[$var] = $val;
56 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
57 $wgNamespaceAliases['Image'] = NS_FILE
;
58 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
61 $wgEnableParserCache = false;
62 DeferredUpdates
::clearPendingUpdates();
63 $wgMemc = wfGetMainCache();
64 $messageMemc = wfGetMessageCacheStorage();
65 $parserMemc = wfGetParserCacheStorage();
67 // $wgContLang = new StubContLang;
69 $context = new RequestContext
;
70 $wgLang = $context->getLanguage();
71 $wgOut = $context->getOutput();
72 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
73 $wgRequest = $context->getRequest();
75 if ( $wgStyleDirectory === false ) {
76 $wgStyleDirectory = "$IP/skins";
79 RepoGroup
::destroySingleton();
80 FileBackendGroup
::destroySingleton();
83 protected function tearDown() {
84 foreach ( $this->savedGlobals
as $var => $val ) {
85 $GLOBALS[$var] = $val;
88 RepoGroup
::destroySingleton();
89 FileBackendGroup
::destroySingleton();
91 $this->teardownUploadDir( $this->uploadDir
);
100 * Remove the dummy uploads directory
102 private function teardownUploadDir( $dir ) {
103 if ( $this->keepUploads
) {
107 // delete the files first, then the dirs.
110 "$dir/3/3a/Foobar.jpg",
111 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
112 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
113 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
114 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
126 "$dir/thumb/3/3a/Foobar.jpg",
140 * Delete the specified files, if they exist.
142 * @param $files Array: full paths to files to delete.
144 private static function deleteFiles( $files ) {
145 foreach ( $files as $file ) {
146 if ( file_exists( $file ) ) {
153 * Delete the specified directories, if they exist. Must be empty.
155 * @param $dirs Array: full paths to directories to delete.
157 private static function deleteDirs( $dirs ) {
158 foreach ( $dirs as $dir ) {
159 if ( is_dir( $dir ) ) {
166 * Create a dummy uploads directory which will contain a couple
167 * of files in order to pass existence tests.
169 * @return String: the directory
171 private function setupUploadDir() {
174 if ( $this->keepUploads
) {
175 $dir = wfTempDir() . '/mwParser-images';
177 if ( is_dir( $dir ) ) {
181 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
184 wfDebug( "Creating upload directory $dir\n" );
186 if ( file_exists( $dir ) ) {
187 wfDebug( "Already exists!\n" );
191 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
192 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
194 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
195 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
200 public static function suite() {
201 // Hack to invoke the autoloader required to get phpunit to recognize
202 // the UploadFromUrlTest class
203 class_exists( 'UploadFromUrlTest' );
204 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );