2929use OCP \Files \Config \IUserMountCache ;
3030use OCP \Files \IRootFolder ;
3131use OCP \Files \NotFoundException ;
32+ use OCP \IConfig ;
3233use OCP \ILogger ;
3334use OCP \Share ;
3435use OCP \Share \IShareHelper ;
@@ -63,8 +64,10 @@ class FilesHooksTest extends TestCase {
6364 protected $ shareHelper ;
6465 /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
6566 protected $ urlGenerator ;
66- /** @var IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
67+ /** @var IUserMountCache|MockObject */
6768 protected $ userMountCache ;
69+ /** @var IConfig|MockObject */
70+ protected $ config ;
6871
6972 protected function setUp (): void {
7073 parent ::setUp ();
@@ -78,6 +81,7 @@ protected function setUp(): void {
7881 $ this ->shareHelper = $ this ->createMock (IShareHelper::class);
7982 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
8083 $ this ->userMountCache = $ this ->createMock (IUserMountCache::class);
84+ $ this ->config = $ this ->createMock (IConfig::class);
8185
8286 $ this ->filesHooks = $ this ->getFilesHooks ();
8387 }
@@ -112,7 +116,8 @@ protected function getFilesHooks(array $mockedMethods = [], $user = 'user') {
112116 $ this ->urlGenerator ,
113117 $ logger ,
114118 $ currentUser ,
115- $ this ->userMountCache
119+ $ this ->userMountCache ,
120+ $ this ->config ,
116121 ])
117122 ->setMethods ($ mockedMethods )
118123 ->getMock ();
@@ -130,7 +135,8 @@ protected function getFilesHooks(array $mockedMethods = [], $user = 'user') {
130135 $ this ->urlGenerator ,
131136 $ logger ,
132137 $ currentUser ,
133- $ this ->userMountCache
138+ $ this ->userMountCache ,
139+ $ this ->config
134140 );
135141 }
136142
@@ -240,6 +246,39 @@ public function dataAddNotificationsForFileAction() {
240246 [['user ' , 'user1 ' , 'user2 ' ], 'stream ' , Files::TYPE_SHARE_RESTORED , ['user ' => true ]],
241247 [['user ' , 'user1 ' , 'user2 ' ], 'email ' , Files::TYPE_SHARE_RESTORED , ['user ' => 42 ]],
242248 ],
249+ 'mountcache_used ' => false ,
250+ [
251+ 'user ' => [
252+ 'subject ' => 'restored_self ' ,
253+ 'subject_params ' => [[1337 => '/user/files/path ' ]],
254+ 'path ' => '/user/files/path ' ,
255+ 'stream ' => true ,
256+ 'email ' => 42 ,
257+ ],
258+ ],
259+ ],
260+ [
261+ [
262+ [['user ' , 'user1 ' , 'user2 ' ], 'stream ' , Files::TYPE_SHARE_RESTORED , ['user1 ' => true ]],
263+ [['user ' , 'user1 ' , 'user2 ' ], 'email ' , Files::TYPE_SHARE_RESTORED , []],
264+ ],
265+ 'mountcache_used ' => false ,
266+ [
267+ 'user1 ' => [
268+ 'subject ' => 'restored_by ' ,
269+ 'subject_params ' => [[1337 => '/user1/files/path ' ], 'user ' ],
270+ 'path ' => '/user1/files/path ' ,
271+ 'stream ' => true ,
272+ 'email ' => 0 ,
273+ ],
274+ ],
275+ ],
276+ [
277+ [
278+ [['user ' , 'user1 ' , 'user2 ' ], 'stream ' , Files::TYPE_SHARE_RESTORED , ['user ' => true ]],
279+ [['user ' , 'user1 ' , 'user2 ' ], 'email ' , Files::TYPE_SHARE_RESTORED , ['user ' => 42 ]],
280+ ],
281+ 'mountcache_used ' => true ,
243282 [
244283 'user ' => [
245284 'subject ' => 'restored_self ' ,
@@ -255,6 +294,7 @@ public function dataAddNotificationsForFileAction() {
255294 [['user ' , 'user1 ' , 'user2 ' ], 'stream ' , Files::TYPE_SHARE_RESTORED , ['user1 ' => true ]],
256295 [['user ' , 'user1 ' , 'user2 ' ], 'email ' , Files::TYPE_SHARE_RESTORED , []],
257296 ],
297+ 'mountcache_used ' => true ,
258298 [
259299 'user1 ' => [
260300 'subject ' => 'restored_by ' ,
@@ -272,6 +312,7 @@ public function dataAddNotificationsForFileAction() {
272312 * @dataProvider dataAddNotificationsForFileAction
273313 *
274314 * @param array $filterUsers
315+ * @param bool $mountCacheUsed
275316 * @param array $addNotifications
276317 */
277318 public function testAddNotificationsForFileAction ($ filterUsers , $ addNotifications ) {
@@ -298,37 +339,47 @@ public function testAddNotificationsForFileAction($filterUsers, $addNotification
298339 'remotes ' => [],
299340 ]);
300341
301- $ this ->userMountCache ->expects ($ this ->once ())
302- ->method ('getMountsForFileId ' )
303- ->willReturn ([
304- new CachedMountFileInfo (
305- $ this ->getUserMock ('user ' ),
306- 1 ,
307- 1 ,
308- '/user/files/ ' ,
309- null ,
310- '' ,
311- 'path '
312- ),
313- new CachedMountFileInfo (
314- $ this ->getUserMock ('user1 ' ),
315- 1 ,
316- 1 ,
317- '/user1/files/ ' ,
318- null ,
319- '' ,
320- 'path '
321- ),
322- new CachedMountFileInfo (
323- $ this ->getUserMock ('user2 ' ),
324- 1 ,
325- 1 ,
326- '/user2/files/ ' ,
327- null ,
328- '' ,
329- 'path '
330- )
331- ]);
342+ $ this ->config ->expects ($ this ->once ())
343+ ->method ('getSystemValueBool ' )
344+ ->with ('activity_use_cached_mountpoints ' , false )
345+ ->willReturn ($ mountCacheUsed );
346+
347+ if ($ mountCacheUsed ) {
348+ $ this ->userMountCache ->expects ($ this ->once ())
349+ ->method ('getMountsForFileId ' )
350+ ->willReturn ([
351+ new CachedMountFileInfo (
352+ $ this ->getUserMock ('user ' ),
353+ 1 ,
354+ 1 ,
355+ '/user/files/ ' ,
356+ null ,
357+ '' ,
358+ 'path '
359+ ),
360+ new CachedMountFileInfo (
361+ $ this ->getUserMock ('user1 ' ),
362+ 1 ,
363+ 1 ,
364+ '/user1/files/ ' ,
365+ null ,
366+ '' ,
367+ 'path '
368+ ),
369+ new CachedMountFileInfo (
370+ $ this ->getUserMock ('user2 ' ),
371+ 1 ,
372+ 1 ,
373+ '/user2/files/ ' ,
374+ null ,
375+ '' ,
376+ 'path '
377+ )
378+ ]);
379+ } else {
380+ $ this ->userMountCache ->expects ($ this ->never ())
381+ ->method ('getMountsForFileId ' );
382+ }
332383
333384 $ this ->settings ->expects ($ this ->exactly (2 ))
334385 ->method ('filterUsersBySetting ' )
0 commit comments