@@ -74,13 +74,13 @@ protected function setUp(): void {
7474 $ this ->userSession = $ this ->createMock (IUserSession::class);
7575 $ this ->accountManager = $ this ->createMock (AccountManager::class);
7676 $ this ->logger = $ this ->createMock (ILogger::class);
77-
77+
7878 $ this ->subAdminManager = $ this ->createMock (SubAdmin::class);
7979
8080 $ this ->groupManager
8181 ->method ('getSubAdmin ' )
8282 ->willReturn ($ this ->subAdminManager );
83-
83+
8484 $ this ->api = $ this ->getMockBuilder (GroupsController::class)
8585 ->setConstructorArgs ([
8686 'provisioning_api ' ,
@@ -286,7 +286,7 @@ public function testGetGroupAsSubadmin() {
286286 $ this ->assertEquals (['users ' => ['user1 ' , 'user2 ' ]], $ result ->getData ());
287287 }
288288
289-
289+
290290 public function testGetGroupAsIrrelevantSubadmin () {
291291 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
292292 $ this ->expectExceptionCode (403 );
@@ -331,7 +331,7 @@ public function testGetGroupAsAdmin() {
331331 $ this ->assertEquals (['users ' => ['user1 ' , 'user2 ' ]], $ result ->getData ());
332332 }
333333
334-
334+
335335 public function testGetGroupNonExisting () {
336336 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
337337 $ this ->expectExceptionMessage ('The requested group could not be found ' );
@@ -342,7 +342,7 @@ public function testGetGroupNonExisting() {
342342 $ this ->api ->getGroup ($ this ->getUniqueID ());
343343 }
344344
345-
345+
346346 public function testGetSubAdminsOfGroupsNotExists () {
347347 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
348348 $ this ->expectExceptionMessage ('Group does not exist ' );
@@ -389,7 +389,7 @@ public function testGetSubAdminsOfGroupEmptyList() {
389389 $ this ->assertEquals ([], $ result ->getData ());
390390 }
391391
392-
392+
393393 public function testAddGroupEmptyGroup () {
394394 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
395395 $ this ->expectExceptionMessage ('Invalid group name ' );
@@ -398,7 +398,7 @@ public function testAddGroupEmptyGroup() {
398398 $ this ->api ->addGroup ('' );
399399 }
400400
401-
401+
402402 public function testAddGroupExistingGroup () {
403403 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
404404 $ this ->expectExceptionCode (102 );
@@ -439,15 +439,15 @@ public function testAddGroupWithSpecialChar() {
439439 $ this ->api ->addGroup ('Iñtërnâtiônàlizætiøn ' );
440440 }
441441
442-
442+
443443 public function testDeleteGroupNonExisting () {
444444 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
445445 $ this ->expectExceptionCode (101 );
446446
447447 $ this ->api ->deleteGroup ('NonExistingGroup ' );
448448 }
449449
450-
450+
451451 public function testDeleteAdminGroup () {
452452 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
453453 $ this ->expectExceptionCode (102 );
@@ -479,6 +479,25 @@ public function testDeleteGroup() {
479479 $ this ->api ->deleteGroup ('ExistingGroup ' );
480480 }
481481
482+ public function testDeleteGroupEncoding () {
483+ $ this ->groupManager
484+ ->method ('groupExists ' )
485+ ->with ('ExistingGroup A/B ' )
486+ ->willReturn ('true ' );
487+
488+ $ group = $ this ->createGroup ('ExistingGroup ' );
489+ $ this ->groupManager
490+ ->method ('get ' )
491+ ->with ('ExistingGroup A/B ' )
492+ ->willReturn ($ group );
493+ $ group
494+ ->expects ($ this ->once ())
495+ ->method ('delete ' )
496+ ->willReturn (true );
497+
498+ $ this ->api ->deleteGroup (urlencode ('ExistingGroup A/B ' ));
499+ }
500+
482501 public function testGetGroupUsersDetails () {
483502 $ gid = 'ncg1 ' ;
484503
@@ -524,4 +543,50 @@ public function testGetGroupUsersDetails() {
524543
525544 $ this ->api ->getGroupUsersDetails ($ gid );
526545 }
546+
547+ public function testGetGroupUsersDetailsEncoded () {
548+ $ gid = 'Department A/B C/D ' ;
549+
550+ $ this ->asAdmin ();
551+ $ this ->useAccountManager ();
552+
553+ $ users = [
554+ 'ncu1 ' => $ this ->createUser ('ncu1 ' ), # regular
555+ 'ncu2 ' => $ this ->createUser ('ncu2 ' ), # the zombie
556+ ];
557+ $ users ['ncu2 ' ]->expects ($ this ->atLeastOnce ())
558+ ->method ('getHome ' )
559+ ->willThrowException (new NoUserException ());
560+
561+ $ this ->userManager ->expects ($ this ->any ())
562+ ->method ('get ' )
563+ ->willReturnCallback (function (string $ uid ) use ($ users ) {
564+ return isset ($ users [$ uid ]) ? $ users [$ uid ] : null ;
565+ });
566+
567+ $ group = $ this ->createGroup ($ gid );
568+ $ group ->expects ($ this ->once ())
569+ ->method ('searchUsers ' )
570+ ->with ('' , null , 0 )
571+ ->willReturn (array_values ($ users ));
572+
573+ $ this ->groupManager
574+ ->method ('get ' )
575+ ->with ($ gid )
576+ ->willReturn ($ group );
577+ $ this ->groupManager ->expects ($ this ->any ())
578+ ->method ('getUserGroups ' )
579+ ->willReturn ([$ group ]);
580+
581+ /** @var \PHPUnit_Framework_MockObject_MockObject */
582+ $ this ->subAdminManager ->expects ($ this ->any ())
583+ ->method ('isSubAdminOfGroup ' )
584+ ->willReturn (false );
585+ $ this ->subAdminManager ->expects ($ this ->any ())
586+ ->method ('getSubAdminsGroups ' )
587+ ->willReturn ([]);
588+
589+
590+ $ this ->api ->getGroupUsersDetails (urlencode ($ gid ));
591+ }
527592}
0 commit comments