1919use OCP \Files \IRootFolder ;
2020use OCP \Files \NotFoundException ;
2121use OCP \Files \SimpleFS \ISimpleFile ;
22+ use OCP \Files \Storage \ISharedStorage ;
23+ use OCP \Files \Storage \IStorage ;
2224use OCP \Files \StorageNotAvailableException ;
2325use OCP \IConfig ;
2426use OCP \IL10N ;
2527use OCP \IPreview ;
2628use OCP \IRequest ;
2729use OCP \IUser ;
2830use OCP \IUserSession ;
31+ use OCP \Share \IAttributes ;
2932use OCP \Share \IManager ;
33+ use OCP \Share \IShare ;
3034use Psr \Log \LoggerInterface ;
3135use Test \TestCase ;
3236
@@ -173,8 +177,12 @@ public function testGetThumbnailInvalidSize(): void {
173177 }
174178
175179 public function testGetThumbnailInvalidImage (): void {
180+ $ storage = $ this ->createMock (IStorage::class);
181+ $ storage ->method ('instanceOfStorage ' )->with (ISharedStorage::class)->willReturn (false );
182+
176183 $ file = $ this ->createMock (File::class);
177184 $ file ->method ('getId ' )->willReturn (123 );
185+ $ file ->method ('getStorage ' )->willReturn ($ storage );
178186 $ this ->userFolder ->method ('get ' )
179187 ->with ($ this ->equalTo ('unknown.jpg ' ))
180188 ->willReturn ($ file );
@@ -196,9 +204,86 @@ public function testGetThumbnailInvalidPartFile(): void {
196204 $ this ->assertEquals ($ expected , $ this ->apiController ->getThumbnail (10 , 10 , 'unknown.jpg ' ));
197205 }
198206
207+ public function testGetThumbnailSharedNoDownload (): void {
208+ $ attributes = $ this ->createMock (IAttributes::class);
209+ $ attributes ->expects (self ::once ())
210+ ->method ('getAttribute ' )
211+ ->with ('permissions ' , 'download ' )
212+ ->willReturn (false );
213+
214+ $ share = $ this ->createMock (IShare::class);
215+ $ share ->expects (self ::once ())
216+ ->method ('getAttributes ' )
217+ ->willReturn ($ attributes );
218+
219+ $ storage = $ this ->createMock (ISharedStorage::class);
220+ $ storage ->expects (self ::once ())
221+ ->method ('instanceOfStorage ' )
222+ ->with (ISharedStorage::class)
223+ ->willReturn (true );
224+ $ storage ->expects (self ::once ())
225+ ->method ('getShare ' )
226+ ->willReturn ($ share );
227+
228+ $ file = $ this ->createMock (File::class);
229+ $ file ->method ('getId ' )->willReturn (123 );
230+ $ file ->method ('getStorage ' )->willReturn ($ storage );
231+
232+ $ this ->userFolder ->method ('get ' )
233+ ->with ('unknown.jpg ' )
234+ ->willReturn ($ file );
235+
236+ $ this ->preview ->expects ($ this ->never ())
237+ ->method ('getPreview ' );
238+
239+ $ expected = new DataResponse (['message ' => 'File not found. ' ], Http::STATUS_NOT_FOUND );
240+ $ this ->assertEquals ($ expected , $ this ->apiController ->getThumbnail (10 , 10 , 'unknown.jpg ' ));
241+ }
242+
243+ public function testGetThumbnailShared (): void {
244+ $ share = $ this ->createMock (IShare::class);
245+ $ share ->expects (self ::once ())
246+ ->method ('getAttributes ' )
247+ ->willReturn (null );
248+
249+ $ storage = $ this ->createMock (ISharedStorage::class);
250+ $ storage ->expects (self ::once ())
251+ ->method ('instanceOfStorage ' )
252+ ->with (ISharedStorage::class)
253+ ->willReturn (true );
254+ $ storage ->expects (self ::once ())
255+ ->method ('getShare ' )
256+ ->willReturn ($ share );
257+
258+ $ file = $ this ->createMock (File::class);
259+ $ file ->method ('getId ' )->willReturn (123 );
260+ $ file ->method ('getStorage ' )->willReturn ($ storage );
261+
262+ $ this ->userFolder ->method ('get ' )
263+ ->with ($ this ->equalTo ('known.jpg ' ))
264+ ->willReturn ($ file );
265+ $ preview = $ this ->createMock (ISimpleFile::class);
266+ $ preview ->method ('getName ' )->willReturn ('my name ' );
267+ $ preview ->method ('getMTime ' )->willReturn (42 );
268+ $ this ->preview ->expects ($ this ->once ())
269+ ->method ('getPreview ' )
270+ ->with ($ this ->equalTo ($ file ), 10 , 10 , true )
271+ ->willReturn ($ preview );
272+
273+ $ ret = $ this ->apiController ->getThumbnail (10 , 10 , 'known.jpg ' );
274+
275+ $ this ->assertEquals (Http::STATUS_OK , $ ret ->getStatus ());
276+ $ this ->assertInstanceOf (FileDisplayResponse::class, $ ret );
277+ }
278+
199279 public function testGetThumbnail (): void {
280+ $ storage = $ this ->createMock (IStorage::class);
281+ $ storage ->method ('instanceOfStorage ' )->with (ISharedStorage::class)->willReturn (false );
282+
200283 $ file = $ this ->createMock (File::class);
201284 $ file ->method ('getId ' )->willReturn (123 );
285+ $ file ->method ('getStorage ' )->willReturn ($ storage );
286+
202287 $ this ->userFolder ->method ('get ' )
203288 ->with ($ this ->equalTo ('known.jpg ' ))
204289 ->willReturn ($ file );
0 commit comments