FormUpTest.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 testFile()
  35. {
  36. $key = 'formPutFile';
  37. $token = $this->auth->uploadToken($this->bucketName, $key);
  38. list($ret, $error) = FormUploader::putFile($token, $key, __file__, $this->cfg, null, 'text/plain', null);
  39. $this->assertNull($error);
  40. $this->assertNotNull($ret['hash']);
  41. }
  42. public function testFile2()
  43. {
  44. $key = 'formPutFile';
  45. $token = $this->auth->uploadToken($this->bucketName, $key);
  46. $upManager = new UploadManager();
  47. list($ret, $error) = $upManager->putFile($token, $key, __file__, null, 'text/plain', null);
  48. $this->assertNull($error);
  49. $this->assertNotNull($ret['hash']);
  50. }
  51. }