Fixed spacing in actions/cache/filebackend/filerepo/job folder
[mediawiki.git] / tests / phpunit / suites / UploadFromUrlTestSuite.php
blob3200e0bd5a7486b0974603ffc257fbcacd2d75bc
1 <?php
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';
15 return true;
18 protected function setUp() {
19 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
20 $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
21 $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection,
22 $parserMemc;
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',
34 'name' => 'local',
35 'url' => 'http://example.com/images',
36 'hashLevels' => 2,
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',
47 ) ),
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;
68 $wgUser = new User;
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;
87 // Restore backends
88 RepoGroup::destroySingleton();
89 FileBackendGroup::destroySingleton();
91 $this->teardownUploadDir( $this->uploadDir );
93 parent::tearDown();
96 private $uploadDir;
97 private $keepUploads;
99 /**
100 * Remove the dummy uploads directory
102 private function teardownUploadDir( $dir ) {
103 if ( $this->keepUploads ) {
104 return;
107 // delete the files first, then the dirs.
108 self::deleteFiles(
109 array(
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",
116 "$dir/0/09/Bad.jpg",
120 self::deleteDirs(
121 array(
122 "$dir/3/3a",
123 "$dir/3",
124 "$dir/thumb/6/65",
125 "$dir/thumb/6",
126 "$dir/thumb/3/3a/Foobar.jpg",
127 "$dir/thumb/3/3a",
128 "$dir/thumb/3",
130 "$dir/0/09/",
131 "$dir/0/",
133 "$dir/thumb",
134 "$dir",
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 ) ) {
147 unlink( $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 ) ) {
160 rmdir( $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() {
172 global $IP;
174 if ( $this->keepUploads ) {
175 $dir = wfTempDir() . '/mwParser-images';
177 if ( is_dir( $dir ) ) {
178 return $dir;
180 } else {
181 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
184 wfDebug( "Creating upload directory $dir\n" );
186 if ( file_exists( $dir ) ) {
187 wfDebug( "Already exists!\n" );
188 return $dir;
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" );
197 return $dir;
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' );
205 return $suite;