5
5
use App \Coding \Disk ;
6
6
use App \Coding \Wiki ;
7
7
use Confluence \Content ;
8
+ use Illuminate \Support \Facades \File ;
8
9
use LaravelFans \Confluence \Facades \Confluence ;
9
10
use Mockery \MockInterface ;
10
11
use Tests \TestCase ;
@@ -180,7 +181,8 @@ public function testHandleConfluenceHtmlSuccess()
180
181
$ this ->instance (Disk::class, $ mockDisk );
181
182
$ mockDisk ->shouldReceive ('uploadAttachments ' )->times (4 )->andReturn ([]);
182
183
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 ])
184
186
->expectsQuestion ('数据来源? ' , 'Confluence ' )
185
187
->expectsQuestion ('数据类型? ' , 'HTML ' )
186
188
->expectsQuestion ('空间导出的 HTML zip 文件路径 ' , $ this ->dataDir . 'confluence/space1/ ' )
@@ -207,6 +209,11 @@ public function testHandleConfluenceHtmlSuccess()
207
209
unlink ($ this ->dataDir . '/confluence/space1/65591.md ' );
208
210
unlink ($ this ->dataDir . '/confluence/space1/attachment-demo_65615.md ' );
209
211
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 ' ));
210
217
}
211
218
212
219
public function testAskNothing ()
@@ -299,4 +306,58 @@ public function testHandleConfluenceSingleHtmlSuccess()
299
306
->expectsOutput ('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
300
307
->assertExitCode (0 );
301
308
}
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
+ }
302
363
}
0 commit comments