20 require_once
'ApiTestCaseUpload.php';
36 $user = self::$users[
'uploader'];
40 'lgname' =>
$user->username,
41 'lgpassword' =>
$user->password
44 $this->assertArrayHasKey(
"login",
$result );
45 $this->assertArrayHasKey(
"result",
$result[
'login'] );
46 $this->assertEquals(
"NeedToken",
$result[
'login'][
'result'] );
47 $token =
$result[
'login'][
'token'];
52 'lgname' =>
$user->username,
53 'lgpassword' =>
$user->password
56 $this->assertArrayHasKey(
"login",
$result );
57 $this->assertArrayHasKey(
"result",
$result[
'login'] );
58 $this->assertEquals(
"Success",
$result[
'login'][
'result'] );
59 $this->assertArrayHasKey(
'lgtoken',
$result[
'login'] );
61 $this->assertNotEmpty( $session,
'API Login must return a session' );
77 $this->assertEquals(
"The token parameter must be set",
$e->getMessage() );
79 $this->assertTrue( $exception,
"Got exception" );
90 ), $session, self::$users[
'uploader']->
user );
93 $this->assertEquals(
"One of the parameters filekey, file, url, statuskey is required",
96 $this->assertTrue( $exception,
"Got exception" );
104 $mimeType =
'image/png';
108 $filePaths = $randomImageGenerator->writeImages( 1, $extension,
wfTempDir() );
109 }
catch ( Exception
$e ) {
110 $this->markTestIncomplete(
$e->getMessage() );
114 $filePath = $filePaths[0];
115 $fileSize = filesize( $filePath );
116 $fileName = basename( $filePath );
121 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
122 $this->markTestIncomplete(
"Couldn't upload file!\n" );
126 'action' =>
'upload',
127 'filename' => $fileName,
128 'file' =>
'dummy content',
129 'comment' =>
'dummy comment',
130 'text' =>
"This is the page text for $fileName",
136 self::$users[
'uploader']->
user );
140 $this->assertTrue( isset(
$result[
'upload'] ) );
141 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
142 $this->assertEquals( $fileSize, (
int)
$result[
'upload'][
'imageinfo'][
'size'] );
143 $this->assertEquals( $mimeType,
$result[
'upload'][
'imageinfo'][
'mime'] );
144 $this->assertFalse( $exception );
147 $this->deleteFileByFilename( $fileName );
155 $mimeType =
'image/png';
158 $fileName =
"apiTestUploadZeroLength.png";
162 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
163 $this->markTestIncomplete(
"Couldn't upload file!\n" );
167 'action' =>
'upload',
168 'filename' => $fileName,
169 'file' =>
'dummy content',
170 'comment' =>
'dummy comment',
171 'text' =>
"This is the page text for $fileName",
178 $this->assertContains(
'The file you submitted was empty',
$e->getMessage() );
181 $this->assertTrue( $exception );
184 $this->deleteFileByFilename( $fileName );
193 $mimeType =
'image/png';
197 $filePaths = $randomImageGenerator->writeImages( 2, $extension,
wfTempDir() );
198 }
catch ( Exception
$e ) {
199 $this->markTestIncomplete(
$e->getMessage() );
204 $fileName = basename( $filePaths[0] );
211 'action' =>
'upload',
212 'filename' => $fileName,
213 'file' =>
'dummy content',
214 'comment' =>
'dummy comment',
215 'text' =>
"This is the page text for $fileName",
220 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[0] ) ) {
221 $this->markTestIncomplete(
"Couldn't upload file!\n" );
227 self::$users[
'uploader']->
user );
231 $this->assertTrue( isset(
$result[
'upload'] ) );
232 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
233 $this->assertFalse( $exception );
237 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePaths[1] ) ) {
238 $this->markTestIncomplete(
"Couldn't upload file!\n" );
244 self::$users[
'uploader']->
user );
248 $this->assertTrue( isset(
$result[
'upload'] ) );
249 $this->assertEquals(
'Warning',
$result[
'upload'][
'result'] );
250 $this->assertTrue( isset(
$result[
'upload'][
'warnings'] ) );
251 $this->assertTrue( isset(
$result[
'upload'][
'warnings'][
'exists'] ) );
252 $this->assertFalse( $exception );
255 $this->deleteFileByFilename( $fileName );
256 unlink( $filePaths[0] );
257 unlink( $filePaths[1] );
265 $mimeType =
'image/png';
269 $filePaths = $randomImageGenerator->writeImages( 1, $extension,
wfTempDir() );
270 }
catch ( Exception
$e ) {
271 $this->markTestIncomplete(
$e->getMessage() );
275 $fileNames[0] = basename( $filePaths[0] );
276 $fileNames[1] =
"SameContentAs" . $fileNames[0];
286 'action' =>
'upload',
287 'filename' => $fileNames[0],
288 'file' =>
'dummy content',
289 'comment' =>
'dummy comment',
290 'text' =>
"This is the page text for " . $fileNames[0],
293 if ( !$this->
fakeUploadFile(
'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
294 $this->markTestIncomplete(
"Couldn't upload file!\n" );
300 self::$users[
'uploader']->
user );
304 $this->assertTrue( isset(
$result[
'upload'] ) );
305 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
306 $this->assertFalse( $exception );
310 if ( !$this->
fakeUploadFile(
'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
311 $this->markTestIncomplete(
"Couldn't upload file!\n" );
315 'action' =>
'upload',
316 'filename' => $fileNames[1],
317 'file' =>
'dummy content',
318 'comment' =>
'dummy comment',
319 'text' =>
"This is the page text for " . $fileNames[1],
325 self::$users[
'uploader']->
user );
329 $this->assertTrue( isset(
$result[
'upload'] ) );
330 $this->assertEquals(
'Warning',
$result[
'upload'][
'result'] );
331 $this->assertTrue( isset(
$result[
'upload'][
'warnings'] ) );
332 $this->assertTrue( isset(
$result[
'upload'][
'warnings'][
'duplicate'] ) );
333 $this->assertFalse( $exception );
336 $this->deleteFileByFilename( $fileNames[0] );
337 $this->deleteFileByFilename( $fileNames[1] );
338 unlink( $filePaths[0] );
346 'wgUser' => self::$users[
'uploader']->
user,
350 $mimeType =
'image/png';
354 $filePaths = $randomImageGenerator->writeImages( 1, $extension,
wfTempDir() );
355 }
catch ( Exception
$e ) {
356 $this->markTestIncomplete(
$e->getMessage() );
360 $filePath = $filePaths[0];
361 $fileSize = filesize( $filePath );
362 $fileName = basename( $filePath );
367 if ( !$this->
fakeUploadFile(
'file', $fileName, $mimeType, $filePath ) ) {
368 $this->markTestIncomplete(
"Couldn't upload file!\n" );
372 'action' =>
'upload',
374 'filename' => $fileName,
375 'file' =>
'dummy content',
376 'comment' =>
'dummy comment',
377 'text' =>
"This is the page text for $fileName",
383 self::$users[
'uploader']->
user );
387 $this->assertFalse( $exception );
388 $this->assertTrue( isset(
$result[
'upload'] ) );
389 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
390 $this->assertEquals( $fileSize, (
int)
$result[
'upload'][
'imageinfo'][
'size'] );
391 $this->assertEquals( $mimeType,
$result[
'upload'][
'imageinfo'][
'mime'] );
392 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
393 $this->assertEquals(
$result[
'upload'][
'sessionkey'],
$result[
'upload'][
'filekey'] );
394 $filekey =
$result[
'upload'][
'filekey'];
401 'action' =>
'upload',
402 'filekey' => $filekey,
403 'filename' => $fileName,
404 'comment' =>
'dummy comment',
405 'text' =>
"This is the page text for $fileName, altered",
412 self::$users[
'uploader']->
user );
416 $this->assertTrue( isset(
$result[
'upload'] ) );
417 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
418 $this->assertFalse( $exception,
"No UsageException exception." );
421 $this->deleteFileByFilename( $fileName );
430 'wgUser' => self::$users[
'uploader']->
user,
433 $chunkSize = 1048576;
436 $mimeType =
'image/jpeg';
437 $url =
'http://upload.wikimedia.org/wikipedia/commons/e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
438 $filePath =
wfTempDir() .
'/Oberaargletscher_from_Oberaar.jpg';
441 if ( !is_file( $filePath ) ) {
442 copy( $url, $filePath );
444 }
catch ( Exception
$e ) {
445 $this->markTestIncomplete(
$e->getMessage() );
448 $fileSize = filesize( $filePath );
449 $fileName = basename( $filePath );
456 'action' =>
'upload',
458 'filename' => $fileName,
459 'filesize' => $fileSize,
464 $chunkSessionKey =
false;
467 $handle = @fopen( $filePath,
"r" );
468 if ( $handle ===
false ) {
469 $this->markTestIncomplete(
"could not open file: $filePath" );
471 while ( !feof( $handle ) ) {
473 $chunkData = @fread( $handle, $chunkSize );
479 if ( !$chunkSessionKey ) {
483 self::$users[
'uploader']->
user );
485 $this->markTestIncomplete(
$e->getMessage() );
488 $this->assertTrue( isset(
$result[
'upload'] ) );
489 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
491 if ( !isset(
$result[
'upload'][
'filekey'] ) ) {
492 $this->markTestIncomplete(
"no filekey provided" );
494 $chunkSessionKey =
$result[
'upload'][
'filekey'];
495 $this->assertEquals(
'Continue',
$result[
'upload'][
'result'] );
497 $this->assertEquals( $chunkSize,
$result[
'upload'][
'offset'] );
498 $resultOffset =
$result[
'upload'][
'offset'];
502 $params[
'filekey'] = $chunkSessionKey;
504 $params[
'offset'] += $chunkSize;
506 $this->assertEquals( $resultOffset,
$params[
'offset'] );
510 self::$users[
'uploader']->
user );
512 $this->markTestIncomplete(
$e->getMessage() );
515 $this->assertTrue( isset(
$result[
'upload'] ) );
516 $this->assertTrue( isset(
$result[
'upload'][
'filekey'] ) );
519 if (
$params[
'offset'] + $chunkSize >= $fileSize ) {
520 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
523 $this->assertEquals(
'Continue',
$result[
'upload'][
'result'] );
525 $resultOffset =
$result[
'upload'][
'offset'];
531 wfDebug( __METHOD__ .
" 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']->
user );
553 $this->assertTrue( isset(
$result[
'upload'] ) );
554 $this->assertEquals(
'Success',
$result[
'upload'][
'result'] );
555 $this->assertFalse( $exception );
558 $this->deleteFileByFilename( $fileName );