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 $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 $wgLocalFileRepo = array(
30 'class' => 'LocalRepo',
32 'directory' => wfTempDir() . '/test-repo',
33 'url' => 'http://example.com/images',
34 'deletedDir' => wfTempDir() . '/test-repo/delete',
36 'transformVia404' => false,
38 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
39 $wgNamespaceAliases['Image'] = NS_FILE
;
40 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
43 $wgEnableParserCache = false;
44 $wgDeferredUpdateList = array();
45 $wgMemc = &wfGetMainCache();
46 $messageMemc = &wfGetMessageCacheStorage();
47 $parserMemc = &wfGetParserCacheStorage();
49 // $wgContLang = new StubContLang;
51 $wgLang = new StubUserLang
;
52 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
53 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
54 $wgRequest = new WebRequest
;
56 if ( $wgStyleDirectory === false ) {
57 $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",
110 * Delete the specified files, if they exist.
112 * @param $files Array: full paths to files to delete.
114 private static function deleteFiles( $files ) {
115 foreach ( $files as $file ) {
116 if ( file_exists( $file ) ) {
123 * Delete the specified directories, if they exist. Must be empty.
125 * @param $dirs Array: full paths to directories to delete.
127 private static function deleteDirs( $dirs ) {
128 foreach ( $dirs as $dir ) {
129 if ( is_dir( $dir ) ) {
136 * Create a dummy uploads directory which will contain a couple
137 * of files in order to pass existence tests.
139 * @return String: the directory
141 private function setupUploadDir() {
144 if ( $this->keepUploads
) {
145 $dir = wfTempDir() . '/mwParser-images';
147 if ( is_dir( $dir ) ) {
151 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
154 wfDebug( "Creating upload directory $dir\n" );
156 if ( file_exists( $dir ) ) {
157 wfDebug( "Already exists!\n" );
161 wfMkdirParents( $dir . '/3/3a' );
162 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
164 wfMkdirParents( $dir . '/0/09' );
165 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
170 public static function suite() {
171 // Hack to invoke the autoloader required to get phpunit to recognize
172 // the UploadFromUrlTest class
173 class_exists( 'UploadFromUrlTest' );
174 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );