No Description

FormUpTest.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Qiniu\Tests;
  3. use Qiniu\Storage\FormUploader;
  4. use Qiniu\Storage\UploadManager;
  5. use Qiniu\Config;
  6. class FormUpTest extends \PHPUnit_Framework_TestCase
  7. {
  8. protected $bucketName;
  9. protected $auth;
  10. protected $cfg;
  11. protected function setUp()
  12. {
  13. global $bucketName;
  14. $this->bucketName = $bucketName;
  15. global $testAuth;
  16. $this->auth = $testAuth;
  17. $this->cfg = new Config();
  18. }
  19. public function testData()
  20. {
  21. $token = $this->auth->uploadToken($this->bucketName);
  22. list($ret, $error) = FormUploader::put($token, 'formput', 'hello world', $this->cfg, null, 'text/plain', null);
  23. $this->assertNull($error);
  24. $this->assertNotNull($ret['hash']);
  25. }
  26. public function testData2()
  27. {
  28. $upManager = new UploadManager();
  29. $token = $this->auth->uploadToken($this->bucketName);
  30. list($ret, $error) = $upManager->put($token, 'formput', 'hello world', null, 'text/plain', null);
  31. $this->assertNull($error);
  32. $this->assertNotNull($ret['hash']);
  33. }
  34. public function testDataFailed()
  35. {
  36. $token = $this->auth->uploadToken('fakebucket');
  37. list($ret, $error) = FormUploader::put($token, 'formput', 'hello world', $this->cfg, null, 'text/plain', null);
  38. $this->assertNull($ret);
  39. $this->assertNotNull($error);
  40. }
  41. public function testFile()
  42. {
  43. $key = 'formPutFile';
  44. $token = $this->auth->uploadToken($this->bucketName, $key);
  45. list($ret, $error) = FormUploader::putFile($token, $key, __file__, $this->cfg, null, 'text/plain', null);
  46. $this->assertNull($error);
  47. $this->assertNotNull($ret['hash']);
  48. }
  49. public function testFile2()
  50. {
  51. $key = 'formPutFile';
  52. $token = $this->auth->uploadToken($this->bucketName, $key);
  53. $upManager = new UploadManager();
  54. list($ret, $error) = $upManager->putFile($token, $key, __file__, null, 'text/plain', null);
  55. $this->assertNull($error);
  56. $this->assertNotNull($ret['hash']);
  57. }
  58. public function testFileFailed()
  59. {
  60. $key = 'fakekey';
  61. $token = $this->auth->uploadToken('fakebucket', $key);
  62. list($ret, $error) = FormUploader::putFile($token, $key, __file__, $this->cfg, null, 'text/plain', null);
  63. $this->assertNull($ret);
  64. $this->assertNotNull($error);
  65. }
  66. }