CdnManagerTest.php 4.1 KB

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