1717use OCP \IURLGenerator ;
1818use OCP \IUser ;
1919use OCP \IUserManager ;
20+ use OCP \Profile \IProfileManager ;
2021use PHPUnit \Framework \MockObject \MockObject ;
2122
2223class ProfilePickerReferenceProviderTest extends TestCase {
2324 private string $ userId = 'admin ' ;
25+ private IUser |MockObject $ adminUser ;
2426 private IL10N |MockObject $ l10n ;
2527 private IURLGenerator |MockObject $ urlGenerator ;
2628 private IUserManager |MockObject $ userManager ;
2729 private IAccountManager |MockObject $ accountManager ;
30+ private IProfileManager |MockObject $ profileManager ;
2831 private ProfilePickerReferenceProvider $ referenceProvider ;
2932
3033 private array $ testUsersData = [
@@ -46,60 +49,74 @@ class ProfilePickerReferenceProviderTest extends TestCase {
4649 'user1 ' => [
4750 IAccountManager::PROPERTY_BIOGRAPHY => [
4851 'scope ' => IAccountManager::SCOPE_PRIVATE ,
52+ 'visible ' => true ,
4953 'value ' => 'This is a first test user ' ,
5054 ],
5155 IAccountManager::PROPERTY_HEADLINE => [
5256 'scope ' => IAccountManager::SCOPE_LOCAL ,
57+ 'visible ' => false ,
5358 'value ' => 'I \'m a first test user ' ,
5459 ],
5560 IAccountManager::PROPERTY_ADDRESS => [
5661 'scope ' => IAccountManager::SCOPE_LOCAL ,
62+ 'visible ' => true ,
5763 'value ' => 'Odessa ' ,
5864 ],
5965 IAccountManager::PROPERTY_WEBSITE => [
6066 'scope ' => IAccountManager::SCOPE_LOCAL ,
67+ 'visible ' => true ,
6168 'value ' => 'https://domain.co/testuser1 ' ,
6269 ],
6370 IAccountManager::PROPERTY_ORGANISATION => [
6471 'scope ' => IAccountManager::SCOPE_PRIVATE ,
72+ 'visible ' => true ,
6573 'value ' => 'Nextcloud GmbH ' ,
6674 ],
6775 IAccountManager::PROPERTY_ROLE => [
6876 'scope ' => IAccountManager::SCOPE_LOCAL ,
77+ 'visible ' => true ,
6978 'value ' => 'Non-existing user ' ,
7079 ],
7180 IAccountManager::PROPERTY_PROFILE_ENABLED => [
7281 'scope ' => IAccountManager::SCOPE_LOCAL ,
82+ 'visible ' => true ,
7383 'value ' => '1 ' ,
7484 ],
7585 ],
7686 'user2 ' => [
7787 IAccountManager::PROPERTY_BIOGRAPHY => [
7888 'scope ' => IAccountManager::SCOPE_LOCAL ,
89+ 'visible ' => true ,
7990 'value ' => 'This is a test user ' ,
8091 ],
8192 IAccountManager::PROPERTY_HEADLINE => [
8293 'scope ' => IAccountManager::SCOPE_LOCAL ,
94+ 'visible ' => true ,
8395 'value ' => 'Second test user ' ,
8496 ],
8597 IAccountManager::PROPERTY_ADDRESS => [
8698 'scope ' => IAccountManager::SCOPE_LOCAL ,
99+ 'visible ' => true ,
87100 'value ' => 'Berlin ' ,
88101 ],
89102 IAccountManager::PROPERTY_WEBSITE => [
90103 'scope ' => IAccountManager::SCOPE_LOCAL ,
104+ 'visible ' => true ,
91105 'value ' => 'https://domain.co/testuser2 ' ,
92106 ],
93107 IAccountManager::PROPERTY_ORGANISATION => [
94108 'scope ' => IAccountManager::SCOPE_PRIVATE ,
109+ 'visible ' => true ,
95110 'value ' => 'Nextcloud GmbH ' ,
96111 ],
97112 IAccountManager::PROPERTY_ROLE => [
98113 'scope ' => IAccountManager::SCOPE_LOCAL ,
114+ 'visible ' => true ,
99115 'value ' => 'Non-existing user ' ,
100116 ],
101117 IAccountManager::PROPERTY_PROFILE_ENABLED => [
102118 'scope ' => IAccountManager::SCOPE_LOCAL ,
119+ 'visible ' => true ,
103120 'value ' => '1 ' ,
104121 ],
105122 ],
@@ -120,22 +137,40 @@ public function setUp(): void {
120137 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
121138 $ this ->userManager = $ this ->createMock (IUserManager::class);
122139 $ this ->accountManager = $ this ->createMock (IAccountManager::class);
140+ $ this ->profileManager = $ this ->createMock (IProfileManager::class);
123141
124142 $ this ->referenceProvider = new ProfilePickerReferenceProvider (
125143 $ this ->l10n ,
126144 $ this ->urlGenerator ,
127145 $ this ->userManager ,
128146 $ this ->accountManager ,
147+ $ this ->profileManager ,
129148 $ this ->userId
130149 );
131150
132151 $ this ->urlGenerator ->expects ($ this ->any ())
133152 ->method ('getBaseUrl ' )
134153 ->willReturn ($ this ->baseUrl );
154+
155+ $ this ->profileManager ->expects ($ this ->any ())
156+ ->method ('isProfileFieldVisible ' )
157+ ->willReturnCallback (function (string $ profileField , IUser $ targetUser , ?IUser $ visitingUser ) {
158+ return $ this ->testAccountsData [$ targetUser ->getUID ()][$ profileField ]['visible ' ]
159+ && $ this ->testAccountsData [$ targetUser ->getUID ()][$ profileField ]['scope ' ] !== IAccountManager::SCOPE_PRIVATE ;
160+ });
161+
162+ $ this ->adminUser = $ this ->createMock (IUser::class);
163+ $ this ->adminUser ->expects ($ this ->any ())
164+ ->method ('getUID ' )
165+ ->willReturn ('admin ' );
166+ $ this ->adminUser ->expects ($ this ->any ())
167+ ->method ('getDisplayName ' )
168+ ->willReturn ('admin ' );
135169 }
136170
137171 private function getTestAccountPropertyValue (string $ testUserId , string $ property ): mixed {
138- if ($ this ->testAccountsData [$ testUserId ][$ property ]['scope ' ] === IAccountManager::SCOPE_PRIVATE ) {
172+ if (!$ this ->testAccountsData [$ testUserId ][$ property ]['visible ' ]
173+ || $ this ->testAccountsData [$ testUserId ][$ property ]['scope ' ] === IAccountManager::SCOPE_PRIVATE ) {
139174 return null ;
140175 }
141176 return $ this ->testAccountsData [$ testUserId ][$ property ]['value ' ];
@@ -163,8 +198,14 @@ private function setupUserAccountReferenceExpectation(string $userId): ?IReferen
163198
164199 $ this ->userManager ->expects ($ this ->any ())
165200 ->method ('get ' )
166- ->with ($ userId )
167- ->willReturn ($ user );
201+ ->willReturnCallback (function (string $ uid ) use ($ user , $ userId ) {
202+ if ($ uid === $ userId ) {
203+ return $ user ;
204+ } elseif ($ uid === 'admin ' ) {
205+ return $ this ->adminUser ;
206+ }
207+ return null ;
208+ });
168209
169210 // setup account expectations
170211 $ account = $ this ->createMock (IAccount::class);
0 commit comments