3 class UploadFromUrlTestSuite
extends PHPUnit_Framework_TestSuite
{
4 public static function addTables( &$tables ) {
5 $tables[] = 'user_properties';
6 $tables[] = 'filearchive';
8 $tables[] = 'updatelog';
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;
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 ) {
59 $wgStyleDirectory = "$IP/skins";
64 public function tearDown() {
65 $this->teardownUploadDir( $this->uploadDir
);
72 * Remove the dummy uploads directory
74 private function teardownUploadDir( $dir ) {
75 if ( $this->keepUploads
) {
79 // delete the files first, then the dirs.
82 "$dir/3/3a/Foobar.jpg",
83 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
84 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
85 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
86 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
98 "$dir/thumb/3/3a/Foobar.jpg",
112 * Delete the specified files, if they exist.
114 * @param $files Array: full paths to files to delete.
116 private static function deleteFiles( $files ) {
117 foreach ( $files as $file ) {
118 if ( file_exists( $file ) ) {
125 * Delete the specified directories, if they exist. Must be empty.
127 * @param $dirs Array: full paths to directories to delete.
129 private static function deleteDirs( $dirs ) {
130 foreach ( $dirs as $dir ) {
131 if ( is_dir( $dir ) ) {
138 * Create a dummy uploads directory which will contain a couple
139 * of files in order to pass existence tests.
141 * @return String: the directory
143 private function setupUploadDir() {
146 if ( $this->keepUploads
) {
147 $dir = wfTempDir() . '/mwParser-images';
149 if ( is_dir( $dir ) ) {
153 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
156 wfDebug( "Creating upload directory $dir\n" );
158 if ( file_exists( $dir ) ) {
159 wfDebug( "Already exists!\n" );
163 wfMkdirParents( $dir . '/3/3a' );
164 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
166 wfMkdirParents( $dir . '/0/09' );
167 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
172 public static function suite() {
173 // Hack to invoke the autoloader required to get phpunit to recognize
174 // the UploadFromUrlTest class
175 class_exists( 'UploadFromUrlTest' );
176 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );