@@ -15,26 +15,112 @@ class CdnManagerTest extends \PHPUnit_Framework_TestCase
1515{
1616 protected $ cdnManager ;
1717 protected $ encryptKey ;
18- protected $ imgUrl ;
18+ protected $ testStartDate ;
19+ protected $ testEndDate ;
20+ protected $ testGranularity ;
21+ protected $ testLogDate ;
22+ protected $ refreshUrl ;
23+ protected $ refreshDirs ;
24+ protected $ customDomain ;
25+ protected $ customDomain2 ;
1926
2027 protected function setUp ()
2128 {
22- global $ timestampAntiLeechEncryptKey ;
23- global $ customDomain ;
2429 global $ testAuth ;
25-
2630 $ this ->cdnManager = new CdnManager ($ testAuth );
31+
32+ global $ timestampAntiLeechEncryptKey ;
2733 $ this ->encryptKey = $ timestampAntiLeechEncryptKey ;
28- $ this ->imgUrl = $ customDomain . '/sdktest.png ' ;
34+
35+ global $ testStartDate ;
36+ $ this ->testStartDate = $ testStartDate ;
37+
38+ global $ testEndDate ;
39+ $ this ->testEndDate = $ testEndDate ;
40+
41+ global $ testGranularity ;
42+ $ this ->testGranularity = $ testGranularity ;
43+
44+ global $ testLogDate ;
45+ $ this ->testLogDate = $ testLogDate ;
46+
47+ global $ customDomain ;
48+ $ this ->refreshUrl = $ customDomain . '/sdktest.png ' ;
49+ $ this ->refreshDirs = $ customDomain ;
50+ $ this ->customDomain = $ customDomain ;
51+
52+ global $ customDomain2 ;
53+ $ this ->customDomain2 = $ customDomain2 ;
2954 }
3055
31- public function testCreateTimestampAntiLeechUrl ()
56+ public function testRefreshUrls ()
3257 {
58+ list ($ ret , $ err ) = $ this ->cdnManager ->refreshUrls (array ($ this ->refreshUrl ));
59+ $ this ->assertNotNull ($ ret );
60+ $ this ->assertNull ($ err );
61+ }
3362
34- $ signUrl = $ this ->cdnManager ->createTimestampAntiLeechUrl ($ this ->imgUrl , $ this ->encryptKey , 3600 );
63+ public function testRefreshDirs ()
64+ {
65+ list ($ ret , $ err ) = $ this ->cdnManager ->refreshDirs (array ($ this ->refreshDirs ));
66+ $ this ->assertNotNull ($ ret );
67+ $ this ->assertNull ($ err );
68+ }
69+
70+ public function testRefreshUrlsAndDirs ()
71+ {
72+ list ($ ret , $ err ) = $ this ->cdnManager ->refreshUrlsAndDirs (array ($ this ->refreshUrl ), array ($ this ->refreshDirs ));
73+ $ this ->assertNotNull ($ ret );
74+ $ this ->assertNull ($ err );
75+ }
76+
77+ public function testPrefetchUrls ()
78+ {
79+ list ($ ret , $ err ) = $ this ->cdnManager ->prefetchUrls (array ($ this ->refreshUrl ));
80+ $ this ->assertNotNull ($ ret );
81+ $ this ->assertNull ($ err );
82+ }
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 ->assertNotNull ($ ret );
93+ $ this ->assertNull ($ err );
94+ }
95+
96+ public function testGetFluxData ()
97+ {
98+ list ($ ret , $ err ) = $ this ->cdnManager ->getFluxData (
99+ array ($ this ->customDomain2 ),
100+ $ this ->testStartDate ,
101+ $ this ->testEndDate ,
102+ $ this ->testGranularity
103+ );
104+ $ this ->assertNotNull ($ ret );
105+ $ this ->assertNull ($ err );
106+ }
107+
108+ public function testGetCdnLogList ()
109+ {
110+ list ($ ret , $ err ) = $ this ->cdnManager ->getCdnLogList (array ('fake.qiniu.com ' ), $ this ->testLogDate );
111+ $ this ->assertNull ($ ret );
112+ $ this ->assertNotNull ($ err );
113+ }
114+
115+ public function testCreateTimestampAntiLeechUrl ()
116+ {
117+ $ signUrl = $ this ->cdnManager ->createTimestampAntiLeechUrl ($ this ->refreshUrl , $ this ->encryptKey , 3600 );
118+ $ response = Client::get ($ signUrl );
119+ $ this ->assertEquals ($ response ->statusCode , 200 );
120+ $ this ->assertNull ($ response ->error );
35121
122+ $ signUrl = $ this ->cdnManager ->createTimestampAntiLeechUrl ($ this ->refreshUrl .'?qiniu ' , $ this ->encryptKey , 3600 );
36123 $ response = Client::get ($ signUrl );
37-
38124 $ this ->assertEquals ($ response ->statusCode , 200 );
39125 $ this ->assertNull ($ response ->error );
40126 }
0 commit comments