3434use OCA \DAV \CalDAV \Proxy \Proxy ;
3535use OCA \DAV \CalDAV \Proxy \ProxyMapper ;
3636use OCA \DAV \Connector \Sabre \Principal ;
37+ use OCP \Accounts \IAccount ;
38+ use OCP \Accounts \IAccountManager ;
39+ use OCP \Accounts \IAccountProperty ;
40+ use OCP \Accounts \IAccountPropertyCollection ;
3741use OCP \App \IAppManager ;
3842use OCP \IConfig ;
3943use OCP \IGroup ;
@@ -59,6 +63,9 @@ class PrincipalTest extends TestCase {
5963 /** @var IGroupManager | MockObject */
6064 private $ groupManager ;
6165
66+ /** @var IAccountManager|MockObject */
67+ private $ accountManager ;
68+
6269 /** @var IManager | MockObject */
6370 private $ shareManager ;
6471
@@ -81,6 +88,7 @@ class PrincipalTest extends TestCase {
8188 protected function setUp (): void {
8289 $ this ->userManager = $ this ->createMock (IUserManager::class);
8390 $ this ->groupManager = $ this ->createMock (IGroupManager::class);
91+ $ this ->accountManager = $ this ->createMock (IAccountManager::class);
8492 $ this ->shareManager = $ this ->createMock (IManager::class);
8593 $ this ->userSession = $ this ->createMock (IUserSession::class);
8694 $ this ->appManager = $ this ->createMock (IAppManager::class);
@@ -92,6 +100,7 @@ protected function setUp(): void {
92100 $ this ->connector = new Principal (
93101 $ this ->userManager ,
94102 $ this ->groupManager ,
103+ $ this ->accountManager ,
95104 $ this ->shareManager ,
96105 $ this ->userSession ,
97106 $ this ->appManager ,
@@ -143,6 +152,45 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
143152 ->withConsecutive ([$ fooUser ], [$ barUser ])
144153 ->willReturnOnConsecutiveCalls ('de ' , 'en ' );
145154
155+ $ fooAccountPropertyCollection = $ this ->createMock (IAccountPropertyCollection::class);
156+ $ fooAccountPropertyCollection ->expects ($ this ->once ())
157+ ->method ('getProperties ' )
158+ ->with ()
159+ ->willReturn ([]);
160+ $ fooAccount = $ this ->createMock (IAccount::class);
161+ $ fooAccount ->expects ($ this ->once ())
162+ ->method ('getPropertyCollection ' )
163+ ->with (IAccountManager::COLLECTION_EMAIL )
164+ ->willReturn ($ fooAccountPropertyCollection );
165+
166+ $ emailPropertyOne = $ this ->createMock (IAccountProperty::class);
167+ $ emailPropertyOne ->expects ($ this ->once ())
168+ ->method ('getValue ' )
169+ ->with ()
170+ ->
willReturn (
'[email protected] ' );
171+ $ emailPropertyTwo = $ this ->createMock (IAccountProperty::class);
172+ $ emailPropertyTwo ->expects ($ this ->once ())
173+ ->method ('getValue ' )
174+ ->with ()
175+ ->
willReturn (
'[email protected] ' );
176+
177+ $ barAccountPropertyCollection = $ this ->createMock (IAccountPropertyCollection::class);
178+ $ barAccountPropertyCollection ->expects ($ this ->once ())
179+ ->method ('getProperties ' )
180+ ->with ()
181+ ->willReturn ([$ emailPropertyOne , $ emailPropertyTwo ]);
182+ $ barAccount = $ this ->createMock (IAccount::class);
183+ $ barAccount ->expects ($ this ->once ())
184+ ->method ('getPropertyCollection ' )
185+ ->with (IAccountManager::COLLECTION_EMAIL )
186+ ->willReturn ($ barAccountPropertyCollection );
187+
188+ $ this ->accountManager
189+ ->expects ($ this ->exactly (2 ))
190+ ->method ('getAccount ' )
191+ ->withConsecutive ([$ fooUser ], [$ barUser ])
192+ ->willReturnOnConsecutiveCalls ($ fooAccount , $ barAccount );
193+
146194 $ expectedResponse = [
147195 0 => [
148196 'uri ' => 'principals/users/foo ' ,
@@ -156,6 +204,7 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
156204 '{urn:ietf:params:xml:ns:caldav}calendar-user-type ' => 'INDIVIDUAL ' ,
157205 '{http://nextcloud.com/ns}language ' => 'en ' ,
158206 '{http://sabredav.org/ns}email-address ' =>
'[email protected] ' ,
207+ '{DAV:}alternate-URI-set ' => [
'mailto:[email protected] ' ,
'mailto:[email protected] ' ]
159208 ]
160209 ];
161210 $ response = $ this ->connector ->getPrincipalsByPrefix ('principals/users ' );
0 commit comments