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['wgStylePath'] = '/skins';
30 $tmpGlobals['wgThumbnailScriptPath'] = false;
31 $tmpGlobals['wgLocalFileRepo'] = array(
32 'class' => 'LocalRepo',
34 'url' => 'http://example.com/images',
36 'transformVia404' => false,
37 'backend' => new FSFileBackend( array(
38 'name' => 'local-backend',
39 'wikiId' => wfWikiId(),
40 'containerPaths' => array(
41 'local-public' => wfTempDir() . '/test-repo/public',
42 'local-thumb' => wfTempDir() . '/test-repo/thumb',
43 'local-temp' => wfTempDir() . '/test-repo/temp',
44 'local-deleted' => wfTempDir() . '/test-repo/delete',
48 foreach ( $tmpGlobals as $var => $val ) {
49 if ( array_key_exists( $var, $GLOBALS ) ) {
50 $this->savedGlobals
[$var] = $GLOBALS[$var];
52 $GLOBALS[$var] = $val;
55 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
56 $wgNamespaceAliases['Image'] = NS_FILE
;
57 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
59 $wgEnableParserCache = false;
60 DeferredUpdates
::clearPendingUpdates();
61 $wgMemc = wfGetMainCache();
62 $messageMemc = wfGetMessageCacheStorage();
63 $parserMemc = wfGetParserCacheStorage();
66 $context = new RequestContext
;
67 $wgLang = $context->getLanguage();
68 $wgOut = $context->getOutput();
69 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
70 $wgRequest = $context->getRequest();
72 if ( $wgStyleDirectory === false ) {
73 $wgStyleDirectory = "$IP/skins";
76 RepoGroup
::destroySingleton();
77 FileBackendGroup
::destroySingleton();
80 protected function tearDown() {
81 foreach ( $this->savedGlobals
as $var => $val ) {
82 $GLOBALS[$var] = $val;
85 RepoGroup
::destroySingleton();
86 FileBackendGroup
::destroySingleton();
88 $this->teardownUploadDir( $this->uploadDir
);
97 * Remove the dummy uploads directory
99 private function teardownUploadDir( $dir ) {
100 if ( $this->keepUploads
) {
104 // delete the files first, then the dirs.
107 "$dir/3/3a/Foobar.jpg",
108 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
109 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
110 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
111 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
123 "$dir/thumb/3/3a/Foobar.jpg",
137 * Delete the specified files, if they exist.
139 * @param array $files Full paths to files to delete.
141 private static function deleteFiles( $files ) {
142 foreach ( $files as $file ) {
143 if ( file_exists( $file ) ) {
150 * Delete the specified directories, if they exist. Must be empty.
152 * @param array $dirs Full paths to directories to delete.
154 private static function deleteDirs( $dirs ) {
155 foreach ( $dirs as $dir ) {
156 if ( is_dir( $dir ) ) {
163 * Create a dummy uploads directory which will contain a couple
164 * of files in order to pass existence tests.
166 * @return string The directory
168 private function setupUploadDir() {
171 if ( $this->keepUploads
) {
172 $dir = wfTempDir() . '/mwParser-images';
174 if ( is_dir( $dir ) ) {
178 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
181 wfDebug( "Creating upload directory $dir\n" );
183 if ( file_exists( $dir ) ) {
184 wfDebug( "Already exists!\n" );
189 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
190 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
192 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
193 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/0/09/Bad.jpg" );
198 public static function suite() {
199 // Hack to invoke the autoloader required to get phpunit to recognize
200 // the UploadFromUrlTest class
201 class_exists( 'UploadFromUrlTest' );
202 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );