10
10
11
11
class CodingTest extends TestCase
12
12
{
13
+ private array $ uploadToken = [
14
+ 'AuthToken ' => '65e5968b5e17d5aaa3f5d33200aca2d1911fe2ad2948b47d899d46e6da1e4 ' ,
15
+ 'Provide ' => 'TENCENT ' ,
16
+ 'SecretId ' => 'AKIDU-VqQm39vRar-ZrHj1UIE5u2gYJ7gWFcG2ThwFNO9eU1HbyQlZp8vVcQ99 ' ,
17
+ 'SecretKey ' => 'clUYSNeg2es16EILsrF6RyCD3ss6uFLX3Xgc= ' ,
18
+ 'UploadLink ' => 'https://coding-net-dev-file-123456.cos.ap-shanghai.myqcloud.com ' ,
19
+ 'UpToken ' => 'EOlMEc2x0xbrFoL9CMy7OqDl5413654938410a360a63207e30dab4655pMKmNJ3t5M-Z8bGt ' ,
20
+ 'Time ' => 1625579588693 ,
21
+ 'Bucket ' => 'coding-net-dev-file-123456 ' ,
22
+ 'AppId ' => '123456 ' ,
23
+ 'Region ' => 'ap-shanghai ' ,
24
+ ];
25
+
13
26
public function testCreateWiki ()
14
27
{
15
28
$ responseBody = file_get_contents ($ this ->dataDir . 'coding/createWikiResponse.json ' );
@@ -74,18 +87,7 @@ public function testCreateUploadToken()
74
87
->willReturn (new Response (200 , [], $ responseBody ));
75
88
$ coding = new Coding ($ clientMock );
76
89
$ result = $ coding ->createUploadToken ($ codingToken , $ codingProjectUri , $ fileName );
77
- $ this ->assertEquals ([
78
- 'AuthToken ' => '65e5968b5e17d5aaa3f5d33200aca2d1911fe2ad2948b47d899d46e6da1e4 ' ,
79
- 'Provide ' => 'TENCENT ' ,
80
- 'SecretId ' => 'AKIDU-VqQm39vRar-ZrHj1UIE5u2gYJ7gWFcG2ThwFNO9eU1HbyQlZp8vVcQ99 ' ,
81
- 'SecretKey ' => 'clUYSNeg2es16EILsrF6RyCD3ss6uFLX3Xgc= ' ,
82
- 'UploadLink ' => 'https://coding-net-dev-file-123456.cos.ap-shanghai.myqcloud.com ' ,
83
- 'UpToken ' => 'EOlMEc2x0xbrFoL9CMy7OqDl5413654938410a360a63207e30dab4655pMKmNJ3t5M-Z8bGt ' ,
84
- 'Time ' => 1625579588693 ,
85
- 'Bucket ' => 'coding-net-dev-file-123456 ' ,
86
- 'AppId ' => '123456 ' ,
87
- 'Region ' => 'ap-shanghai ' ,
88
- ], $ result );
90
+ $ this ->assertEquals ($ this ->uploadToken , $ result );
89
91
}
90
92
91
93
public function testCreateMarkdownZip ()
@@ -107,18 +109,11 @@ public function testCreateMarkdownZip()
107
109
108
110
public function testUpload ()
109
111
{
110
- $ uploadToken = [
111
- 'SecretId ' => 'AKIDU-VqQm39vRar-ZrHj1UIE5u2gYJ7gWFcG2ThwFNO9eU1HbyQlZp8vVcQ99 ' ,
112
- 'SecretKey ' => 'clUYSNeg2es16EILsrF6RyCD3ss6uFLX3Xgc= ' ,
113
- 'Bucket ' => 'coding-net-dev-file-123456 ' ,
114
- 'AppId ' => '123456 ' ,
115
- 'Region ' => 'ap-shanghai ' ,
116
- ];
117
112
$ file = $ this ->faker ->filePath ();
118
113
Storage::fake ('cos ' );
119
114
120
115
$ coding = new Coding ();
121
- $ coding ->upload ($ uploadToken , $ file );
116
+ $ coding ->upload ($ this -> uploadToken , $ file );
122
117
123
118
Storage::disk ('cos ' )->assertExists (basename ($ file ));
124
119
}
@@ -154,4 +149,43 @@ public function testGetImportJobStatus()
154
149
$ result = $ coding ->getImportJobStatus ($ codingToken , $ codingProjectUri , $ jobId );
155
150
$ this ->assertEquals ('success ' , $ result );
156
151
}
152
+
153
+ public function testCreateWikiByZip ()
154
+ {
155
+ $ responseBody = file_get_contents ($ this ->dataDir . 'coding/CreateWikiByZipResponse.json ' );
156
+ $ codingToken = $ this ->faker ->md5 ;
157
+ $ codingProjectUri = $ this ->faker ->slug ;
158
+
159
+ $ data = [
160
+ 'ParentIid ' => 0 ,
161
+ 'FileName ' => $ this ->faker ->word ,
162
+ ];
163
+ $ clientMock = $ this ->getMockBuilder (Client::class)->getMock ();
164
+ $ clientMock ->expects ($ this ->once ())
165
+ ->method ('request ' )
166
+ ->with (
167
+ 'POST ' ,
168
+ 'https://e.coding.net/open-api ' ,
169
+ [
170
+ 'headers ' => [
171
+ 'Accept ' => 'application/json ' ,
172
+ 'Authorization ' => "token $ {codingToken}" ,
173
+ 'Content-Type ' => 'application/json '
174
+ ],
175
+ 'json ' => [
176
+ 'Action ' => 'CreateWikiByZip ' ,
177
+ 'ProjectName ' => $ codingProjectUri ,
178
+ 'ParentIid ' => $ data ['ParentIid ' ],
179
+ 'FileName ' => $ data ['FileName ' ],
180
+ 'Key ' => $ data ['FileName ' ],
181
+ 'Time ' => $ this ->uploadToken ['Time ' ],
182
+ 'AuthToken ' => $ this ->uploadToken ['AuthToken ' ],
183
+ ],
184
+ ]
185
+ )
186
+ ->willReturn (new Response (200 , [], $ responseBody ));
187
+ $ coding = new Coding ($ clientMock );
188
+ $ result = $ coding ->createWikiByZip ($ codingToken , $ codingProjectUri , $ this ->uploadToken , $ data );
189
+ $ this ->assertArrayHasKey ('JobId ' , $ result );
190
+ }
157
191
}
0 commit comments