3 require_once dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php';
5 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
6 public $savedGlobals = [];
8 public static function addTables( &$tables ) {
9 $tables[] = 'user_properties';
10 $tables[] = 'filearchive';
11 $tables[] = 'logging';
12 $tables[] = 'updatelog';
13 $tables[] = 'iwlinks';
18 protected function setUp() {
19 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
20 $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
21 $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection,
24 $tmpDir = $this->getNewTempDirectory();
27 $tmpGlobals['wgScript'] = '/index.php';
28 $tmpGlobals['wgScriptPath'] = '/';
29 $tmpGlobals['wgArticlePath'] = '/wiki/$1';
30 $tmpGlobals['wgStylePath'] = '/skins';
31 $tmpGlobals['wgThumbnailScriptPath'] = false;
32 $tmpGlobals['wgLocalFileRepo'] = [
33 'class' => 'LocalRepo',
35 'url' => 'http://example.com/images',
37 'transformVia404' => false,
38 'backend' => new FSFileBackend( [
39 'name' => 'local-backend',
40 'wikiId' => wfWikiID(),
42 'local-public' => "{$tmpDir}/test-repo/public",
43 'local-thumb' => "{$tmpDir}/test-repo/thumb",
44 'local-temp' => "{$tmpDir}/test-repo/temp",
45 'local-deleted' => "{$tmpDir}/test-repo/delete",
49 foreach ( $tmpGlobals as $var => $val ) {
50 if ( array_key_exists( $var, $GLOBALS ) ) {
51 $this->savedGlobals[$var] = $GLOBALS[$var];
53 $GLOBALS[$var] = $val;
56 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
57 $wgNamespaceAliases['Image'] = NS_FILE;
58 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
60 $wgParserCacheType = CACHE_NONE;
61 DeferredUpdates::clearPendingUpdates();
62 $wgMemc = wfGetMainCache();
63 $messageMemc = wfGetMessageCacheStorage();
65 RequestContext::resetMain();
66 $context = RequestContext::getMain();
68 $wgLang = $context->getLanguage();
69 $wgOut = $context->getOutput();
70 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
71 $wgRequest = $context->getRequest();
73 if ( $wgStyleDirectory === false ) {
74 $wgStyleDirectory = "$IP/skins";
77 RepoGroup::destroySingleton();
78 FileBackendGroup::destroySingleton();
81 protected function tearDown() {
82 foreach ( $this->savedGlobals as $var => $val ) {
83 $GLOBALS[$var] = $val;
86 RepoGroup::destroySingleton();
87 FileBackendGroup::destroySingleton();
93 * Delete the specified files, if they exist.
95 * @param array $files Full paths to files to delete.
97 private static function deleteFiles( $files ) {
98 foreach ( $files as $file ) {
99 if ( file_exists( $file ) ) {
106 * Delete the specified directories, if they exist. Must be empty.
108 * @param array $dirs Full paths to directories to delete.
110 private static function deleteDirs( $dirs ) {
111 foreach ( $dirs as $dir ) {
112 if ( is_dir( $dir ) ) {
119 * Create a dummy uploads directory which will contain a couple
120 * of files in order to pass existence tests.
122 * @return string The directory
124 private function setupUploadDir() {
127 $dir = $this->getNewTempDirectory();
129 wfDebug( "Creating upload directory $dir\n" );
131 wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
132 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
134 wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
135 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/0/09/Bad.jpg" );
140 public static function suite() {
141 // Hack to invoke the autoloader required to get phpunit to recognize
142 // the UploadFromUrlTest class
143 class_exists( 'UploadFromUrlTest' );
144 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );