1212use OCP \App \IAppManager ;
1313use OCP \AppFramework \Http \JSONResponse ;
1414use OCP \Contacts \IManager ;
15+ use OCP \IAppConfig ;
1516use OCP \IRequest ;
1617use OCP \IUserManager ;
1718use PHPUnit \Framework \MockObject \MockObject ;
@@ -34,6 +35,7 @@ class ContactControllerTest extends TestCase {
3435 /** @var IUserManager|MockObject */
3536 private $ userManager ;
3637 private ContactsService |MockObject $ service ;
38+ private IAppConfig |MockObject $ appConfig ;
3739
3840 /** @var ContactController */
3941 protected $ controller ;
@@ -49,13 +51,15 @@ protected function setUp():void {
4951 $ this ->appManager = $ this ->createMock (IAppManager::class);
5052 $ this ->userManager = $ this ->createMock (IUserManager::class);
5153 $ this ->service = $ this ->createMock (ContactsService::class);
54+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
5255 $ this ->logger = $ this ->createMock (NullLogger::class);
5356 $ this ->controller = new ContactController ($ this ->appName ,
5457 $ this ->request ,
5558 $ this ->manager ,
5659 $ this ->appManager ,
5760 $ this ->userManager ,
5861 $ this ->service ,
62+ $ this ->appConfig ,
5963 $ this ->logger ,
6064 );
6165 }
@@ -338,6 +342,10 @@ public function testSearchAttendee():void {
338342 $ this ->manager ->expects (self ::once ())
339343 ->method ('isEnabled ' )
340344 ->willReturn (true );
345+ $ this ->appConfig ->expects (self ::once ())
346+ ->method ('getValueBool ' )
347+ ->with ('dav ' , 'caldav.external_attendees_disabled ' , false )
348+ ->willReturn (false );
341349 $ this ->service
342350 ->method ('hasEmail ' )
343351 ->willReturnMap ([
@@ -360,20 +368,23 @@ public function testSearchAttendee():void {
360368 [$ user1 , 'Person 1 ' ],
361369 [$ user2 , 'Person 2 ' ],
362370 [$ user3 , '' ],
371+ [$ user4 , 'Person 3 ' ],
363372 ]);
364- $ this ->service ->expects (self ::exactly (2 ))
373+ $ this ->service ->expects (self ::exactly (3 ))
365374 ->method ('getLanguageId ' )
366375 ->willReturnMap ([
367376 [$ user1 , 'de ' ],
368- [$ user3 , 'en_us ' ],
377+ [$ user2 , null ],
378+ [$ user4 , 'en_us ' ],
369379 ]);
370- $ this ->service ->expects (self ::exactly (2 ))
380+ $ this ->service ->expects (self ::exactly (3 ))
371381 ->method ('getTimezoneId ' )
372382 ->willReturnMap ([
373383 [$ user1 , 'Europe/Berlin ' ],
374- [$ user3 , 'Australia/Adelaide ' ],
384+ [$ user2 , null ],
385+ [$ user4 , 'Australia/Adelaide ' ],
375386 ]);
376- $ this ->service ->expects (self ::exactly (2 ))
387+ $ this ->service ->expects (self ::exactly (3 ))
377388 ->method ('getEmail ' )
378389 ->willReturnMap ([
379390 [$ user1 , [
@@ -382,7 +393,7 @@ public function testSearchAttendee():void {
382393 ]
383394 ],
384395385- [$ user3 , ['foo5 @example.com ' ]],
396+ [$ user4 , ['foo4 @example.com ' ]],
386397 ]);
387398 $ this ->service ->method ('getPhotoUri ' )
388399 ->willReturnMap ([
@@ -394,7 +405,7 @@ public function testSearchAttendee():void {
394405 $ this ->manager ->expects (self ::exactly (2 ))
395406 ->method ('search ' )
396407 ->willReturnMap ([
397- ['search 123 ' , ['FN ' , 'EMAIL ' ], ['enumeration ' => false ], [$ user1 , $ user2 , $ user3 , $ user4 ]],
408+ ['search 123 ' , ['FN ' , 'EMAIL ' ], ['enumeration ' => true ], [$ user1 , $ user2 , $ user3 , $ user4 ]],
398409 ['search 123 ' , ['CATEGORIES ' ], [], [$ user4 ]]
399410 ]);
400411
@@ -421,6 +432,101 @@ public function testSearchAttendee():void {
421432 'tzid ' => null ,
422433 'photo ' => null ,
423434 'type ' => 'individual '
435+ ], [
436+ 'name ' => 'Person 3 ' ,
437+ 'emails ' => [
438+ 439+ ],
440+ 'lang ' => 'en_us ' ,
441+ 'tzid ' => 'Australia/Adelaide ' ,
442+ 'photo ' => null ,
443+ 'type ' => 'individual '
444+ ]
445+ ], $ response ->getData ());
446+ $ this ->assertEquals (200 , $ response ->getStatus ());
447+ }
448+
449+ public function testSearchAttendeeExternalAttendeesDisabled ():void {
450+ $ user1 = [
451+ 'FN ' => 'Person 1 ' ,
452+ 'EMAIL ' => [
453+ 454+ 455+ ],
456+ 'LANG ' => 'de ' ,
457+ 'TZ ' => 'Europe/Berlin ' ,
458+ 'PHOTO ' => 'VALUE=uri:http://foo.bar '
459+ ];
460+ $ user2 = [
461+ 'FN ' => 'Person 2 ' ,
462+ 463+ ];
464+ $ user3 = [
465+ 'isLocalSystemBook ' => true ,
466+ 'FN ' => 'System User ' ,
467+ 468+ 'LANG ' => 'en ' ,
469+ 'TZ ' => 'UTC ' ,
470+ ];
471+
472+ $ this ->manager ->expects (self ::once ())
473+ ->method ('isEnabled ' )
474+ ->willReturn (true );
475+ $ this ->appConfig ->expects (self ::once ())
476+ ->method ('getValueBool ' )
477+ ->with ('dav ' , 'caldav.external_attendees_disabled ' , false )
478+ ->willReturn (true );
479+ $ this ->service
480+ ->method ('hasEmail ' )
481+ ->willReturnMap ([
482+ [$ user1 , true ],
483+ [$ user2 , true ],
484+ [$ user3 , true ],
485+ ]);
486+ $ this ->service
487+ ->method ('isSystemBook ' )
488+ ->willReturnMap ([
489+ [$ user1 , false ],
490+ [$ user2 , false ],
491+ [$ user3 , true ],
492+ ]);
493+ $ this ->service
494+ ->method ('getNameFromContact ' )
495+ ->willReturnMap ([
496+ [$ user3 , 'System User ' ],
497+ ]);
498+ $ this ->service ->expects (self ::once ())
499+ ->method ('getLanguageId ' )
500+ ->with ($ user3 )
501+ ->willReturn ('en ' );
502+ $ this ->service ->expects (self ::once ())
503+ ->method ('getTimezoneId ' )
504+ ->with ($ user3 )
505+ ->willReturn ('UTC ' );
506+ $ this ->service ->expects (self ::once ())
507+ ->method ('getEmail ' )
508+ ->with ($ user3 )
509+ ->
willReturn ([
'[email protected] ' ]);
510+ $ this ->service ->expects (self ::once ())
511+ ->method ('getPhotoUri ' )
512+ ->with ($ user3 )
513+ ->willReturn (null );
514+ $ this ->manager ->expects (self ::once ())
515+ ->method ('search ' )
516+ ->with ('search 123 ' , ['FN ' , 'EMAIL ' ], ['enumeration ' => true ])
517+ ->willReturn ([$ user1 , $ user2 , $ user3 ]);
518+
519+ $ response = $ this ->controller ->searchAttendee ('search 123 ' );
520+
521+ $ this ->assertInstanceOf (JSONResponse::class, $ response );
522+ $ this ->assertEquals ([
523+ [
524+ 'name ' => 'System User ' ,
525+ 'emails ' => [
'[email protected] ' ],
526+ 'lang ' => 'en ' ,
527+ 'tzid ' => 'UTC ' ,
528+ 'photo ' => null ,
529+ 'type ' => 'individual '
424530 ]
425531 ], $ response ->getData ());
426532 $ this ->assertEquals (200 , $ response ->getStatus ());
0 commit comments