Skip to content

Commit 0715665

Browse files
committed
fixup! fix(settings): show the groups display name for non-loaded groups
1 parent ace2275 commit 0715665

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

apps/provisioning_api/tests/Controller/GroupsControllerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OCA\Provisioning_API\Tests\Controller;
99

10+
use OC\Group\DisplayNameCache as GroupDisplayNameCache;
1011
use OC\Group\Manager;
1112
use OC\User\NoUserException;
1213
use OCA\Provisioning_API\Controller\GroupsController;
@@ -36,6 +37,7 @@ class GroupsControllerTest extends \Test\TestCase {
3637
protected IFactory&MockObject $l10nFactory;
3738
protected LoggerInterface&MockObject $logger;
3839
protected GroupsController&MockObject $api;
40+
private GroupDisplayNameCache&MockObject $groupDisplayNameCache;
3941

4042
private IRootFolder $rootFolder;
4143

@@ -53,6 +55,7 @@ protected function setUp(): void {
5355
$this->l10nFactory = $this->createMock(IFactory::class);
5456
$this->logger = $this->createMock(LoggerInterface::class);
5557
$this->rootFolder = $this->createMock(IRootFolder::class);
58+
$this->groupDisplayNameCache = $this->createMock(GroupDisplayNameCache::class);
5659

5760
$this->groupManager
5861
->method('getSubAdmin')
@@ -70,7 +73,8 @@ protected function setUp(): void {
7073
$this->subAdminManager,
7174
$this->l10nFactory,
7275
$this->rootFolder,
73-
$this->logger
76+
$this->logger,
77+
$this->groupDisplayNameCache,
7478
])
7579
->onlyMethods(['fillStorageInfo'])
7680
->getMock();

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Exception;
1212
use OC\Authentication\Token\RemoteWipe;
13+
use OC\Group\DisplayNameCache as GroupDisplayNameCache;
1314
use OC\Group\Manager;
1415
use OC\KnownUser\KnownUserService;
1516
use 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

Comments
 (0)