Index: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php |
— | — | @@ -0,0 +1,168 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once('UploadFromUrlTest.php'); |
| 5 | + |
| 6 | +class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite |
| 7 | +{ |
| 8 | + public static function addTables(&$tables) { |
| 9 | + $tables[] = 'user_properties'; |
| 10 | + $tables[] = 'filearchive'; |
| 11 | + $tables[] = 'logging'; |
| 12 | + $tables[] = 'updatelog'; |
| 13 | + $tables[] = 'iwlinks'; |
| 14 | + return true; |
| 15 | + } |
| 16 | + |
| 17 | + function setUp() { |
| 18 | + global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, |
| 19 | + $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, |
| 20 | + $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, |
| 21 | + $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, |
| 22 | + $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath, |
| 23 | + $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath; |
| 24 | + |
| 25 | + $wgScript = '/index.php'; |
| 26 | + $wgScriptPath = '/'; |
| 27 | + $wgArticlePath = '/wiki/$1'; |
| 28 | + $wgStyleSheetPath = '/skins'; |
| 29 | + $wgStylePath = '/skins'; |
| 30 | + $wgThumbnailScriptPath = false; |
| 31 | + $wgLocalFileRepo = array( |
| 32 | + 'class' => 'LocalRepo', |
| 33 | + 'name' => 'local', |
| 34 | + 'directory' => 'test-repo', |
| 35 | + 'url' => 'http://example.com/images', |
| 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 | + * Remove the dummy uploads directory |
| 72 | + */ |
| 73 | + private function teardownUploadDir( $dir ) { |
| 74 | + if ( $this->keepUploads ) { |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + // delete the files first, then the dirs. |
| 79 | + self::deleteFiles( |
| 80 | + array ( |
| 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", |
| 86 | + |
| 87 | + "$dir/0/09/Bad.jpg", |
| 88 | + ) |
| 89 | + ); |
| 90 | + |
| 91 | + self::deleteDirs( |
| 92 | + array ( |
| 93 | + "$dir/3/3a", |
| 94 | + "$dir/3", |
| 95 | + "$dir/thumb/6/65", |
| 96 | + "$dir/thumb/6", |
| 97 | + "$dir/thumb/3/3a/Foobar.jpg", |
| 98 | + "$dir/thumb/3/3a", |
| 99 | + "$dir/thumb/3", |
| 100 | + |
| 101 | + "$dir/0/09/", |
| 102 | + "$dir/0/", |
| 103 | + |
| 104 | + "$dir/thumb", |
| 105 | + "$dir", |
| 106 | + ) |
| 107 | + ); |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + /** |
| 112 | + * Delete the specified files, if they exist. |
| 113 | + * @param array $files full paths to files to delete. |
| 114 | + */ |
| 115 | + private static function deleteFiles( $files ) { |
| 116 | + foreach( $files as $file ) { |
| 117 | + if( file_exists( $file ) ) { |
| 118 | + unlink( $file ); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + /** |
| 123 | + * Delete the specified directories, if they exist. Must be empty. |
| 124 | + * @param array $dirs full paths to directories to delete. |
| 125 | + */ |
| 126 | + private static function deleteDirs( $dirs ) { |
| 127 | + foreach( $dirs as $dir ) { |
| 128 | + if( is_dir( $dir ) ) { |
| 129 | + rmdir( $dir ); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Create a dummy uploads directory which will contain a couple |
| 136 | + * of files in order to pass existence tests. |
| 137 | + * @return string The directory |
| 138 | + */ |
| 139 | + private function setupUploadDir() { |
| 140 | + global $IP; |
| 141 | + if ( $this->keepUploads ) { |
| 142 | + $dir = wfTempDir() . '/mwParser-images'; |
| 143 | + if ( is_dir( $dir ) ) { |
| 144 | + return $dir; |
| 145 | + } |
| 146 | + } else { |
| 147 | + $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; |
| 148 | + } |
| 149 | + |
| 150 | + wfDebug( "Creating upload directory $dir\n" ); |
| 151 | + if ( file_exists( $dir ) ) { |
| 152 | + wfDebug( "Already exists!\n" ); |
| 153 | + return $dir; |
| 154 | + } |
| 155 | + wfMkdirParents( $dir . '/3/3a' ); |
| 156 | + copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); |
| 157 | + |
| 158 | + wfMkdirParents( $dir . '/0/09' ); |
| 159 | + copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); |
| 160 | + return $dir; |
| 161 | + } |
| 162 | + |
| 163 | + public static function suite() |
| 164 | + { |
| 165 | + return new UploadFromUrlTestSuite('UploadFromUrlTest'); |
| 166 | + } |
| 167 | + |
| 168 | +} |
| 169 | + |
Property changes on: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php |
___________________________________________________________________ |
Name: svn:eol-syle |
1 | 170 | + native |
Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php |
— | — | @@ -13,9 +13,10 @@ |
14 | 14 | class UploadFromUrlTest extends ApiSetup { |
15 | 15 | |
16 | 16 | function setUp() { |
17 | | - global $wgEnableUploads, $wgLocalFileRepo; |
| 17 | + global $wgEnableUploads, $wgLocalFileRepo, $wgAllowCopyUploads; |
18 | 18 | |
19 | 19 | $wgEnableUploads = true; |
| 20 | + $wgAllowCopyUploads = true; |
20 | 21 | parent::setup(); |
21 | 22 | $wgLocalFileRepo = array( |
22 | 23 | 'class' => 'LocalRepo', |
— | — | @@ -172,7 +173,7 @@ |
173 | 174 | $job = Job::pop(); |
174 | 175 | $this->assertEquals( 'UploadFromUrlJob', get_class($job) ); |
175 | 176 | |
176 | | - $status = $job->run(); |
| 177 | + $status = $job->run(); |
177 | 178 | $this->assertTrue( $status->isOk() ); |
178 | 179 | |
179 | 180 | return $data; |
Index: trunk/phase3/maintenance/tests/phpunit.xml |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | <file>TitlePermissionTest.php</file> |
34 | 34 | <file>TitleTest.php</file> |
35 | 35 | <file>UploadTest.php</file> |
36 | | - <file>UploadFromUrlTest.php</file> |
| 36 | + <file>UploadFromUrlTestSuite.php</file> |
37 | 37 | <file>XmlTest.php</file> |
38 | 38 | </testsuite> |
39 | 39 | <groups> |