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,
20 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
21 $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
23 $tmpGlobals = array();
25 $tmpGlobals['wgScript'] = '/index.php';
26 $tmpGlobals['wgScriptPath'] = '/';
27 $tmpGlobals['wgArticlePath'] = '/wiki/$1';
28 $tmpGlobals['wgStyleSheetPath'] = '/skins';
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 'lockManager' => 'fsLockManager',
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
;
60 $wgEnableParserCache = false;
61 DeferredUpdates
::clearPendingUpdates();
62 $wgMemc = wfGetMainCache();
63 $messageMemc = wfGetMessageCacheStorage();
64 $parserMemc = wfGetParserCacheStorage();
66 // $wgContLang = new StubContLang;
68 $context = new RequestContext
;
69 $wgLang = $context->getLanguage();
70 $wgOut = $context->getOutput();
71 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
72 $wgRequest = $context->getRequest();
74 if ( $wgStyleDirectory === false ) {
75 $wgStyleDirectory = "$IP/skins";
78 RepoGroup
::destroySingleton();
79 FileBackendGroup
::destroySingleton();
82 protected function tearDown() {
83 foreach ( $this->savedGlobals
as $var => $val ) {
84 $GLOBALS[$var] = $val;
87 RepoGroup
::destroySingleton();
88 FileBackendGroup
::destroySingleton();
90 $this->teardownUploadDir( $this->uploadDir
);
99 * Remove the dummy uploads directory
101 private function teardownUploadDir( $dir ) {
102 if ( $this->keepUploads
) {
106 // delete the files first, then the dirs.
109 "$dir/3/3a/Foobar.jpg",
110 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
111 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
112 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
113 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
125 "$dir/thumb/3/3a/Foobar.jpg",
139 * Delete the specified files, if they exist.
141 * @param $files Array: full paths to files to delete.
143 private static function deleteFiles( $files ) {
144 foreach ( $files as $file ) {
145 if ( file_exists( $file ) ) {
152 * Delete the specified directories, if they exist. Must be empty.
154 * @param $dirs Array: full paths to directories to delete.
156 private static function deleteDirs( $dirs ) {
157 foreach ( $dirs as $dir ) {
158 if ( is_dir( $dir ) ) {
165 * Create a dummy uploads directory which will contain a couple
166 * of files in order to pass existence tests.
168 * @return String: the directory
170 private function setupUploadDir() {
173 if ( $this->keepUploads
) {
174 $dir = wfTempDir() . '/mwParser-images';
176 if ( is_dir( $dir ) ) {
180 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
183 wfDebug( "Creating upload directory $dir\n" );
185 if ( file_exists( $dir ) ) {
186 wfDebug( "Already exists!\n" );
190 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
191 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
193 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
194 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
199 public static function suite() {
200 // Hack to invoke the autoloader required to get phpunit to recognize
201 // the UploadFromUrlTest class
202 class_exists( 'UploadFromUrlTest' );
203 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );