3 require_once( dirname( dirname( __FILE__
) ) . '/includes/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, $wgDeferredUpdateList,
18 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
19 $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
20 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
21 $wgThumbnailScriptPath, $wgScriptPath,
22 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
24 $wgScript = '/index.php';
26 $wgArticlePath = '/wiki/$1';
27 $wgStyleSheetPath = '/skins';
28 $wgStylePath = '/skins';
29 $wgThumbnailScriptPath = false;
30 $wgLocalFileRepo = array(
31 'class' => 'LocalRepo',
33 'directory' => wfTempDir() . '/test-repo',
34 'url' => 'http://example.com/images',
35 'deletedDir' => wfTempDir() . '/test-repo/delete',
37 'transformVia404' => false,
39 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
40 $wgNamespaceAliases['Image'] = NS_FILE
;
41 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
44 $wgEnableParserCache = false;
45 $wgDeferredUpdateList = array();
46 $wgMemc = &wfGetMainCache();
47 $messageMemc = &wfGetMessageCacheStorage();
48 $parserMemc = &wfGetParserCacheStorage();
50 // $wgContLang = new StubContLang;
52 $wgLang = new StubUserLang
;
53 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
54 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
55 $wgRequest = new WebRequest
;
57 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
58 array( $messageMemc, $wgUseDatabaseMessages,
59 $wgMsgCacheExpiry ) );
60 if ( $wgStyleDirectory === false ) {
61 $wgStyleDirectory = "$IP/skins";
66 public function tearDown() {
67 $this->teardownUploadDir( $this->uploadDir
);
74 * Remove the dummy uploads directory
76 private function teardownUploadDir( $dir ) {
77 if ( $this->keepUploads
) {
81 // delete the files first, then the dirs.
84 "$dir/3/3a/Foobar.jpg",
85 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
86 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
87 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
88 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
100 "$dir/thumb/3/3a/Foobar.jpg",
114 * Delete the specified files, if they exist.
116 * @param $files Array: full paths to files to delete.
118 private static function deleteFiles( $files ) {
119 foreach ( $files as $file ) {
120 if ( file_exists( $file ) ) {
127 * Delete the specified directories, if they exist. Must be empty.
129 * @param $dirs Array: full paths to directories to delete.
131 private static function deleteDirs( $dirs ) {
132 foreach ( $dirs as $dir ) {
133 if ( is_dir( $dir ) ) {
140 * Create a dummy uploads directory which will contain a couple
141 * of files in order to pass existence tests.
143 * @return String: the directory
145 private function setupUploadDir() {
148 if ( $this->keepUploads
) {
149 $dir = wfTempDir() . '/mwParser-images';
151 if ( is_dir( $dir ) ) {
155 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
158 wfDebug( "Creating upload directory $dir\n" );
160 if ( file_exists( $dir ) ) {
161 wfDebug( "Already exists!\n" );
165 wfMkdirParents( $dir . '/3/3a' );
166 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
168 wfMkdirParents( $dir . '/0/09' );
169 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
174 public static function suite() {
175 // Hack to invoke the autoloader required to get phpunit to recognize
176 // the UploadFromUrlTest class
177 class_exists( 'UploadFromUrlTest' );
178 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );