Merge "Pass the language code to the MessagesPreLoad hook"
[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 $parserMemc;
23
24 $tmpDir = $this->getNewTempDirectory();
25 $tmpGlobals = [];
26
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',
34 'name' => 'local',
35 'url' => 'http://example.com/images',
36 'hashLevels' => 2,
37 'transformVia404' => false,
38 'backend' => new FSFileBackend( [
39 'name' => 'local-backend',
40 'wikiId' => wfWikiID(),
41 'containerPaths' => [
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",
46 ]
47 ] ),
48 ];
49 foreach ( $tmpGlobals as $var => $val ) {
50 if ( array_key_exists( $var, $GLOBALS ) ) {
51 $this->savedGlobals[$var] = $GLOBALS[$var];
52 }
53 $GLOBALS[$var] = $val;
54 }
55
56 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
57 $wgNamespaceAliases['Image'] = NS_FILE;
58 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
59
60 $wgParserCacheType = CACHE_NONE;
61 DeferredUpdates::clearPendingUpdates();
62 $wgMemc = wfGetMainCache();
63 $messageMemc = wfGetMessageCacheStorage();
64 $parserMemc = wfGetParserCacheStorage();
65
66 RequestContext::resetMain();
67 $context = RequestContext::getMain();
68 $wgUser = new User;
69 $wgLang = $context->getLanguage();
70 $wgOut = $context->getOutput();
71 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
72 $wgRequest = $context->getRequest();
73
74 if ( $wgStyleDirectory === false ) {
75 $wgStyleDirectory = "$IP/skins";
76 }
77
78 RepoGroup::destroySingleton();
79 FileBackendGroup::destroySingleton();
80 }
81
82 protected function tearDown() {
83 foreach ( $this->savedGlobals as $var => $val ) {
84 $GLOBALS[$var] = $val;
85 }
86 // Restore backends
87 RepoGroup::destroySingleton();
88 FileBackendGroup::destroySingleton();
89
90 parent::tearDown();
91 }
92
93 /**
94 * Delete the specified files, if they exist.
95 *
96 * @param array $files Full paths to files to delete.
97 */
98 private static function deleteFiles( $files ) {
99 foreach ( $files as $file ) {
100 if ( file_exists( $file ) ) {
101 unlink( $file );
102 }
103 }
104 }
105
106 /**
107 * Delete the specified directories, if they exist. Must be empty.
108 *
109 * @param array $dirs Full paths to directories to delete.
110 */
111 private static function deleteDirs( $dirs ) {
112 foreach ( $dirs as $dir ) {
113 if ( is_dir( $dir ) ) {
114 rmdir( $dir );
115 }
116 }
117 }
118
119 /**
120 * Create a dummy uploads directory which will contain a couple
121 * of files in order to pass existence tests.
122 *
123 * @return string The directory
124 */
125 private function setupUploadDir() {
126 global $IP;
127
128 $dir = $this->getNewTempDirectory();
129
130 wfDebug( "Creating upload directory $dir\n" );
131
132 wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
133 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
134
135 wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
136 copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/0/09/Bad.jpg" );
137
138 return $dir;
139 }
140
141 public static function suite() {
142 // Hack to invoke the autoloader required to get phpunit to recognize
143 // the UploadFromUrlTest class
144 class_exists( 'UploadFromUrlTest' );
145 $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
146
147 return $suite;
148 }
149 }