17
17
use OCP \IURLGenerator ;
18
18
use OCP \IUser ;
19
19
use OCP \IUserManager ;
20
+ use OCP \Profile \IProfileManager ;
20
21
use PHPUnit \Framework \MockObject \MockObject ;
21
22
22
23
class ProfilePickerReferenceProviderTest extends TestCase {
23
24
private string $ userId = 'admin ' ;
25
+ private IUser |MockObject $ adminUser ;
24
26
private IL10N |MockObject $ l10n ;
25
27
private IURLGenerator |MockObject $ urlGenerator ;
26
28
private IUserManager |MockObject $ userManager ;
27
29
private IAccountManager |MockObject $ accountManager ;
30
+ private IProfileManager |MockObject $ profileManager ;
28
31
private ProfilePickerReferenceProvider $ referenceProvider ;
29
32
30
33
private array $ testUsersData = [
@@ -46,60 +49,74 @@ class ProfilePickerReferenceProviderTest extends TestCase {
46
49
'user1 ' => [
47
50
IAccountManager::PROPERTY_BIOGRAPHY => [
48
51
'scope ' => IAccountManager::SCOPE_PRIVATE ,
52
+ 'visible ' => true ,
49
53
'value ' => 'This is a first test user ' ,
50
54
],
51
55
IAccountManager::PROPERTY_HEADLINE => [
52
56
'scope ' => IAccountManager::SCOPE_LOCAL ,
57
+ 'visible ' => false ,
53
58
'value ' => 'I \'m a first test user ' ,
54
59
],
55
60
IAccountManager::PROPERTY_ADDRESS => [
56
61
'scope ' => IAccountManager::SCOPE_LOCAL ,
62
+ 'visible ' => true ,
57
63
'value ' => 'Odessa ' ,
58
64
],
59
65
IAccountManager::PROPERTY_WEBSITE => [
60
66
'scope ' => IAccountManager::SCOPE_LOCAL ,
67
+ 'visible ' => true ,
61
68
'value ' => 'https://domain.co/testuser1 ' ,
62
69
],
63
70
IAccountManager::PROPERTY_ORGANISATION => [
64
71
'scope ' => IAccountManager::SCOPE_PRIVATE ,
72
+ 'visible ' => true ,
65
73
'value ' => 'Nextcloud GmbH ' ,
66
74
],
67
75
IAccountManager::PROPERTY_ROLE => [
68
76
'scope ' => IAccountManager::SCOPE_LOCAL ,
77
+ 'visible ' => true ,
69
78
'value ' => 'Non-existing user ' ,
70
79
],
71
80
IAccountManager::PROPERTY_PROFILE_ENABLED => [
72
81
'scope ' => IAccountManager::SCOPE_LOCAL ,
82
+ 'visible ' => true ,
73
83
'value ' => '1 ' ,
74
84
],
75
85
],
76
86
'user2 ' => [
77
87
IAccountManager::PROPERTY_BIOGRAPHY => [
78
88
'scope ' => IAccountManager::SCOPE_LOCAL ,
89
+ 'visible ' => true ,
79
90
'value ' => 'This is a test user ' ,
80
91
],
81
92
IAccountManager::PROPERTY_HEADLINE => [
82
93
'scope ' => IAccountManager::SCOPE_LOCAL ,
94
+ 'visible ' => true ,
83
95
'value ' => 'Second test user ' ,
84
96
],
85
97
IAccountManager::PROPERTY_ADDRESS => [
86
98
'scope ' => IAccountManager::SCOPE_LOCAL ,
99
+ 'visible ' => true ,
87
100
'value ' => 'Berlin ' ,
88
101
],
89
102
IAccountManager::PROPERTY_WEBSITE => [
90
103
'scope ' => IAccountManager::SCOPE_LOCAL ,
104
+ 'visible ' => true ,
91
105
'value ' => 'https://domain.co/testuser2 ' ,
92
106
],
93
107
IAccountManager::PROPERTY_ORGANISATION => [
94
108
'scope ' => IAccountManager::SCOPE_PRIVATE ,
109
+ 'visible ' => true ,
95
110
'value ' => 'Nextcloud GmbH ' ,
96
111
],
97
112
IAccountManager::PROPERTY_ROLE => [
98
113
'scope ' => IAccountManager::SCOPE_LOCAL ,
114
+ 'visible ' => true ,
99
115
'value ' => 'Non-existing user ' ,
100
116
],
101
117
IAccountManager::PROPERTY_PROFILE_ENABLED => [
102
118
'scope ' => IAccountManager::SCOPE_LOCAL ,
119
+ 'visible ' => true ,
103
120
'value ' => '1 ' ,
104
121
],
105
122
],
@@ -120,22 +137,44 @@ public function setUp(): void {
120
137
$ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
121
138
$ this ->userManager = $ this ->createMock (IUserManager::class);
122
139
$ this ->accountManager = $ this ->createMock (IAccountManager::class);
140
+ $ this ->profileManager = $ this ->createMock (IProfileManager::class);
123
141
124
142
$ this ->referenceProvider = new ProfilePickerReferenceProvider (
125
143
$ this ->l10n ,
126
144
$ this ->urlGenerator ,
127
145
$ this ->userManager ,
128
146
$ this ->accountManager ,
147
+ $ this ->profileManager ,
129
148
$ this ->userId
130
149
);
131
150
132
151
$ this ->urlGenerator ->expects ($ this ->any ())
133
152
->method ('getBaseUrl ' )
134
153
->willReturn ($ this ->baseUrl );
154
+
155
+ $ this ->profileManager ->expects ($ this ->any ())
156
+ ->method ('isProfileEnabled ' )
157
+ ->willReturn (true );
158
+
159
+ $ this ->profileManager ->expects ($ this ->any ())
160
+ ->method ('isProfileFieldVisible ' )
161
+ ->willReturnCallback (function (string $ profileField , IUser $ targetUser , ?IUser $ visitingUser ) {
162
+ return $ this ->testAccountsData [$ targetUser ->getUID ()][$ profileField ]['visible ' ]
163
+ && $ this ->testAccountsData [$ targetUser ->getUID ()][$ profileField ]['scope ' ] !== IAccountManager::SCOPE_PRIVATE ;
164
+ });
165
+
166
+ $ this ->adminUser = $ this ->createMock (IUser::class);
167
+ $ this ->adminUser ->expects ($ this ->any ())
168
+ ->method ('getUID ' )
169
+ ->willReturn ('admin ' );
170
+ $ this ->adminUser ->expects ($ this ->any ())
171
+ ->method ('getDisplayName ' )
172
+ ->willReturn ('admin ' );
135
173
}
136
174
137
175
private function getTestAccountPropertyValue (string $ testUserId , string $ property ): mixed {
138
- if ($ this ->testAccountsData [$ testUserId ][$ property ]['scope ' ] === IAccountManager::SCOPE_PRIVATE ) {
176
+ if (!$ this ->testAccountsData [$ testUserId ][$ property ]['visible ' ]
177
+ || $ this ->testAccountsData [$ testUserId ][$ property ]['scope ' ] === IAccountManager::SCOPE_PRIVATE ) {
139
178
return null ;
140
179
}
141
180
return $ this ->testAccountsData [$ testUserId ][$ property ]['value ' ];
@@ -163,8 +202,14 @@ private function setupUserAccountReferenceExpectation(string $userId): ?IReferen
163
202
164
203
$ this ->userManager ->expects ($ this ->any ())
165
204
->method ('get ' )
166
- ->with ($ userId )
167
- ->willReturn ($ user );
205
+ ->willReturnCallback (function (string $ uid ) use ($ user , $ userId ) {
206
+ if ($ uid === $ userId ) {
207
+ return $ user ;
208
+ } elseif ($ uid === 'admin ' ) {
209
+ return $ this ->adminUser ;
210
+ }
211
+ return null ;
212
+ });
168
213
169
214
// setup account expectations
170
215
$ account = $ this ->createMock (IAccount::class);
0 commit comments