31 $user = self::$users[
'uploader'];
32 $userName = $user->getUser()->getName();
33 $password = $user->getPassword();
37 'lgname' => $userName,
38 'lgpassword' => $password
41 $this->assertArrayHasKey(
"login", $result );
42 $this->assertArrayHasKey(
"result", $result[
'login'] );
43 $this->assertEquals(
"NeedToken", $result[
'login'][
'result'] );
44 $token = $result[
'login'][
'token'];
49 'lgname' => $userName,
50 'lgpassword' => $password
53 $this->assertArrayHasKey(
"login", $result );
54 $this->assertArrayHasKey(
"result", $result[
'login'] );
55 $this->assertEquals(
"Success", $result[
'login'][
'result'] );
57 $this->assertNotEmpty( $session,
'API Login must return a session' );
73 $this->assertContains(
'The "token" parameter must be set',
$e->getMessage() );
75 $this->assertTrue( $exception,
"Got exception" );
86 ], $session, self::$users[
'uploader']->getUser() );
90 'One of the parameters "filekey", "file" and "url" is required.',
94 $this->assertTrue( $exception,
"Got exception" );
102 $mimeType =
'image/png';
106 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
107 }
catch ( Exception
$e ) {
108 $this->markTestIncomplete(
$e->getMessage() );
112 $filePath = $filePaths[0];
113 $fileSize = filesize( $filePath );
114 $fileName = basename( $filePath );
119 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
120 $this->markTestIncomplete(
"Couldn't upload file!\n" );
124 'action' =>
'upload',
125 'filename' => $fileName,
126 'file' =>
'dummy content',
127 'comment' =>
'dummy comment',
128 'text' =>
"This is the page text for $fileName",
134 self::$users[
'uploader']->getUser() );
138 $this->assertTrue( isset( $result[
'upload'] ) );
139 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
140 $this->assertEquals( $fileSize, (
int)$result[
'upload'][
'imageinfo'][
'size'] );
141 $this->assertEquals( $mimeType, $result[
'upload'][
'imageinfo'][
'mime'] );
142 $this->assertFalse( $exception );
152 $mimeType =
'image/png';
155 $fileName =
"apiTestUploadZeroLength.png";
159 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
160 $this->markTestIncomplete(
"Couldn't upload file!\n" );
164 'action' =>
'upload',
165 'filename' => $fileName,
166 'file' =>
'dummy content',
167 'comment' =>
'dummy comment',
168 'text' =>
"This is the page text for $fileName",
175 $this->assertContains(
'The file you submitted was empty',
$e->getMessage() );
178 $this->assertTrue( $exception );
189 $mimeType =
'image/png';
193 $filePaths = $randomImageGenerator->writeImages( 2, $extension, $this->
getNewTempDirectory() );
194 }
catch ( Exception
$e ) {
195 $this->markTestIncomplete(
$e->getMessage() );
200 $fileName = basename( $filePaths[0] );
207 'action' =>
'upload',
208 'filename' => $fileName,
209 'file' =>
'dummy content',
210 'comment' =>
'dummy comment',
211 'text' =>
"This is the page text for $fileName",
216 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[0] ) ) {
217 $this->markTestIncomplete(
"Couldn't upload file!\n" );
223 self::$users[
'uploader']->getUser() );
227 $this->assertTrue( isset( $result[
'upload'] ) );
228 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
229 $this->assertFalse( $exception );
233 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[1] ) ) {
234 $this->markTestIncomplete(
"Couldn't upload file!\n" );
240 self::$users[
'uploader']->getUser() );
244 $this->assertTrue( isset( $result[
'upload'] ) );
245 $this->assertEquals(
'Warning', $result[
'upload'][
'result'] );
246 $this->assertTrue( isset( $result[
'upload'][
'warnings'] ) );
247 $this->assertTrue( isset( $result[
'upload'][
'warnings'][
'exists'] ) );
248 $this->assertFalse( $exception );
259 $mimeType =
'image/png';
263 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
264 }
catch ( Exception
$e ) {
265 $this->markTestIncomplete(
$e->getMessage() );
269 $fileNames[0] = basename( $filePaths[0] );
270 $fileNames[1] =
"SameContentAs" . $fileNames[0];
280 'action' =>
'upload',
281 'filename' => $fileNames[0],
282 'file' =>
'dummy content',
283 'comment' =>
'dummy comment',
284 'text' =>
"This is the page text for " . $fileNames[0],
287 if ( !$this->
fakeUploadFile(
'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
288 $this->markTestIncomplete(
"Couldn't upload file!\n" );
294 self::$users[
'uploader']->getUser() );
298 $this->assertTrue( isset( $result[
'upload'] ) );
299 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
300 $this->assertFalse( $exception );
304 if ( !$this->
fakeUploadFile(
'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
305 $this->markTestIncomplete(
"Couldn't upload file!\n" );
309 'action' =>
'upload',
310 'filename' => $fileNames[1],
311 'file' =>
'dummy content',
312 'comment' =>
'dummy comment',
313 'text' =>
"This is the page text for " . $fileNames[1],
319 self::$users[
'uploader']->getUser() );
323 $this->assertTrue( isset( $result[
'upload'] ) );
324 $this->assertEquals(
'Warning', $result[
'upload'][
'result'] );
325 $this->assertTrue( isset( $result[
'upload'][
'warnings'] ) );
326 $this->assertTrue( isset( $result[
'upload'][
'warnings'][
'duplicate'] ) );
327 $this->assertFalse( $exception );
339 'wgUser' => self::$users[
'uploader']->getUser(),
343 $mimeType =
'image/png';
347 $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->
getNewTempDirectory() );
348 }
catch ( Exception
$e ) {
349 $this->markTestIncomplete(
$e->getMessage() );
353 $filePath = $filePaths[0];
354 $fileSize = filesize( $filePath );
355 $fileName = basename( $filePath );
360 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
361 $this->markTestIncomplete(
"Couldn't upload file!\n" );
365 'action' =>
'upload',
367 'filename' => $fileName,
368 'file' =>
'dummy content',
369 'comment' =>
'dummy comment',
370 'text' =>
"This is the page text for $fileName",
376 self::$users[
'uploader']->getUser() );
380 $this->assertFalse( $exception );
381 $this->assertTrue( isset( $result[
'upload'] ) );
382 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
383 $this->assertEquals( $fileSize, (
int)$result[
'upload'][
'imageinfo'][
'size'] );
384 $this->assertEquals( $mimeType, $result[
'upload'][
'imageinfo'][
'mime'] );
385 $this->assertTrue( isset( $result[
'upload'][
'filekey'] ) );
386 $this->assertEquals( $result[
'upload'][
'sessionkey'], $result[
'upload'][
'filekey'] );
387 $filekey = $result[
'upload'][
'filekey'];
394 'action' =>
'upload',
395 'filekey' => $filekey,
396 'filename' => $fileName,
397 'comment' =>
'dummy comment',
398 'text' =>
"This is the page text for $fileName, altered",
405 self::$users[
'uploader']->getUser() );
409 $this->assertTrue( isset( $result[
'upload'] ) );
410 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
411 $this->assertFalse( $exception,
"No ApiUsageException exception." );
423 'wgUser' => self::$users[
'uploader']->getUser(),
426 $chunkSize = 1048576;
430 $mimeType =
'image/jpeg';
431 $url =
'http://upload.wikimedia.org/wikipedia/commons/'
432 .
'e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
435 copy( $url, $filePath );
436 }
catch ( Exception
$e ) {
437 $this->markTestIncomplete(
$e->getMessage() );
440 $fileSize = filesize( $filePath );
441 $fileName = basename( $filePath );
448 'action' =>
'upload',
450 'filename' => $fileName,
451 'filesize' => $fileSize,
456 $chunkSessionKey =
false;
459 Wikimedia\suppressWarnings();
460 $handle = fopen( $filePath,
"r" );
461 Wikimedia\restoreWarnings();
463 if ( $handle ===
false ) {
464 $this->markTestIncomplete(
"could not open file: $filePath" );
467 while ( !feof( $handle ) ) {
469 Wikimedia\suppressWarnings();
470 $chunkData = fread( $handle, $chunkSize );
471 Wikimedia\restoreWarnings();
477 if ( !$chunkSessionKey ) {
481 self::$users[
'uploader']->getUser() );
483 $this->markTestIncomplete(
$e->getMessage() );
486 $this->assertTrue( isset( $result[
'upload'] ) );
487 $this->assertTrue( isset( $result[
'upload'][
'filekey'] ) );
489 if ( !isset( $result[
'upload'][
'filekey'] ) ) {
490 $this->markTestIncomplete(
"no filekey provided" );
492 $chunkSessionKey = $result[
'upload'][
'filekey'];
493 $this->assertEquals(
'Continue', $result[
'upload'][
'result'] );
495 $this->assertEquals( $chunkSize, $result[
'upload'][
'offset'] );
496 $resultOffset = $result[
'upload'][
'offset'];
500 $params[
'filekey'] = $chunkSessionKey;
503 $params[
'offset'] += $chunkSize;
505 $this->assertEquals( $resultOffset,
$params[
'offset'] );
509 self::$users[
'uploader']->getUser() );
511 $this->markTestIncomplete(
$e->getMessage() );
514 $this->assertTrue( isset( $result[
'upload'] ) );
515 $this->assertTrue( isset( $result[
'upload'][
'filekey'] ) );
518 if (
$params[
'offset'] + $chunkSize >= $fileSize ) {
519 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
522 $this->assertEquals(
'Continue', $result[
'upload'][
'result'] );
524 $resultOffset = $result[
'upload'][
'offset'];
531 .
" hohoh filesize {$fileSize} info {$result['upload']['imageinfo']['size']}\n\n" );
532 $this->assertEquals( $fileSize, $result[
'upload'][
'imageinfo'][
'size'] );
533 $this->assertEquals( $mimeType, $result[
'upload'][
'imageinfo'][
'mime'] );
534 $this->assertTrue( isset( $result[
'upload'][
'filekey'] ) );
535 $filekey = $result[
'upload'][
'filekey'];
539 'action' =>
'upload',
540 'filekey' => $filekey,
541 'filename' => $fileName,
542 'comment' =>
'dummy comment',
543 'text' =>
"This is the page text for $fileName, altered",
549 self::$users[
'uploader']->getUser() );
553 $this->assertTrue( isset( $result[
'upload'] ) );
554 $this->assertEquals(
'Success', $result[
'upload'][
'result'] );
555 $this->assertFalse( $exception );
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
doApiRequestWithToken(array $params, array $session=null, User $user=null, $tokenType='auto')
Convenience function to access the token parameter of doApiRequest() more succinctly.
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
Abstract class to support upload tests.
clearFakeUploads()
Remove traces of previous fake uploads.
fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData)
deleteFileByContent( $filePath)
Helper function – given a file on the filesystem, find matching content in the db (and associated art...
deleteFileByFileName( $fileName)
Helper function – remove files and associated articles with a particular filename.
fakeUploadFile( $fieldName, $fileName, $type, $filePath)
Fake an upload by dumping the file into temp space, and adding info to $_FILES.
testUploadZeroLength( $session)
@depends testLogin
testUploadStash( $session)
@depends testLogin
testLogin()
Testing login XXX this is a funny way of getting session context.
testUploadSameContent( $session)
@depends testLogin
testUploadRequiresToken( $session)
@depends testLogin
testUploadMissingParams( $session)
@depends testLogin
testUploadSameFileName( $session)
@depends testLogin
testUpload( $session)
@depends testLogin
testUploadChunks( $session)
@depends testLogin
Exception used to abort API execution with an error.
RandomImageGenerator: does what it says on the tin.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
returning false will NOT prevent logging $e