3 require_once( dirname( dirname( __FILE__
) ) . '/includes/upload/UploadFromUrlTest.php' );
5 class UploadFromUrlTestSuite
extends PHPUnit_Framework_TestSuite
{
6 public static function addTables( &$tables ) {
7 $tables[] = 'user_properties';
8 $tables[] = 'filearchive';
10 $tables[] = 'updatelog';
11 $tables[] = 'iwlinks';
17 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
18 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
19 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
20 $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
21 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
23 $wgScript = '/index.php';
25 $wgArticlePath = '/wiki/$1';
26 $wgStyleSheetPath = '/skins';
27 $wgStylePath = '/skins';
28 $wgThumbnailScriptPath = false;
29 $backend = new FSFileBackend( array(
30 'name' => 'local-backend',
31 'lockManager' => 'fsLockManager',
32 'containerPaths' => array(
33 'images-public' => wfTempDir() . '/test-repo/public',
34 'images-thumb' => wfTempDir() . '/test-repo/thumb',
35 'images-temp' => wfTempDir() . '/test-repo/temp',
36 'images-deleted' => wfTempDir() . '/test-repo/delete',
39 $wgLocalFileRepo = array(
40 'class' => 'LocalRepo',
42 'url' => 'http://example.com/images',
44 'transformVia404' => false,
47 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
48 $wgNamespaceAliases['Image'] = NS_FILE
;
49 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
52 $wgEnableParserCache = false;
53 DeferredUpdates
::clearPendingUpdates();
54 $wgMemc = wfGetMainCache();
55 $messageMemc = wfGetMessageCacheStorage();
56 $parserMemc = wfGetParserCacheStorage();
58 // $wgContLang = new StubContLang;
60 $context = new RequestContext
;
61 $wgLang = $context->getLanguage();
62 $wgOut = $context->getOutput();
63 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
64 $wgRequest = $context->getRequest();
66 if ( $wgStyleDirectory === false ) {
67 $wgStyleDirectory = "$IP/skins";
72 public function tearDown() {
73 $this->teardownUploadDir( $this->uploadDir
);
80 * Remove the dummy uploads directory
82 private function teardownUploadDir( $dir ) {
83 if ( $this->keepUploads
) {
87 // delete the files first, then the dirs.
90 "$dir/3/3a/Foobar.jpg",
91 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
92 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
93 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
94 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
106 "$dir/thumb/3/3a/Foobar.jpg",
120 * Delete the specified files, if they exist.
122 * @param $files Array: full paths to files to delete.
124 private static function deleteFiles( $files ) {
125 foreach ( $files as $file ) {
126 if ( file_exists( $file ) ) {
133 * Delete the specified directories, if they exist. Must be empty.
135 * @param $dirs Array: full paths to directories to delete.
137 private static function deleteDirs( $dirs ) {
138 foreach ( $dirs as $dir ) {
139 if ( is_dir( $dir ) ) {
146 * Create a dummy uploads directory which will contain a couple
147 * of files in order to pass existence tests.
149 * @return String: the directory
151 private function setupUploadDir() {
154 if ( $this->keepUploads
) {
155 $dir = wfTempDir() . '/mwParser-images';
157 if ( is_dir( $dir ) ) {
161 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
164 wfDebug( "Creating upload directory $dir\n" );
166 if ( file_exists( $dir ) ) {
167 wfDebug( "Already exists!\n" );
171 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
172 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
174 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
175 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
180 public static function suite() {
181 // Hack to invoke the autoloader required to get phpunit to recognize
182 // the UploadFromUrlTest class
183 class_exists( 'UploadFromUrlTest' );
184 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );