No Description

CdnManagerTest.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 $testStartDate;
  16. protected $testEndDate;
  17. protected $testGranularity;
  18. protected $testLogDate;
  19. protected $refreshUrl;
  20. protected $refreshDirs;
  21. protected $customDomain;
  22. protected $customDomain2;
  23. protected function setUp()
  24. {
  25. global $testAuth;
  26. $this->cdnManager = new CdnManager($testAuth);
  27. global $timestampAntiLeechEncryptKey;
  28. $this->encryptKey = $timestampAntiLeechEncryptKey;
  29. global $testStartDate;
  30. $this->testStartDate = $testStartDate;
  31. global $testEndDate;
  32. $this->testEndDate = $testEndDate;
  33. global $testGranularity;
  34. $this->testGranularity = $testGranularity;
  35. global $testLogDate;
  36. $this->testLogDate = $testLogDate;
  37. global $customDomain;
  38. $this->refreshUrl = $customDomain . '/sdktest.png';
  39. $this->refreshDirs = $customDomain;
  40. $this->customDomain = $customDomain;
  41. global $customDomain2;
  42. $this->customDomain2 = $customDomain2;
  43. }
  44. public function testRefreshUrls()
  45. {
  46. list($ret, $err) = $this->cdnManager->refreshUrls(array($this->refreshUrl));
  47. $this->assertNull($err);
  48. $this->assertNotNull($ret);
  49. }
  50. public function testRefreshDirs()
  51. {
  52. list($ret, $err) = $this->cdnManager->refreshDirs(array($this->refreshDirs));
  53. $this->assertNull($err);
  54. $this->assertNotNull($ret);
  55. }
  56. public function testRefreshUrlsAndDirs()
  57. {
  58. list($ret, $err) = $this->cdnManager->refreshUrlsAndDirs(array($this->refreshUrl), array($this->refreshDirs));
  59. $this->assertNull($err);
  60. $this->assertNotNull($ret);
  61. }
  62. public function testGetCdnRefreshList()
  63. {
  64. list($ret, $err) = $this->cdnManager->getCdnRefreshList(null, null, null, 'success');
  65. $this->assertNull($err);
  66. $this->assertNotNull($ret);
  67. }
  68. public function testPrefetchUrls()
  69. {
  70. list($ret, $err) = $this->cdnManager->prefetchUrls(array($this->refreshUrl));
  71. $this->assertNull($err);
  72. $this->assertNotNull($ret);
  73. }
  74. public function testGetCdnPrefetchList()
  75. {
  76. list($ret, $err) = $this->cdnManager->getCdnPrefetchList(null, null, 'success');
  77. $this->assertNull($err);
  78. $this->assertNotNull($ret);
  79. }
  80. public function testGetBandwidthData()
  81. {
  82. list($ret, $err) = $this->cdnManager->getBandwidthData(
  83. array($this->customDomain2),
  84. $this->testStartDate,
  85. $this->testEndDate,
  86. $this->testGranularity
  87. );
  88. $this->assertNull($err);
  89. $this->assertNotNull($ret);
  90. }
  91. public function testGetFluxData()
  92. {
  93. list($ret, $err) = $this->cdnManager->getFluxData(
  94. array($this->customDomain2),
  95. $this->testStartDate,
  96. $this->testEndDate,
  97. $this->testGranularity
  98. );
  99. $this->assertNull($err);
  100. $this->assertNotNull($ret);
  101. }
  102. public function testGetCdnLogList()
  103. {
  104. list($ret, $err) = $this->cdnManager->getCdnLogList(array('fake.qiniu.com'), $this->testLogDate);
  105. $this->assertNotNull($err);
  106. $this->assertNull($ret);
  107. }
  108. public function testCreateTimestampAntiLeechUrl()
  109. {
  110. $signUrl = $this->cdnManager->createTimestampAntiLeechUrl($this->refreshUrl, $this->encryptKey, 3600);
  111. $response = Client::get($signUrl);
  112. $this->assertNull($response->error);
  113. $this->assertEquals($response->statusCode, 200);
  114. $signUrl = $this->cdnManager->createTimestampAntiLeechUrl(
  115. $this->refreshUrl . '?qiniu',
  116. $this->encryptKey,
  117. 3600
  118. );
  119. $response = Client::get($signUrl);
  120. $this->assertNull($response->error);
  121. $this->assertEquals($response->statusCode, 200);
  122. }
  123. }