77namespace Core \Command \Preview ;
88
99use OC \Core \Command \Preview \Cleanup ;
10+ use OC \Preview \PreviewService ;
1011use OCP \Files \Folder ;
1112use OCP \Files \IRootFolder ;
1213use OCP \Files \NotFoundException ;
@@ -22,22 +23,27 @@ class CleanupTest extends TestCase {
2223 private LoggerInterface &MockObject $ logger ;
2324 private InputInterface &MockObject $ input ;
2425 private OutputInterface &MockObject $ output ;
26+ private PreviewService &MockObject $ previewService ;
2527 private Cleanup $ repair ;
2628
2729 protected function setUp (): void {
2830 parent ::setUp ();
2931 $ this ->rootFolder = $ this ->createMock (IRootFolder::class);
3032 $ this ->logger = $ this ->createMock (LoggerInterface::class);
33+ $ this ->previewService = $ this ->createMock (PreviewService::class);
3134 $ this ->repair = new Cleanup (
3235 $ this ->rootFolder ,
3336 $ this ->logger ,
37+ $ this ->previewService ,
3438 );
3539
3640 $ this ->input = $ this ->createMock (InputInterface::class);
3741 $ this ->output = $ this ->createMock (OutputInterface::class);
3842 }
3943
4044 public function testCleanup (): void {
45+ $ this ->previewService ->expects ($ this ->once ())->method ('deleteAll ' );
46+
4147 $ previewFolder = $ this ->createMock (Folder::class);
4248 $ previewFolder ->expects ($ this ->once ())
4349 ->method ('isDeletable ' )
@@ -73,6 +79,8 @@ public function testCleanup(): void {
7379 }
7480
7581 public function testCleanupWhenNotDeletable (): void {
82+ $ this ->previewService ->expects ($ this ->once ())->method ('deleteAll ' );
83+
7684 $ previewFolder = $ this ->createMock (Folder::class);
7785 $ previewFolder ->expects ($ this ->once ())
7886 ->method ('isDeletable ' )
@@ -102,6 +110,8 @@ public function testCleanupWhenNotDeletable(): void {
102110
103111 #[\PHPUnit \Framework \Attributes \DataProvider('dataForTestCleanupWithDeleteException ' )]
104112 public function testCleanupWithDeleteException (string $ exceptionClass , string $ errorMessage ): void {
113+ $ this ->previewService ->expects ($ this ->once ())->method ('deleteAll ' );
114+
105115 $ previewFolder = $ this ->createMock (Folder::class);
106116 $ previewFolder ->expects ($ this ->once ())
107117 ->method ('isDeletable ' )
@@ -138,6 +148,8 @@ public static function dataForTestCleanupWithDeleteException(): array {
138148 }
139149
140150 public function testCleanupWithCreateException (): void {
151+ $ this ->previewService ->expects ($ this ->once ())->method ('deleteAll ' );
152+
141153 $ previewFolder = $ this ->createMock (Folder::class);
142154 $ previewFolder ->expects ($ this ->once ())
143155 ->method ('isDeletable ' )
@@ -172,4 +184,16 @@ public function testCleanupWithCreateException(): void {
172184
173185 $ this ->assertEquals (1 , $ this ->repair ->run ($ this ->input , $ this ->output ));
174186 }
187+
188+ public function testCleanupWithPreviewServiceException (): void {
189+ $ this ->previewService ->expects ($ this ->once ())->method ('deleteAll ' )
190+ ->willThrowException (new NotPermittedException ('abc ' ));
191+
192+ $ this ->logger ->expects ($ this ->once ())->method ('error ' )->with ("Previews can't be removed: exception occurred: abc " );
193+
194+ $ this ->rootFolder ->expects ($ this ->never ())
195+ ->method ('get ' );
196+
197+ $ this ->assertEquals (1 , $ this ->repair ->run ($ this ->input , $ this ->output ));
198+ }
175199}
0 commit comments