3 require_once( 'UploadFromUrlTest.php' );
5 class UploadFromUrlTestSuite
extends PHPUnit_Framework_TestSuite
7 public static function addTables( &$tables ) {
8 $tables[] = 'user_properties';
9 $tables[] = 'filearchive';
10 $tables[] = 'logging';
11 $tables[] = 'updatelog';
12 $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 $wgNamespacesWithSubpages, $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
;
51 $wgUser = new StubUser
;
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, wfWikiID() ) );
60 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
64 public function tearDown() {
65 $this->teardownUploadDir( $this->uploadDir
);
71 * Remove the dummy uploads directory
73 private function teardownUploadDir( $dir ) {
74 if ( $this->keepUploads
) {
78 // delete the files first, then the dirs.
81 "$dir/3/3a/Foobar.jpg",
82 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
83 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
84 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
85 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
97 "$dir/thumb/3/3a/Foobar.jpg",
112 * Delete the specified files, if they exist.
113 * @param array $files full paths to files to delete.
115 private static function deleteFiles( $files ) {
116 foreach ( $files as $file ) {
117 if ( file_exists( $file ) ) {
123 * Delete the specified directories, if they exist. Must be empty.
124 * @param array $dirs full paths to directories to delete.
126 private static function deleteDirs( $dirs ) {
127 foreach ( $dirs as $dir ) {
128 if ( is_dir( $dir ) ) {
135 * Create a dummy uploads directory which will contain a couple
136 * of files in order to pass existence tests.
137 * @return string The directory
139 private function setupUploadDir() {
141 if ( $this->keepUploads
) {
142 $dir = wfTempDir() . '/mwParser-images';
143 if ( is_dir( $dir ) ) {
147 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
150 wfDebug( "Creating upload directory $dir\n" );
151 if ( file_exists( $dir ) ) {
152 wfDebug( "Already exists!\n" );
155 wfMkdirParents( $dir . '/3/3a' );
156 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
158 wfMkdirParents( $dir . '/0/09' );
159 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
163 public static function suite()
165 return new UploadFromUrlTestSuite( 'UploadFromUrlTest' );