55use App \Coding \Disk ;
66use App \Coding \Wiki ;
77use Confluence \Content ;
8+ use Illuminate \Support \Facades \File ;
89use LaravelFans \Confluence \Facades \Confluence ;
910use Mockery \MockInterface ;
1011use Tests \TestCase ;
@@ -180,7 +181,8 @@ public function testHandleConfluenceHtmlSuccess()
180181 $ this ->instance (Disk::class, $ mockDisk );
181182 $ mockDisk ->shouldReceive ('uploadAttachments ' )->times (4 )->andReturn ([]);
182183
183- $ this ->artisan ('wiki:import ' , ['--save-markdown ' => true ])
184+ File::delete ($ this ->dataDir . '/confluence/space1/success.log ' );
185+ $ this ->artisan ('wiki:import ' , ['--save-markdown ' => true , '--continue ' => true ])
184186 ->expectsQuestion ('数据来源? ' , 'Confluence ' )
185187 ->expectsQuestion ('数据类型? ' , 'HTML ' )
186188 ->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , $ this ->dataDir . 'confluence/space1/ ' )
@@ -207,6 +209,11 @@ public function testHandleConfluenceHtmlSuccess()
207209 unlink ($ this ->dataDir . '/confluence/space1/65591.md ' );
208210 unlink ($ this ->dataDir . '/confluence/space1/attachment-demo_65615.md ' );
209211 unlink ($ this ->dataDir . '/confluence/space1/text-demo_65601.md ' );
212+ $ log = "image-demo_65619.html = 27 \n"
213+ . "65591.html = 27 \n"
214+ . "attachment-demo_65615.html = 27 \n"
215+ . "text-demo_65601.html = 27 \n" ;
216+ $ this ->assertEquals ($ log , file_get_contents ($ this ->dataDir . '/confluence/space1/success.log ' ));
210217 }
211218
212219 public function testAskNothing ()
@@ -299,4 +306,58 @@ public function testHandleConfluenceSingleHtmlSuccess()
299306 ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
300307 ->assertExitCode (0 );
301308 }
309+
310+ public function testHandleConfluenceHtmlContinueSuccess ()
311+ {
312+ $ this ->setConfig ();
313+
314+ // 注意:不能使用 partialMock
315+ // https://laracasts.com/discuss/channels/testing/this-partialmock-doesnt-call-the-constructor
316+ $ mock = \Mockery::mock (Wiki::class, [])->makePartial ();
317+ $ this ->instance (Wiki::class, $ mock );
318+
319+ $ mock ->shouldReceive ('createWikiByUploadZip ' )->times (2 )->andReturn (json_decode (
320+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateWikiByZipResponse.json ' ),
321+ true
322+ )['Response ' ]);
323+ $ mock ->shouldReceive ('getImportJobStatus ' )->times (2 )->andReturn (json_decode (
324+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'DescribeImportJobStatusResponse.json ' ),
325+ true
326+ )['Response ' ]['Data ' ]);
327+ $ mock ->shouldReceive ('updateTitle ' )->times (2 )->andReturn (true );
328+
329+
330+ $ mockDisk = \Mockery::mock (Disk::class, [])->makePartial ();
331+ $ this ->instance (Disk::class, $ mockDisk );
332+ $ mockDisk ->shouldReceive ('uploadAttachments ' )->times (2 )->andReturn ([]);
333+
334+ $ log = "image-demo_65619.html = 27 \n"
335+ . "65591.html = 27 \n" ;
336+ file_put_contents ($ this ->dataDir . '/confluence/space1/success.log ' , $ log );
337+ $ this ->artisan ('wiki:import ' , ['--continue ' => true ])
338+ ->expectsQuestion ('数据来源? ' , 'Confluence ' )
339+ ->expectsQuestion ('数据类型? ' , 'HTML ' )
340+ ->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , $ this ->dataDir . 'confluence/space1/ ' )
341+ ->expectsOutput ('空间名称:空间 1 ' )
342+ ->expectsOutput ('空间标识:space1 ' )
343+ ->expectsOutput ('发现 3 个一级页面 ' )
344+ ->expectsOutput ("开始导入 CODING: " )
345+ ->expectsOutput ('页面不存在: ' . $ this ->dataDir . 'confluence/space1/not-found.html ' )
346+ ->expectsOutput ('断点续传,跳过页面:image-demo_65619.html ' )
347+ ->expectsOutput ('断点续传,跳过页面:65591.html ' )
348+ ->expectsOutput ('发现 2 个子页面 ' )
349+ ->expectsOutput ('标题:Attachment Demo ' )
350+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
351+ ->expectsOutput ('标题:Text Demo ' )
352+ ->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
353+ ->expectsOutput ('报错信息汇总: ' )
354+ ->expectsOutput ('页面不存在: ' . $ this ->dataDir . 'confluence/space1/not-found.html ' )
355+ ->assertExitCode (1 );
356+ $ log = "image-demo_65619.html = 27 \n"
357+ . "65591.html = 27 \n"
358+ . "attachment-demo_65615.html = 27 \n"
359+ . "text-demo_65601.html = 27 \n" ;
360+ $ this ->assertEquals ($ log , file_get_contents ($ this ->dataDir . '/confluence/space1/success.log ' ));
361+ unlink ($ this ->dataDir . '/confluence/space1/success.log ' );
362+ }
302363}
0 commit comments