@@ -183,7 +183,9 @@ public function testRemoveMounts(): void {
183183 $ this ->eventDispatcher
184184 ->expects ($ this ->exactly (2 ))
185185 ->method ('dispatchTyped ' )
186- ->with ($ this ->callback (function (UserMountAddedEvent |UserMountRemovedEvent $ event ) use (&$ operation ) {
186+ ->with ($ this ->callback (function (
187+ UserMountAddedEvent |UserMountRemovedEvent $ event ,
188+ ) use (&$ operation ) {
187189 return match (++$ operation ) {
188190 1 => $ event instanceof UserMountAddedEvent && $ event ->mountPoint ->getMountPoint () === '/asd/ ' ,
189191 2 => $ event instanceof UserMountRemovedEvent && $ event ->mountPoint ->getMountPoint () === '/asd/ ' ,
@@ -214,7 +216,9 @@ public function testChangeMounts(): void {
214216 $ this ->eventDispatcher
215217 ->expects ($ this ->exactly (3 ))
216218 ->method ('dispatchTyped ' )
217- ->with ($ this ->callback (function (UserMountAddedEvent |UserMountRemovedEvent $ event ) use (&$ operation ) {
219+ ->with ($ this ->callback (function (
220+ UserMountAddedEvent |UserMountRemovedEvent $ event ,
221+ ) use (&$ operation ) {
218222 return match (++$ operation ) {
219223 1 => $ event instanceof UserMountAddedEvent && $ event ->mountPoint ->getMountPoint () === '/bar/ ' ,
220224 2 => $ event instanceof UserMountAddedEvent && $ event ->mountPoint ->getMountPoint () === '/foo/ ' ,
@@ -250,7 +254,9 @@ public function testChangeMountId(): void {
250254 $ this ->eventDispatcher
251255 ->expects ($ this ->exactly (2 ))
252256 ->method ('dispatchTyped ' )
253- ->with ($ this ->callback (function (UserMountAddedEvent |UserMountUpdatedEvent $ event ) use (&$ operation ) {
257+ ->with ($ this ->callback (function (
258+ UserMountAddedEvent |UserMountUpdatedEvent $ event ,
259+ ) use (&$ operation ) {
254260 return match (++$ operation ) {
255261 1 => $ event instanceof UserMountAddedEvent && $ event ->mountPoint ->getMountPoint () === '/foo/ ' ,
256262 2 => $ event instanceof UserMountUpdatedEvent && $ event ->oldMountPoint ->getMountId () === null && $ event ->newMountPoint ->getMountId () === 1 ,
@@ -611,12 +617,59 @@ public function testChangedSameRootId(): void {
611617
612618 $ this ->cache ->flush ();
613619 $ cached = $ this ->cache ->getMountsForUser ($ user );
614- usort ($ cached , fn (ICachedMountInfo $ a , ICachedMountInfo $ b ) => $ a ->getMountPoint () <=> $ b ->getMountPoint ());
620+ usort ($ cached , fn (ICachedMountInfo $ a , ICachedMountInfo $ b ,
621+ ) => $ a ->getMountPoint () <=> $ b ->getMountPoint ());
615622
616- $ mountPoints = array_map (fn (ICachedMountInfo $ mountInfo ) => $ mountInfo ->getMountPoint (), $ cached );
623+ $ mountPoints = array_map (fn (ICachedMountInfo $ mountInfo ,
624+ ) => $ mountInfo ->getMountPoint (), $ cached );
617625 $ this ->assertEquals (['/asd/ ' , '/asd2/ ' ], $ mountPoints );
618626
619- $ mountIds = array_map (fn (ICachedMountInfo $ mountInfo ) => $ mountInfo ->getMountId (), $ cached );
627+ $ mountIds = array_map (fn (ICachedMountInfo $ mountInfo ,
628+ ) => $ mountInfo ->getMountId (), $ cached );
620629 $ this ->assertEquals ([null , 1 ], $ mountIds );
621630 }
631+
632+ public function testGetMountForPath (): void {
633+ $ user = $ this ->userManager ->get ('u1 ' );
634+
635+ [$ storage ] = $ this ->getStorage (10 );
636+ $ mount1 = new MountPoint ($ storage , '/asd/ ' );
637+ $ mount2 = new MountPoint ($ storage , '/asd/foo ' );
638+
639+ $ this ->cache ->registerMounts ($ user , [$ mount1 , $ mount2 ]);
640+ $ this ->cache ->flush ();
641+
642+ $ this ->assertEquals ('/asd/ ' , $ this ->cache ->getMountForPath ($ user , '/asd/bar/ ' )->getMountPoint ());
643+ $ this ->assertEquals ('/asd/ ' , $ this ->cache ->getMountForPath ($ user , '/asd/ ' )->getMountPoint ());
644+ $ this ->assertEquals ('/asd/foo/ ' , $ this ->cache ->getMountForPath ($ user , '/asd/foo/bar/ ' )->getMountPoint ());
645+ $ this ->assertEquals ('/asd/foo/ ' , $ this ->cache ->getMountForPath ($ user , '/asd/foo/ ' )->getMountPoint ());
646+ }
647+
648+ public function testGetMountsInPath (): void {
649+ $ user = $ this ->userManager ->get ('u1 ' );
650+
651+ [$ storage ] = $ this ->getStorage (10 );
652+ $ mount1 = new MountPoint ($ storage , '/asd/ ' );
653+ $ mount2 = new MountPoint ($ storage , '/asd/foo/ ' );
654+ $ mount3 = new MountPoint ($ storage , '/asd/foo/bar/ ' );
655+
656+ $ this ->cache ->registerMounts ($ user , [$ mount1 , $ mount2 , $ mount3 ]);
657+ $ this ->cache ->flush ();
658+
659+ $ getMountPaths = function (string $ path ) use ($ user ) {
660+ $ mountPoints = array_values (
661+ array_map (
662+ fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (),
663+ $ this ->cache ->getMountsInPath ($ user , $ path )
664+ )
665+ );
666+ sort ($ mountPoints );
667+ return $ mountPoints ;
668+ };
669+
670+ $ this ->assertEquals (['/asd/foo/ ' , '/asd/foo/bar/ ' ], $ getMountPaths ('/asd/ ' ));
671+ $ this ->assertEquals ([], $ getMountPaths ('/asd/foo/bar/ ' ));
672+ $ this ->assertEquals (['/asd/foo/bar/ ' ], $ getMountPaths ('/asd/foo/ ' ));
673+ $ this ->assertEquals ([], $ getMountPaths ('/asd/bar/ ' ));
674+ }
622675}
0 commit comments