Merge "Add more checks to ApiStructureTest.php"
[lhc/web/wiklou.git] / tests / phpunit / suites / UploadFromUrlTestSuite.php
1 <?php
2
3 require_once dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php';
4
5 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
6 public $savedGlobals = [];
7
8 public static function addTables( &$tables ) {
9 $tables[] = 'user_properties';
10 $tables[] = 'filearchive';
11 $tables[] = 'logging';
12 $tables[] = 'updatelog';
13 $tables[] = 'iwlinks';
14
15 return true;
16 }
17
18 protected function setUp() {
19 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
20 $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
21 $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection;
22
23 $tmpDir = $this->getNewTempDirectory();
24 $tmpGlobals = [];
25
26 $tmpGlobals['wgScript'] = '/index.php';
27 $tmpGlobals['wgScriptPath'] = '/';
28 $tmpGlobals['wgArticlePath'] = '/wiki/$1';
29 $tmpGlobals['wgStylePath'] = '/skins';
30 $tmpGlobals['wgThumbnailScriptPath'] = false;
31 $tmpGlobals['wgLocalFileRepo'] = [
32 'class' => LocalRepo::class,
33 'name' => 'local',
34 'url' => 'http://example.com/images',
35 'hashLevels' => 2,
36 'transformVia404' => false,
37 'backend' => new FSFileBackend( [
38 'name' => 'local-backend',
39 'wikiId' => wfWikiID(),
40 'containerPaths' => [
41 'local-public' => "{$tmpDir}/test-repo/public",
42 'local-thumb' => "{$tmpDir}/test-repo/thumb",
43 'local-temp' => "{$tmpDir}/test-repo/temp",
44 'local-deleted' => "{$tmpDir}/test-repo/delete",
45 ]
46 ] ),
47 ];
48 foreach ( $tmpGlobals as $var => $val ) {
49 if ( array_key_exists( $var, $GLOBALS ) ) {
50 $this->savedGlobals[$var] = $GLOBALS[$var];
51 }
52 $GLOBALS[$var] = $val;
53 }
54
55 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
56 $wgNamespaceAliases['Image'] = NS_FILE;
57 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
58
59 $wgParserCacheType = CACHE_NONE;
60 DeferredUpdates::clearPendingUpdates();
61 $wgMemc = wfGetMainCache();
62 $messageMemc = wfGetMessageCacheStorage();
63
64 RequestContext::resetMain();
65 $context = RequestContext::getMain();
66 $wgUser = new User;
67 $wgLang = $context->getLanguage();
68 $wgOut = $context->getOutput();
69 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
70 $wgRequest = $context->getRequest();
71
72 if ( $wgStyleDirectory === false ) {
73 $wgStyleDirectory = "$IP/skins";
74 }
75
76 RepoGroup::destroySingleton();
77 FileBackendGroup::destroySingleton();
78 }
79
80 protected function tearDown() {
81 foreach ( $this->savedGlobals as $var => $val ) {
82 $GLOBALS[$var] = $val;
83 }
84 // Restore backends
85 RepoGroup::destroySingleton();
86 FileBackendGroup::destroySingleton();
87
88 parent::tearDown();
89 }
90
91 public static function suite() {
92 // Hack to invoke the autoloader required to get phpunit to recognize
93 // the UploadFromUrlTest class
94 class_exists( 'UploadFromUrlTest' );
95 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
96
97 return $suite;
98 }
99 }