Index: trunk/extensions/ResumableUpload/tests/qunit/ResumableUploadTest.js |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +/** |
| 3 | + * Stubs for resumable upload javascript test |
| 4 | + */ |
| 5 | + |
| 6 | +module( 'resumableUploadApi.js' ); |
| 7 | + |
| 8 | +test( 'getToken', function(){ |
| 9 | + |
| 10 | +}); |
| 11 | + |
| 12 | +test( 'instaciateUpload', function(){ |
| 13 | + |
| 14 | +}); |
| 15 | + |
| 16 | +test( 'uploadChunks', function(){ |
| 17 | + |
| 18 | +}) |
| 19 | + |
| 20 | +test( 'handleResult', function(){ |
| 21 | + |
| 22 | +}) |
\ No newline at end of file |
Property changes on: trunk/extensions/ResumableUpload/tests/qunit/ResumableUploadTest.js |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 23 | + text/plain |
Index: trunk/extensions/ResumableUpload/tests/qunit/index.html |
— | — | @@ -0,0 +1,48 @@ |
| 2 | +<!DOCTYPE html> |
| 3 | +<html> |
| 4 | +<head> |
| 5 | + <title>ResumableUpload JavaScript Test Suite</title> |
| 6 | + |
| 7 | + <!-- MediaWiki Modules --> |
| 8 | + <meta name="ResourceLoaderDynamicStyles" content="" /> |
| 9 | + |
| 10 | + <script src="../../../../resources/jquery/jquery.js"></script> |
| 11 | + |
| 12 | + <script> function startUp(){} </script> |
| 13 | + <script src="../mediawiki/mediawiki.js"></script> |
| 14 | + <script> mw.config = new mw.Map( false ); </script> |
| 15 | + |
| 16 | + <script src="../../../../resources/jquery/jquery.checkboxShiftClick.js"></script> |
| 17 | + <script src="../../../../resources/jquery/jquery.client.js"></script> |
| 18 | + <script src="../../../../resources/jquery/jquery.cookie.js"></script> |
| 19 | + <script src="../../../../resources/jquery/jquery.messageBox.js"></script> |
| 20 | + <script src="../../../../resources/jquery/jquery.makeCollapsible.js"></script> |
| 21 | + <script src="../../../../resources/jquery/jquery.placeholder.js"></script> |
| 22 | + |
| 23 | + <script src="../../../../resources/jquery/jquery.colorUtil.js"></script> |
| 24 | + |
| 25 | + <!-- QUnit dependancies and scripts --> |
| 26 | + <link rel="stylesheet" href="../../../../resources/jquery/jquery.qunit.css" /> |
| 27 | + <script src="../../../../resources/jquery/jquery.qunit.js"></script> |
| 28 | + |
| 29 | + <!-- Your tests styles go here --> |
| 30 | + <link rel="stylesheet" href="unit/main.css" /> |
| 31 | + |
| 32 | + <!-- Your test suites go here --> |
| 33 | + <script src="ResumableUploadTest.js"></script> |
| 34 | + |
| 35 | + <!-- TestSwarm --> |
| 36 | + <script src="http://toolserver.org/~krinkle/testswarm/js/inject.js"></script> |
| 37 | +</head> |
| 38 | +<body> |
| 39 | + <h1 id="qunit-header">MediaWiki JavaScript Test Suite</h1> |
| 40 | + <h2 id="qunit-banner"></h2> |
| 41 | + <div id="qunit-testrunner-toolbar"></div> |
| 42 | + <h2 id="qunit-userAgent"></h2> |
| 43 | + <ol id="qunit-tests"></ol> |
| 44 | + |
| 45 | +<div id="mw-content"> |
| 46 | + <div id="bodyContent"></div> |
| 47 | +</div> |
| 48 | +</body> |
| 49 | +</html> |
Property changes on: trunk/extensions/ResumableUpload/tests/qunit/index.html |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 50 | + text/plain |
Index: trunk/extensions/ResumableUpload/tests/qunit/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +How this works with testSwarm is yet to be determined |
| 3 | +See https://bugzilla.wikimedia.org/show_bug.cgi?id=28915 |
\ No newline at end of file |
Index: trunk/extensions/ResumableUpload/tests/phpunit/bootstrap.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Set up the MediaWiki environment when running tests with "phpunit" command |
| 6 | + * |
| 7 | + * Warning: this file is not included from global scope! |
| 8 | + * @file |
| 9 | + */ |
| 10 | + |
| 11 | +global $wgCommandLineMode, $IP, $optionsWithArgs; |
| 12 | +$IP = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ). "/mw-svn"; |
| 13 | +define( 'MW_PHPUNIT_TEST', true ); |
| 14 | + |
| 15 | +require_once( "$IP/maintenance/commandLine.inc" ); |
| 16 | + |
| 17 | +if( !version_compare(PHPUnit_Runner_Version::id(), "3.4.1", ">") ) { |
| 18 | + echo <<<EOF |
| 19 | +************************************************************ |
| 20 | + |
| 21 | +These tests run best with version PHPUnit 3.4.2 or better. |
| 22 | +Earlier versions may show failures because earlier versions |
| 23 | +of PHPUnit do not properly implement dependencies. |
| 24 | + |
| 25 | +************************************************************ |
| 26 | + |
| 27 | +EOF; |
| 28 | +} |
\ No newline at end of file |
Index: trunk/extensions/ResumableUpload/tests/phpunit/phpunit.xml |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +<!-- See http://www.phpunit.de/manual/3.3/en/appendixes.configuration.html --> |
| 3 | +<phpunit bootstrap="./bootstrap.php" |
| 4 | + colors="false" |
| 5 | + backupGlobals="false" |
| 6 | + convertErrorsToExceptions="true" |
| 7 | + convertNoticesToExceptions="true" |
| 8 | + convertWarningsToExceptions="true" |
| 9 | + stopOnFailure="false"> |
| 10 | + <testsuite name="MediaWiki Test Suite"> |
| 11 | + <!-- <directory>.</directory> --> |
| 12 | + <file>UploadFromChunksTest.php</file> |
| 13 | + </testsuite> |
| 14 | + <groups> |
| 15 | + <exclude> |
| 16 | + <group>Broken</group> |
| 17 | + <group>Stub</group> |
| 18 | + </exclude> |
| 19 | + </groups> |
| 20 | +</phpunit> |
\ No newline at end of file |
Property changes on: trunk/extensions/ResumableUpload/tests/phpunit/phpunit.xml |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 21 | + text/plain |
Index: trunk/extensions/ResumableUpload/tests/phpunit/ResumableUploadTest.php |
— | — | @@ -0,0 +1,371 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +global $IP; |
| 5 | +require_once( "$IP/maintenance/tests/ApiSetup.php" ); |
| 6 | +require_once( "$IP/maintenance/deleteArchivedFiles.inc" ); |
| 7 | +require_once( "$IP/maintenance/deleteArchivedRevisions.inc" ); |
| 8 | +require_once( dirname( dirname( __FILE__ ) ) . '/ResumableUpload.php' ); |
| 9 | + |
| 10 | +class nullClass { |
| 11 | + public function handleOutput(){} |
| 12 | + public function purgeRedundantText(){} |
| 13 | +} |
| 14 | + |
| 15 | +class UploadFromChunksTest extends ApiSetup { |
| 16 | + |
| 17 | + // a base64 encoded image; |
| 18 | + private $pngimg = "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAASUExURf///8zMzJmZmWZmZjMzMwAAAPOPemkAAAM1SURBVHjaYmBgYGBkYQUBFkYWFiCPCchixQAMCCZAACF0MAMVM4K4TFh0IGsBCCAkOxhYmBnAAKaHhZkZmxaAAGJgYIbpYGBihGgBWsTMzMwE4jIhaWGAYoAAYmCECDExYAcwGxkg5oNIgABigDqLARdgZmGB2wICrKwAAcSA3xKgIxlZ0PwCEEAMBCxhgHoWSQtAADFAAxgfYEJ1GEAAQbQw4tUCsocBYQVAADEgu4uRkREeUCwszEwwLhOKLQABhNDCBA4aSDgwwhIAJKqYUPwCEEAMUK/AUwnc9aywJMCI7DAgAAggBohZ8JTBhGIJzCoWZL8ABBCYidAB8RUjWppkYUG2BSCAGMDqEMZiswUtXgACiAHsFYixTMywGGLGpgUWYgABxAA2mQkWCMyMqFoYmdD8ACQAAogBHJHMrCxg1cyIiICmCkYWDFsAAgiihYmZCewFFpR0BfI3LLch+QUggBiQ0iQjEyMDmh54qCBlUIAAYsCRJsElADQvgWKTlRGeKwECiAF3XgGmMEYQYADZzcoA9z5AAMG9RQCAtEC9DxBADFiyFyMjVi0wABBAWLQwQdIiuhYGWJIACCBg+KKUJ9BoBRdS2LQALQMIIGDQIEmwAO1kYcVWHCDZAhBAqFqYmOAxj2YNtAwDAYAAYmDEiBYWzHKKkRERYiwAAYSphZEZwxZGZiZQVEJTJkAAMTCyokc7M5oORlC5wcoEjxeAAAJqQXU0UB6W5WFmABMtEzMi1wEEEFAbE0YyAUuzMMEsYQalMkQSBQggUDmNPU3C9IA4LCxI+QUggEBiKOU8yExgqccCL3chnkPKlQABhGo6ejHBDKmdUHMlQAAhhQvQaGZGkBIkjcAMywLmI+VKgABCSowsTJhZkhlWXiBpAQggYBqBZl9GVOdBcz0LZqEEEEAMqLULMBLg1THWog9IAwQQA0qiZcRW5aPbAhBADCg1El4tMAAQQAxoiZYZXnTh1AIQQAzo2QlYpDDjcBgrxGEAAcSAJTthswmiBUwDBBC2GpkZJTaRvQ+mAQKIAUuuxdZWQvILQABBmSxMjBj5EpcWgACCMoFOYYSpZyHQHgMIMACt2hmoVEikCQAAAABJRU5ErkJggg=="; |
| 19 | + |
| 20 | + function setUp() { |
| 21 | + global $wgEnableUploads, $wgLocalFileRepo; |
| 22 | + |
| 23 | + $wgEnableUploads = true; |
| 24 | + parent::setup(); |
| 25 | + $wgLocalFileRepo = array( |
| 26 | + 'class' => 'LocalRepo', |
| 27 | + 'name' => 'local', |
| 28 | + 'directory' => 'test-repo', |
| 29 | + 'url' => 'http://example.com/images', |
| 30 | + 'hashLevels' => 2, |
| 31 | + 'transformVia404' => false, |
| 32 | + ); |
| 33 | + |
| 34 | + ini_set( 'log_errors', 1 ); |
| 35 | + ini_set( 'error_reporting', 1 ); |
| 36 | + ini_set( 'display_errors', 1 ); |
| 37 | + } |
| 38 | + |
| 39 | + function makeChunk( $content ) { |
| 40 | + $file = tempnam( wfTempDir(), "" ); |
| 41 | + $fh = fopen( $file, "wb" ); |
| 42 | + if ( $fh == false ) { |
| 43 | + $this->markTestIncomplete( "Couldn't open $file!\n" ); |
| 44 | + return; |
| 45 | + } |
| 46 | + fwrite( $fh, $content ); |
| 47 | + fclose( $fh ); |
| 48 | + |
| 49 | + $_FILES['chunk']['tmp_name'] = $file; |
| 50 | + $_FILES['chunk']['size'] = 3; |
| 51 | + $_FILES['chunk']['error'] = null; |
| 52 | + $_FILES['chunk']['name'] = "test.txt"; |
| 53 | + } |
| 54 | + |
| 55 | + function cleanChunk() { |
| 56 | + if ( file_exists( $_FILES['chunk']['tmp_name'] ) ) |
| 57 | + unlink( $_FILES['chunk']['tmp_name'] ); |
| 58 | + } |
| 59 | + |
| 60 | + function doApiRequest( $params, $data = null ) { |
| 61 | + $session = isset( $data[2] ) ? $data[2] : array(); |
| 62 | + $_SESSION = $session; |
| 63 | + |
| 64 | + $req = new FauxRequest( $params, true, $session ); |
| 65 | + $module = new ApiMain( $req, true ); |
| 66 | + $module->execute(); |
| 67 | + |
| 68 | + return array( $module->getResultData(), $req, $_SESSION ); |
| 69 | + } |
| 70 | + |
| 71 | + /* function testGetTitle() { */ |
| 72 | + /* $filename = tempnam( wfTempDir(), "" ); */ |
| 73 | + /* $c = new ApiResumableUpload; */ |
| 74 | + /* $c->initialize( false, "temp.txt", null, $filename, 0, null ); */ |
| 75 | + /* $this->assertEquals( null, $c->getUpload()->getTitle() ); */ |
| 76 | + |
| 77 | + /* $c = new ApiResumableUpload; */ |
| 78 | + /* $c->initialize( false, "Temp.png", null, $filename, 0, null ); */ |
| 79 | + /* $this->assertEquals( Title::makeTitleSafe( NS_FILE, "Temp.png" ), $c->getUpload()->getTitle() ); */ |
| 80 | + /* } */ |
| 81 | + |
| 82 | + function testLogin() { |
| 83 | + $data = $this->doApiRequest( array( |
| 84 | + 'action' => 'login', |
| 85 | + 'lgname' => self::$userName, |
| 86 | + 'lgpassword' => self::$passWord ) ); |
| 87 | + $this->assertArrayHasKey( "login", $data[0] ); |
| 88 | + $this->assertArrayHasKey( "result", $data[0]['login'] ); |
| 89 | + $this->assertEquals( "NeedToken", $data[0]['login']['result'] ); |
| 90 | + $token = $data[0]['login']['token']; |
| 91 | + |
| 92 | + $data = $this->doApiRequest( array( |
| 93 | + 'action' => 'login', |
| 94 | + "lgtoken" => $token, |
| 95 | + "lgname" => self::$userName, |
| 96 | + "lgpassword" => self::$passWord ) ); |
| 97 | + |
| 98 | + $this->assertArrayHasKey( "login", $data[0] ); |
| 99 | + $this->assertArrayHasKey( "result", $data[0]['login'] ); |
| 100 | + $this->assertEquals( "Success", $data[0]['login']['result'] ); |
| 101 | + $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] ); |
| 102 | + |
| 103 | + return $data; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @depends testLogin |
| 108 | + */ |
| 109 | + function testSetupChunkBannedFileType( $data ) { |
| 110 | + global $wgUser; |
| 111 | + $wgUser = User::newFromName( self::$userName ); |
| 112 | + $wgUser->load(); |
| 113 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 114 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 115 | + $exception = false; |
| 116 | + |
| 117 | + try { |
| 118 | + $this->doApiRequest( array( |
| 119 | + 'action' => 'resumableupload', |
| 120 | + 'comment' => 'test', |
| 121 | + 'watchlist' => 'watch', |
| 122 | + 'filename' => 'tmp.txt', |
| 123 | + 'token' => $token ), $data ); |
| 124 | + } catch ( UsageException $e ) { |
| 125 | + $exception = true; |
| 126 | + $this->assertEquals( "This type of file is banned", $e->getMessage() ); |
| 127 | + } |
| 128 | + |
| 129 | + $this->assertTrue( $exception, "Got exception" ); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * @depends testLogin |
| 134 | + */ |
| 135 | + function testSetupChunkSession( $data ) { |
| 136 | + global $wgUser; |
| 137 | + $wgUser = User::newFromName( self::$userName ); |
| 138 | + $wgUser->load(); |
| 139 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 140 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 141 | + |
| 142 | + $data = $this->doApiRequest( array( |
| 143 | + 'action' => 'resumableupload', |
| 144 | + 'comment' => 'test', |
| 145 | + 'watchlist' => 'watch', |
| 146 | + 'filename' => 'TestPic.png', |
| 147 | + 'token' => $token ), $data ); |
| 148 | + |
| 149 | + $this->assertArrayHasKey( 'uploadUrl', $data[0] ); |
| 150 | + $this->assertRegexp( '/action=resumableupload/', $data[0]['uploadUrl'] ); |
| 151 | + $this->assertRegexp( '/chunksession=/', $data[0]['uploadUrl'] ); |
| 152 | + $this->assertRegexp( '/token=/', $data[0]['uploadUrl'] ); |
| 153 | + |
| 154 | + return $data; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * @depends testLogin |
| 159 | + */ |
| 160 | + function testInvalidSessionKey( $data ) { |
| 161 | + global $wgUser; |
| 162 | + $wgUser = User::newFromName( self::$userName ); |
| 163 | + $wgUser->load(); |
| 164 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 165 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 166 | + $exception = false; |
| 167 | + |
| 168 | + try { |
| 169 | + $this->doApiRequest( array( |
| 170 | + 'action' => 'resumableupload', |
| 171 | + 'enablechunks' => true, |
| 172 | + 'token' => $token, |
| 173 | + 'chunksession' => 'bogus' ), $data ); |
| 174 | + } catch ( UsageException $e ) { |
| 175 | + $exception = true; |
| 176 | + $this->assertEquals( "Not a valid session key", $e->getMessage() ); |
| 177 | + } |
| 178 | + |
| 179 | + $this->assertTrue( $exception, "Got exception" ); |
| 180 | + } |
| 181 | + |
| 182 | + function testPerformUploadInitError() { |
| 183 | + global $wgUser; |
| 184 | + $wgUser = User::newFromId( 1 ); |
| 185 | + |
| 186 | + $req = new FauxRequest( |
| 187 | + array( |
| 188 | + 'action' => 'resumableupload', |
| 189 | + 'sessionkey' => '1', |
| 190 | + 'filename' => 'test.png', |
| 191 | + ) ); |
| 192 | + $module = new ApiMain( $req, true ); |
| 193 | + $gotException = false; |
| 194 | + try { |
| 195 | + $module->execute(); |
| 196 | + } catch ( UsageException $e ) { |
| 197 | + $this->assertEquals( "The token parameter must be set", $e->getMessage() ); |
| 198 | + $gotException = true; |
| 199 | + } |
| 200 | + |
| 201 | + $this->assertTrue( $gotException ); |
| 202 | + } |
| 203 | + |
| 204 | + |
| 205 | + /** |
| 206 | + * @depends testLogin |
| 207 | + */ |
| 208 | + function testSetupChunkForBannedContent( $data ) { |
| 209 | + global $wgUser; |
| 210 | + $wgUser = User::newFromName( self::$userName ); |
| 211 | + $wgUser->load(); |
| 212 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 213 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 214 | + $exception = false; |
| 215 | + |
| 216 | + $this->makeChunk( "123" ); |
| 217 | + $data = $this->doApiRequest( array( |
| 218 | + 'action' => 'resumableupload', |
| 219 | + 'comment' => 'test', |
| 220 | + 'watchlist' => 'watch', |
| 221 | + 'filename' => 'tmp.png', |
| 222 | + 'token' => $token ), $data ); |
| 223 | + return $data; |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * @depends testSetupChunkForBannedContent |
| 228 | + */ |
| 229 | + function testChunkUploadBannedContent ( $data ) { |
| 230 | + global $wgUser; |
| 231 | + $wgUser = User::newFromName( self::$userName ); |
| 232 | + $wgUser->load(); |
| 233 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 234 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 235 | + $exception = false; |
| 236 | + $url = $data[0]['uploadUrl']; |
| 237 | + $params = wfCgiToArray( substr( $url, strpos( $url, "?" ) ) ); |
| 238 | + $params['done'] = true; |
| 239 | + |
| 240 | + $this->makeChunk( "123" ); |
| 241 | + $gotException = false; |
| 242 | + try { |
| 243 | + $data = $this->doApiRequest( $params, $data ); |
| 244 | + } catch ( UsageException $e ) { |
| 245 | + $this->assertEquals( "This file did not pass file verification", |
| 246 | + $e->getMessage() ); |
| 247 | + $gotException = true; |
| 248 | + } |
| 249 | + $this->cleanChunk(); |
| 250 | + $this->assertTrue( $gotException ); |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * @depends testLogin |
| 255 | + */ |
| 256 | + function testUploadChunkDoneGood( $data ) { |
| 257 | + global $wgUser, $wgVerifyMimeType; |
| 258 | + $wgVerifyMimeType = false; |
| 259 | + |
| 260 | + $this->markTestIncomplete("Not working yet ... fails every other time b/c we're not dealing with a temporary db"); |
| 261 | + |
| 262 | + DeleteArchivedFilesImplementation::doDelete(new nullClass, true); |
| 263 | + DeleteArchivedRevisionsImplementation::doDelete(new nullClass); |
| 264 | + |
| 265 | + $id = Title::newFromText( "Twar.png", NS_FILE )->getArticleID(); |
| 266 | + $oldFile = Article::newFromID( $id ); |
| 267 | + if ( $oldFile ) { |
| 268 | + $oldFile->doDeleteArticle(); |
| 269 | + $oldFile->doPurge(); |
| 270 | + } |
| 271 | + |
| 272 | + $oldFile = wfFindFile( "Twar.png" ); |
| 273 | + if ( $oldFile ) { |
| 274 | + $oldFile->delete(); |
| 275 | + } |
| 276 | + $id = Title::newFromText( "Twar.png", NS_FILE )->getArticleID(); |
| 277 | + $this->assertEquals(0, $id); |
| 278 | + |
| 279 | + $oldFile = Article::newFromID( $id ); |
| 280 | + $this->assertEquals(null, $oldFile); |
| 281 | + |
| 282 | + $wgUser = User::newFromName( self::$userName ); |
| 283 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 284 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 285 | + $data = $this->doApiRequest( array( |
| 286 | + 'action' => 'resumableupload', |
| 287 | + 'comment' => 'test', |
| 288 | + 'watchlist' => 'watch', |
| 289 | + 'filename' => 'twar.png', |
| 290 | + 'token' => $token ), $data ); |
| 291 | + |
| 292 | + $url = $data[0]['uploadUrl']; |
| 293 | + $params = wfCgiToArray( substr( $url, strpos( $url, "?" ) ) ); |
| 294 | + $size = 0; |
| 295 | + for ( $i = 0; $i < 5; $i++ ) { |
| 296 | + $this->makeChunk( "123" ); |
| 297 | + $size += $_FILES['chunk']['size']; |
| 298 | + |
| 299 | + $data = $this->doApiRequest( $params, $data ); |
| 300 | + $this->assertArrayHasKey( "result", $data[0] ); |
| 301 | + $this->assertTrue( (bool)$data[0]["result"] ); |
| 302 | + |
| 303 | + $this->assertArrayHasKey( "filesize", $data[0] ); |
| 304 | + $this->assertEquals( $size, $data[0]['filesize'] ); |
| 305 | + |
| 306 | + $this->cleanChunk(); |
| 307 | + } |
| 308 | + |
| 309 | + $params['done'] = true; |
| 310 | + |
| 311 | + $this->makeChunk( "456" ); |
| 312 | + $data = $this->doApiRequest( $params, $data ); |
| 313 | + |
| 314 | + $this->cleanChunk(); |
| 315 | + $this->assertArrayHasKey( 'result', $data[0] ); |
| 316 | + |
| 317 | + $this->assertEquals( 1, $data[0]['result'] ); |
| 318 | + |
| 319 | + $this->assertArrayHasKey( 'done', $data[0] ); |
| 320 | + $this->assertEquals( 1, $data[0]['done'] ); |
| 321 | + |
| 322 | + $this->assertArrayHasKey( 'resultUrl', $data[0] ); |
| 323 | + $this->assertRegExp( '/File:Twar.png/', $data[0]['resultUrl'] ); |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * @depends testLogin |
| 328 | + */ |
| 329 | + function testUploadChunkDoneDuplicate( $data ) { |
| 330 | + global $wgUser, $wgVerifyMimeType; |
| 331 | + |
| 332 | + $this->markTestIncomplete("Not working yet"); |
| 333 | + |
| 334 | + $wgVerifyMimeType = false; |
| 335 | + $wgUser = User::newFromName( self::$userName ); |
| 336 | + $data[2]['wsEditToken'] = $data[2]['wsToken']; |
| 337 | + $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX; |
| 338 | + $data = $this->doApiRequest( array( |
| 339 | + 'filename' => 'twar.png', |
| 340 | + 'action' => 'resumableupload', |
| 341 | + 'token' => $token ), $data ); |
| 342 | + |
| 343 | + $url = $data[0]['uploadUrl']; |
| 344 | + $params = wfCgiToArray( substr( $url, strpos( $url, "?" ) ) ); |
| 345 | + $size = 0; |
| 346 | + $gotException = false; |
| 347 | + for ( $i = 0; $i < 30; $i++ ) { |
| 348 | + $this->makeChunk( "123" ); |
| 349 | + $size += $_FILES['chunk']['size']; |
| 350 | + try { |
| 351 | + $data = $this->doApiRequest( $params, $data ); |
| 352 | + } catch (UsageException $e) { |
| 353 | + $arr = $e->getMessageArray(); |
| 354 | + $this->assertArrayHasKey( "code", $arr ); |
| 355 | + $this->assertEquals( "internal-error", $arr['code'] ); |
| 356 | + |
| 357 | + $this->assertEquals( "fileexistserror", $arr[0][0] ); |
| 358 | + $gotException = true; |
| 359 | + } |
| 360 | + } |
| 361 | + $this->cleanChunk(); |
| 362 | + $this->assertTrue($gotException); |
| 363 | + } |
| 364 | + |
| 365 | + function testCleanup() { |
| 366 | + $dbw = wfGetDB( DB_MASTER ); |
| 367 | + $dbw->begin(); |
| 368 | + $dbw->delete("image", array('img_user_text' => self::$userName )); |
| 369 | + $dbw->commit(); |
| 370 | + $this->assertTrue(true); |
| 371 | + } |
| 372 | +} |