* Replaced $wgMessageCache by MessageCache::singleton(); since we only use one instan...
[lhc/web/wiklou.git] / tests / phpunit / suites / UploadFromUrlTestSuite.php
1 <?php
2
3 require_once( dirname( dirname( __FILE__ ) ) . '/includes/UploadFromUrlTest.php' );
4
5 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
6 public static function addTables( &$tables ) {
7 $tables[] = 'user_properties';
8 $tables[] = 'filearchive';
9 $tables[] = 'logging';
10 $tables[] = 'updatelog';
11 $tables[] = 'iwlinks';
12
13 return true;
14 }
15
16 function setUp() {
17 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
18 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
19 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
20 $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
21 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
22
23 $wgScript = '/index.php';
24 $wgScriptPath = '/';
25 $wgArticlePath = '/wiki/$1';
26 $wgStyleSheetPath = '/skins';
27 $wgStylePath = '/skins';
28 $wgThumbnailScriptPath = false;
29 $wgLocalFileRepo = array(
30 'class' => 'LocalRepo',
31 'name' => 'local',
32 'directory' => wfTempDir() . '/test-repo',
33 'url' => 'http://example.com/images',
34 'deletedDir' => wfTempDir() . '/test-repo/delete',
35 'hashLevels' => 2,
36 'transformVia404' => false,
37 );
38 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
39 $wgNamespaceAliases['Image'] = NS_FILE;
40 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
41
42
43 $wgEnableParserCache = false;
44 $wgDeferredUpdateList = array();
45 $wgMemc = &wfGetMainCache();
46 $messageMemc = &wfGetMessageCacheStorage();
47 $parserMemc = &wfGetParserCacheStorage();
48
49 // $wgContLang = new StubContLang;
50 $wgUser = new User;
51 $wgLang = new StubUserLang;
52 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
53 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
54 $wgRequest = new WebRequest;
55
56 if ( $wgStyleDirectory === false ) {
57 $wgStyleDirectory = "$IP/skins";
58 }
59
60 }
61
62 public function tearDown() {
63 $this->teardownUploadDir( $this->uploadDir );
64 }
65
66 private $uploadDir;
67 private $keepUploads;
68
69 /**
70 * Remove the dummy uploads directory
71 */
72 private function teardownUploadDir( $dir ) {
73 if ( $this->keepUploads ) {
74 return;
75 }
76
77 // delete the files first, then the dirs.
78 self::deleteFiles(
79 array (
80 "$dir/3/3a/Foobar.jpg",
81 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
82 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
83 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
84 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
85
86 "$dir/0/09/Bad.jpg",
87 )
88 );
89
90 self::deleteDirs(
91 array (
92 "$dir/3/3a",
93 "$dir/3",
94 "$dir/thumb/6/65",
95 "$dir/thumb/6",
96 "$dir/thumb/3/3a/Foobar.jpg",
97 "$dir/thumb/3/3a",
98 "$dir/thumb/3",
99
100 "$dir/0/09/",
101 "$dir/0/",
102
103 "$dir/thumb",
104 "$dir",
105 )
106 );
107 }
108
109 /**
110 * Delete the specified files, if they exist.
111 *
112 * @param $files Array: full paths to files to delete.
113 */
114 private static function deleteFiles( $files ) {
115 foreach ( $files as $file ) {
116 if ( file_exists( $file ) ) {
117 unlink( $file );
118 }
119 }
120 }
121
122 /**
123 * Delete the specified directories, if they exist. Must be empty.
124 *
125 * @param $dirs Array: full paths to directories to delete.
126 */
127 private static function deleteDirs( $dirs ) {
128 foreach ( $dirs as $dir ) {
129 if ( is_dir( $dir ) ) {
130 rmdir( $dir );
131 }
132 }
133 }
134
135 /**
136 * Create a dummy uploads directory which will contain a couple
137 * of files in order to pass existence tests.
138 *
139 * @return String: the directory
140 */
141 private function setupUploadDir() {
142 global $IP;
143
144 if ( $this->keepUploads ) {
145 $dir = wfTempDir() . '/mwParser-images';
146
147 if ( is_dir( $dir ) ) {
148 return $dir;
149 }
150 } else {
151 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
152 }
153
154 wfDebug( "Creating upload directory $dir\n" );
155
156 if ( file_exists( $dir ) ) {
157 wfDebug( "Already exists!\n" );
158 return $dir;
159 }
160
161 wfMkdirParents( $dir . '/3/3a' );
162 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
163
164 wfMkdirParents( $dir . '/0/09' );
165 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
166
167 return $dir;
168 }
169
170 public static function suite() {
171 // Hack to invoke the autoloader required to get phpunit to recognize
172 // the UploadFromUrlTest class
173 class_exists( 'UploadFromUrlTest' );
174 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
175 return $suite;
176 }
177 }