Fixed some doxygen warnings
[lhc/web/wiklou.git] / maintenance / tests / UploadFromUrlTestSuite.php
1 <?php
2
3 require_once( 'UploadFromUrlTest.php' );
4
5 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite
6 {
7 public static function addTables( &$tables ) {
8 $tables[] = 'user_properties';
9 $tables[] = 'filearchive';
10 $tables[] = 'logging';
11 $tables[] = 'updatelog';
12 $tables[] = 'iwlinks';
13 return true;
14 }
15
16 function setUp() {
17 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
18 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
19 $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
20 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
21 $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
22 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
23
24 $wgScript = '/index.php';
25 $wgScriptPath = '/';
26 $wgArticlePath = '/wiki/$1';
27 $wgStyleSheetPath = '/skins';
28 $wgStylePath = '/skins';
29 $wgThumbnailScriptPath = false;
30 $wgLocalFileRepo = array(
31 'class' => 'LocalRepo',
32 'name' => 'local',
33 'directory' => wfTempDir().'/test-repo',
34 'url' => 'http://example.com/images',
35 'deletedDir' => wfTempDir().'/test-repo/delete',
36 'hashLevels' => 2,
37 'transformVia404' => false,
38 );
39 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
40 $wgNamespaceAliases['Image'] = NS_FILE;
41 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
42
43
44 $wgEnableParserCache = false;
45 $wgDeferredUpdateList = array();
46 $wgMemc =& wfGetMainCache();
47 $messageMemc =& wfGetMessageCacheStorage();
48 $parserMemc =& wfGetParserCacheStorage();
49
50 $wgContLang = new StubContLang;
51 $wgUser = new StubUser;
52 $wgLang = new StubUserLang;
53 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
54 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
55 $wgRequest = new WebRequest;
56
57 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
58 array( $messageMemc, $wgUseDatabaseMessages,
59 $wgMsgCacheExpiry, wfWikiID() ) );
60 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
61
62 }
63
64 public function tearDown() {
65 $this->teardownUploadDir( $this->uploadDir );
66 }
67
68 private $uploadDir;
69 private $keepUploads;
70
71 /**
72 * Remove the dummy uploads directory
73 */
74 private function teardownUploadDir( $dir ) {
75 if ( $this->keepUploads ) {
76 return;
77 }
78
79 // delete the files first, then the dirs.
80 self::deleteFiles(
81 array (
82 "$dir/3/3a/Foobar.jpg",
83 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
84 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
85 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
86 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
87
88 "$dir/0/09/Bad.jpg",
89 )
90 );
91
92 self::deleteDirs(
93 array (
94 "$dir/3/3a",
95 "$dir/3",
96 "$dir/thumb/6/65",
97 "$dir/thumb/6",
98 "$dir/thumb/3/3a/Foobar.jpg",
99 "$dir/thumb/3/3a",
100 "$dir/thumb/3",
101
102 "$dir/0/09/",
103 "$dir/0/",
104
105 "$dir/thumb",
106 "$dir",
107 )
108 );
109 }
110
111
112 /**
113 * Delete the specified files, if they exist.
114 *
115 * @param $files Array: full paths to files to delete.
116 */
117 private static function deleteFiles( $files ) {
118 foreach ( $files as $file ) {
119 if ( file_exists( $file ) ) {
120 unlink( $file );
121 }
122 }
123 }
124
125 /**
126 * Delete the specified directories, if they exist. Must be empty.
127 *
128 * @param $dirs Array: full paths to directories to delete.
129 */
130 private static function deleteDirs( $dirs ) {
131 foreach ( $dirs as $dir ) {
132 if ( is_dir( $dir ) ) {
133 rmdir( $dir );
134 }
135 }
136 }
137
138 /**
139 * Create a dummy uploads directory which will contain a couple
140 * of files in order to pass existence tests.
141 *
142 * @return String: the directory
143 */
144 private function setupUploadDir() {
145 global $IP;
146 if ( $this->keepUploads ) {
147 $dir = wfTempDir() . '/mwParser-images';
148 if ( is_dir( $dir ) ) {
149 return $dir;
150 }
151 } else {
152 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
153 }
154
155 wfDebug( "Creating upload directory $dir\n" );
156 if ( file_exists( $dir ) ) {
157 wfDebug( "Already exists!\n" );
158 return $dir;
159 }
160 wfMkdirParents( $dir . '/3/3a' );
161 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
162
163 wfMkdirParents( $dir . '/0/09' );
164 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
165 return $dir;
166 }
167
168 public static function suite()
169 {
170 return new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
171 }
172
173 }
174