2828use OCP \Migration \IRepairStep ;
2929use Test \TestCase ;
3030use OC \Share20 \DefaultShareProvider ;
31+ use OCP \IUserManager ;
32+ use OCP \IGroupManager ;
3133
3234/**
3335 * Tests for repairing invalid shares
@@ -47,6 +49,12 @@ class RepairUnmergedSharesTest extends TestCase {
4749 /** @var int */
4850 private $ lastShareTime ;
4951
52+ /** @var IUserManager */
53+ private $ userManager ;
54+
55+ /** @var IGroupManager */
56+ private $ groupManager ;
57+
5058 protected function setUp () {
5159 parent ::setUp ();
5260
@@ -61,45 +69,14 @@ protected function setUp() {
6169 $ this ->connection = \OC ::$ server ->getDatabaseConnection ();
6270 $ this ->deleteAllShares ();
6371
64- $ user1 = $ this ->getMock ('\OCP\IUser ' );
65- $ user1 ->expects ($ this ->any ())
66- ->method ('getUID ' )
67- ->will ($ this ->returnValue ('user1 ' ));
68-
69- $ user2 = $ this ->getMock ('\OCP\IUser ' );
70- $ user2 ->expects ($ this ->any ())
71- ->method ('getUID ' )
72- ->will ($ this ->returnValue ('user2 ' ));
73-
74- $ users = [$ user1 , $ user2 ];
75-
76- $ groupManager = $ this ->getMock ('\OCP\IGroupManager ' );
77- $ groupManager ->expects ($ this ->any ())
78- ->method ('getUserGroupIds ' )
79- ->will ($ this ->returnValueMap ([
80- // owner
81- [$ user1 , ['samegroup1 ' , 'samegroup2 ' ]],
82- // recipient
83- [$ user2 , ['recipientgroup1 ' , 'recipientgroup2 ' ]],
84- ]));
85-
86- $ userManager = $ this ->getMock ('\OCP\IUserManager ' );
87- $ userManager ->expects ($ this ->once ())
88- ->method ('countUsers ' )
89- ->will ($ this ->returnValue ([2 ]));
90- $ userManager ->expects ($ this ->once ())
91- ->method ('callForAllUsers ' )
92- ->will ($ this ->returnCallback (function (\Closure $ closure ) use ($ users ) {
93- foreach ($ users as $ user ) {
94- $ closure ($ user );
95- }
96- }));
72+ $ this ->userManager = $ this ->getMock ('\OCP\IUserManager ' );
73+ $ this ->groupManager = $ this ->getMock ('\OCP\IGroupManager ' );
9774
9875 // used to generate incremental stimes
9976 $ this ->lastShareTime = time ();
10077
10178 /** @var \OCP\IConfig $config */
102- $ this ->repair = new RepairUnmergedShares ($ config , $ this ->connection , $ userManager , $ groupManager );
79+ $ this ->repair = new RepairUnmergedShares ($ config , $ this ->connection , $ this -> userManager , $ this -> groupManager );
10380 }
10481
10582 protected function tearDown () {
@@ -510,6 +487,38 @@ public function sharesDataProvider() {
510487 * @dataProvider sharesDataProvider
511488 */
512489 public function testMergeGroupShares ($ shares , $ expectedShares ) {
490+ $ user1 = $ this ->getMock ('\OCP\IUser ' );
491+ $ user1 ->expects ($ this ->any ())
492+ ->method ('getUID ' )
493+ ->will ($ this ->returnValue ('user1 ' ));
494+
495+ $ user2 = $ this ->getMock ('\OCP\IUser ' );
496+ $ user2 ->expects ($ this ->any ())
497+ ->method ('getUID ' )
498+ ->will ($ this ->returnValue ('user2 ' ));
499+
500+ $ users = [$ user1 , $ user2 ];
501+
502+ $ this ->groupManager ->expects ($ this ->any ())
503+ ->method ('getUserGroupIds ' )
504+ ->will ($ this ->returnValueMap ([
505+ // owner
506+ [$ user1 , ['samegroup1 ' , 'samegroup2 ' ]],
507+ // recipient
508+ [$ user2 , ['recipientgroup1 ' , 'recipientgroup2 ' ]],
509+ ]));
510+
511+ $ this ->userManager ->expects ($ this ->once ())
512+ ->method ('countUsers ' )
513+ ->will ($ this ->returnValue ([2 ]));
514+ $ this ->userManager ->expects ($ this ->once ())
515+ ->method ('callForAllUsers ' )
516+ ->will ($ this ->returnCallback (function (\Closure $ closure ) use ($ users ) {
517+ foreach ($ users as $ user ) {
518+ $ closure ($ user );
519+ }
520+ }));
521+
513522 $ shareIds = [];
514523
515524 foreach ($ shares as $ share ) {
@@ -536,5 +545,30 @@ public function testMergeGroupShares($shares, $expectedShares) {
536545 $ this ->assertEquals ($ expectedShare [1 ], $ share ['permissions ' ]);
537546 }
538547 }
548+
549+ public function duplicateNamesProvider () {
550+ return [
551+ // matching
552+ ['filename (1).txt ' , true ],
553+ ['folder (2) ' , true ],
554+ ['filename (1)(2).txt ' , true ],
555+ // non-matching
556+ ['filename ().txt ' , false ],
557+ ['folder () ' , false ],
558+ ['folder (1x) ' , false ],
559+ ['folder (x1) ' , false ],
560+ ['filename (a) ' , false ],
561+ ['filename (1). ' , false ],
562+ ['filename (1).txt.txt ' , false ],
563+ ['filename (1)..txt ' , false ],
564+ ];
565+ }
566+
567+ /**
568+ * @dataProvider duplicateNamesProvider
569+ */
570+ public function testIsPotentialDuplicateName ($ name , $ expectedResult ) {
571+ $ this ->assertEquals ($ expectedResult , $ this ->invokePrivate ($ this ->repair , 'isPotentialDuplicateName ' , [$ name ]));
572+ }
539573}
540574
0 commit comments