@@ -133,14 +133,14 @@ public function testHandleConfluenceHtmlFileNotExist()
133133 $ this ->artisan ('wiki:import ' )
134134 ->expectsQuestion ('数据来源? ' , 'Confluence ' )
135135 ->expectsQuestion ('数据类型? ' , 'HTML ' )
136- ->expectsQuestion ('空间导出的 HTML 目录 ' , '~/Downloads/ ' )
136+ ->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , '~/Downloads/ ' )
137137 ->expectsOutput ('文件不存在:~/Downloads/index.html ' )
138138 ->assertExitCode (1 );
139139
140140 $ this ->artisan ('wiki:import ' )
141141 ->expectsQuestion ('数据来源? ' , 'Confluence ' )
142142 ->expectsQuestion ('数据类型? ' , 'HTML ' )
143- ->expectsQuestion ('空间导出的 HTML 目录 ' , '~/Downloads/index.html ' )
143+ ->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , '~/Downloads/index.html ' )
144144 ->expectsOutput ('文件不存在:~/Downloads/index.html ' )
145145 ->assertExitCode (1 );
146146 }
@@ -177,7 +177,7 @@ public function testHandleConfluenceHtmlSuccess()
177177 $ this ->artisan ('wiki:import ' )
178178 ->expectsQuestion ('数据来源? ' , 'Confluence ' )
179179 ->expectsQuestion ('数据类型? ' , 'HTML ' )
180- ->expectsQuestion ('空间导出的 HTML 目录 ' , $ this ->dataDir . 'confluence/space1/ ' )
180+ ->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , $ this ->dataDir . 'confluence/space1/ ' )
181181 ->expectsOutput ('空间名称:空间 1 ' )
182182 ->expectsOutput ('空间标识:space1 ' )
183183 ->expectsOutput ('发现 2 个一级页面 ' )
@@ -210,4 +210,59 @@ public function testAskNothing()
210210 ->expectsOutput ('文件不存在:/dev/null/index.html ' )
211211 ->assertExitCode (1 );
212212 }
213+
214+ public function testHandleConfluenceHtmlZipSuccess ()
215+ {
216+ $ codingToken = $ this ->faker ->md5 ;
217+ config (['coding.token ' => $ codingToken ]);
218+ $ codingTeamDomain = $ this ->faker ->domainWord ;
219+ config (['coding.team_domain ' => $ codingTeamDomain ]);
220+ $ codingProjectUri = $ this ->faker ->slug ;
221+ config (['coding.project_uri ' => $ codingProjectUri ]);
222+
223+ // 注意:不能使用 partialMock
224+ // https://laracasts.com/discuss/channels/testing/this-partialmock-doesnt-call-the-constructor
225+ $ mock = \Mockery::mock (Wiki::class, [])->makePartial ();
226+ $ this ->instance (Wiki::class, $ mock );
227+
228+ $ mock ->shouldReceive ('createWikiByUploadZip ' )->times (5 )->andReturn (json_decode (
229+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateWikiByZipResponse.json ' ),
230+ true
231+ )['Response ' ]);
232+ $ mock ->shouldReceive ('getImportJobStatus ' )->times (5 )->andReturn (json_decode (
233+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'DescribeImportJobStatusResponse.json ' ),
234+ true
235+ )['Response ' ]['Data ' ]);
236+ $ mock ->shouldReceive ('updateWikiTitle ' )->times (5 )->andReturn (true );
237+
238+
239+ $ mockDisk = \Mockery::mock (Disk::class, [])->makePartial ();
240+ $ this ->instance (Disk::class, $ mockDisk );
241+ $ mockDisk ->shouldReceive ('uploadAttachments ' )->times (5 )->andReturn ([]);
242+
243+ $ this ->artisan ('wiki:import ' )
244+ ->expectsQuestion ('数据来源? ' , 'Confluence ' )
245+ ->expectsQuestion ('数据类型? ' , 'HTML ' )
246+ ->expectsQuestion (
247+ '空间导出的 HTML zip 文件路径 ' ,
248+ $ this ->dataDir . 'confluence/Confluence-space-export-231543-81.html.zip '
249+ )
250+ ->expectsOutput ('空间名称:空间 1 ' )
251+ ->expectsOutput ('空间标识:space1 ' )
252+ ->expectsOutput ('发现 1 个一级页面 ' )
253+ ->expectsOutput ("开始导入 CODING: " )
254+ ->expectsOutput ('标题:空间 1 Home ' )
255+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
256+ ->expectsOutput ('发现 2 个子页面 ' )
257+ ->expectsOutput ('标题:hello world ' )
258+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
259+ ->expectsOutput ('发现 2 个子页面 ' )
260+ ->expectsOutput ('标题:hello ' )
261+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
262+ ->expectsOutput ('标题:world ' )
263+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
264+ ->expectsOutput ('标题:你好世界 ' )
265+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
266+ ->assertExitCode (0 );
267+ }
213268}
0 commit comments