3 require_once( dirname( dirname( __FILE__
) ) . '/includes/upload/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 $context = new RequestContext
;
52 $wgLang = $context->getLang();
53 $wgOut = $context->getOutput();
54 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
55 $wgRequest = $context->getRequest();
57 if ( $wgStyleDirectory === false ) {
58 $wgStyleDirectory = "$IP/skins";
63 public function tearDown() {
64 $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",
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() {
145 if ( $this->keepUploads
) {
146 $dir = wfTempDir() . '/mwParser-images';
148 if ( is_dir( $dir ) ) {
152 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
155 wfDebug( "Creating upload directory $dir\n" );
157 if ( file_exists( $dir ) ) {
158 wfDebug( "Already exists!\n" );
162 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
163 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
165 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
166 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
171 public static function suite() {
172 // Hack to invoke the autoloader required to get phpunit to recognize
173 // the UploadFromUrlTest class
174 class_exists( 'UploadFromUrlTest' );
175 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );