1010
1111use Exception ;
1212use OC \Authentication \Token \RemoteWipe ;
13+ use OC \Group \DisplayNameCache as GroupDisplayNameCache ;
1314use OC \Group \Manager ;
1415use OC \KnownUser \KnownUserService ;
1516use OC \PhoneNumberUtil ;
@@ -70,6 +71,7 @@ class UsersControllerTest extends TestCase {
7071 private IPhoneNumberUtil $ phoneNumberUtil ;
7172 private IAppManager $ appManager ;
7273 private IAppConfig &MockObject $ appConfig ;
74+ private GroupDisplayNameCache &MockObject $ groupDisplayNameCache ;
7375
7476 protected function setUp (): void {
7577 parent ::setUp ();
@@ -93,6 +95,7 @@ protected function setUp(): void {
9395 $ this ->appManager = $ this ->createMock (IAppManager::class);
9496 $ this ->appConfig = $ this ->createMock (IAppConfig::class);
9597 $ this ->rootFolder = $ this ->createMock (IRootFolder::class);
98+ $ this ->groupDisplayNameCache = $ this ->createMock (GroupDisplayNameCache::class);
9699
97100 $ l10n = $ this ->createMock (IL10N ::class);
98101 $ l10n ->method ('t ' )->willReturnCallback (fn (string $ txt , array $ replacement = []) => sprintf ($ txt , ...$ replacement ));
@@ -120,6 +123,7 @@ protected function setUp(): void {
120123 $ this ->phoneNumberUtil ,
121124 $ this ->appManager ,
122125 $ this ->appConfig ,
126+ $ this ->groupDisplayNameCache ,
123127 ])
124128 ->onlyMethods (['fillStorageInfo ' ])
125129 ->getMock ();
@@ -510,6 +514,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
510514 $ this ->phoneNumberUtil ,
511515 $ this ->appManager ,
512516 $ this ->appConfig ,
517+ $ this ->groupDisplayNameCache ,
513518 ])
514519 ->onlyMethods (['editUser ' ])
515520 ->getMock ();
@@ -1130,18 +1135,23 @@ public function testGetUserDataAsAdmin(): void {
11301135 ->expects ($ this ->once ())
11311136 ->method ('getSubAdminsGroups ' )
11321137 ->willReturn ([$ group3 ]);
1133- $ group0 ->expects ($ this ->once ( ))
1138+ $ group0 ->expects ($ this ->exactly ( 3 ))
11341139 ->method ('getGID ' )
11351140 ->willReturn ('group0 ' );
1136- $ group1 ->expects ($ this ->once ( ))
1141+ $ group1 ->expects ($ this ->exactly ( 3 ))
11371142 ->method ('getGID ' )
11381143 ->willReturn ('group1 ' );
1139- $ group2 ->expects ($ this ->once ( ))
1144+ $ group2 ->expects ($ this ->exactly ( 3 ))
11401145 ->method ('getGID ' )
11411146 ->willReturn ('group2 ' );
11421147 $ group3 ->expects ($ this ->once ())
11431148 ->method ('getGID ' )
11441149 ->willReturn ('group3 ' );
1150+ $ this ->groupDisplayNameCache
1151+ ->method ('getDisplayName ' )
1152+ ->willReturnCallback (function (string $ gid ): string {
1153+ return ucfirst ($ gid );
1154+ });
11451155
11461156 $ this ->mockAccount ($ targetUser , [
11471157 IAccountManager::PROPERTY_ADDRESS => ['value ' => 'address ' ],
@@ -1243,6 +1253,11 @@ public function testGetUserDataAsAdmin(): void {
12431253 'notify_email ' => null ,
12441254 'manager ' => '' ,
12451255 'pronouns ' => 'they/them ' ,
1256+ 'groupsWithDisplayname ' => [
1257+ ['id ' => 'group0 ' , 'name ' => 'Group0 ' ],
1258+ ['id ' => 'group1 ' , 'name ' => 'Group1 ' ],
1259+ ['id ' => 'group2 ' , 'name ' => 'Group2 ' ],
1260+ ],
12461261 ];
12471262 $ this ->assertEquals ($ expected , $ this ->invokePrivate ($ this ->api , 'getUserData ' , ['UID ' ]));
12481263 }
@@ -1391,6 +1406,7 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
13911406 'notify_email ' => null ,
13921407 'manager ' => '' ,
13931408 'pronouns ' => 'they/them ' ,
1409+ 'groupsWithDisplayname ' => [],
13941410 ];
13951411 $ this ->assertEquals ($ expected , $ this ->invokePrivate ($ this ->api , 'getUserData ' , ['UID ' ]));
13961412 }
@@ -1577,6 +1593,7 @@ public function testGetUserDataAsSubAdminSelfLookup(): void {
15771593 'notify_email ' => null ,
15781594 'manager ' => '' ,
15791595 'pronouns ' => 'they/them ' ,
1596+ 'groupsWithDisplayname ' => [],
15801597 ];
15811598 $ this ->assertEquals ($ expected , $ this ->invokePrivate ($ this ->api , 'getUserData ' , ['UID ' ]));
15821599 }
@@ -4151,6 +4168,7 @@ public function testGetCurrentUserLoggedIn(): void {
41514168 $ this ->phoneNumberUtil ,
41524169 $ this ->appManager ,
41534170 $ this ->appConfig ,
4171+ $ this ->groupDisplayNameCache ,
41544172 ])
41554173 ->onlyMethods (['getUserData ' ])
41564174 ->getMock ();
@@ -4246,6 +4264,7 @@ public function testGetUser(): void {
42464264 $ this ->phoneNumberUtil ,
42474265 $ this ->appManager ,
42484266 $ this ->appConfig ,
4267+ $ this ->groupDisplayNameCache ,
42494268 ])
42504269 ->onlyMethods (['getUserData ' ])
42514270 ->getMock ();
0 commit comments