3 class UploadFromUrlTestSuite
extends PHPUnit_Framework_TestSuite
5 public static function addTables( &$tables ) {
6 $tables[] = 'user_properties';
7 $tables[] = 'filearchive';
9 $tables[] = 'updatelog';
10 $tables[] = 'iwlinks';
15 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
16 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
17 $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
18 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
19 $wgThumbnailScriptPath, $wgScriptPath,
20 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
22 $wgScript = '/index.php';
24 $wgArticlePath = '/wiki/$1';
25 $wgStyleSheetPath = '/skins';
26 $wgStylePath = '/skins';
27 $wgThumbnailScriptPath = false;
28 $wgLocalFileRepo = array(
29 'class' => 'LocalRepo',
31 'directory' => wfTempDir().'/test-repo',
32 'url' => 'http://example.com/images',
33 'deletedDir' => wfTempDir().'/test-repo/delete',
35 'transformVia404' => false,
37 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
38 $wgNamespaceAliases['Image'] = NS_FILE
;
39 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
42 $wgEnableParserCache = false;
43 $wgDeferredUpdateList = array();
44 $wgMemc =& wfGetMainCache();
45 $messageMemc =& wfGetMessageCacheStorage();
46 $parserMemc =& wfGetParserCacheStorage();
48 //$wgContLang = new StubContLang;
49 $wgUser = new StubUser
;
50 $wgLang = new StubUserLang
;
51 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
52 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
53 $wgRequest = new WebRequest
;
55 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
56 array( $messageMemc, $wgUseDatabaseMessages,
57 $wgMsgCacheExpiry ) );
58 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
62 public function tearDown() {
63 $this->teardownUploadDir( $this->uploadDir
);
70 * Remove the dummy uploads directory
72 private function teardownUploadDir( $dir ) {
73 if ( $this->keepUploads
) {
77 // delete the files first, then the dirs.
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",
96 "$dir/thumb/3/3a/Foobar.jpg",
111 * Delete the specified files, if they exist.
113 * @param $files Array: full paths to files to delete.
115 private static function deleteFiles( $files ) {
116 foreach ( $files as $file ) {
117 if ( file_exists( $file ) ) {
124 * Delete the specified directories, if they exist. Must be empty.
126 * @param $dirs Array: full paths to directories to delete.
128 private static function deleteDirs( $dirs ) {
129 foreach ( $dirs as $dir ) {
130 if ( is_dir( $dir ) ) {
137 * Create a dummy uploads directory which will contain a couple
138 * of files in order to pass existence tests.
140 * @return String: the directory
142 private function setupUploadDir() {
144 if ( $this->keepUploads
) {
145 $dir = wfTempDir() . '/mwParser-images';
146 if ( is_dir( $dir ) ) {
150 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
153 wfDebug( "Creating upload directory $dir\n" );
154 if ( file_exists( $dir ) ) {
155 wfDebug( "Already exists!\n" );
158 wfMkdirParents( $dir . '/3/3a' );
159 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
161 wfMkdirParents( $dir . '/0/09' );
162 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
166 public static function suite()
168 return new UploadFromUrlTestSuite( 'UploadFromUrlTest' );