CdnManagerTest.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: wf
  5. * Date: 2017/6/21
  6. * Time: AM8:46
  7. */
  8. namespace Qiniu\Tests;
  9. use Qiniu\Cdn\CdnManager;
  10. use Qiniu\Http\Client;
  11. class CdnManagerTest extends \PHPUnit_Framework_TestCase
  12. {
  13. protected $cdnManager;
  14. protected $encryptKey;
  15. protected $imgUrl;
  16. protected function setUp()
  17. {
  18. global $timestampAntiLeechEncryptKey;
  19. global $customDomain;
  20. global $testAuth;
  21. $this->cdnManager = new CdnManager($testAuth);
  22. $this->encryptKey = $timestampAntiLeechEncryptKey;
  23. $this->imgUrl = $customDomain . '/24.jpg';
  24. }
  25. public function testCreateTimestampAntiLeechUrl()
  26. {
  27. $signUrl = $this->cdnManager->createTimestampAntiLeechUrl($this->imgUrl, $this->encryptKey, 3600);
  28. $response = Client::get($signUrl);
  29. $this->assertEquals($response->statusCode, 200);
  30. $this->assertNull($response->error);
  31. $url2 = $this->imgUrl . '?imageInfo';
  32. $signUrl2 = $this->cdnManager->createTimestampAntiLeechUrl($url2, $this->encryptKey, 3600);
  33. $response = Client::get($signUrl2);
  34. $imgInfo = $response->json();
  35. $this->assertEquals($response->statusCode, 200);
  36. $this->assertEquals($imgInfo['size'], 2196145);
  37. $this->assertNull($response->error);
  38. }
  39. }