1515use OC \User \User ;
1616use OCP \Config \IUserConfig ;
1717use OCP \EventDispatcher \IEventDispatcher ;
18+ use OCP \Federation \ICloudId ;
19+ use OCP \Federation \ICloudIdManager ;
1820use OCP \ICache ;
1921use OCP \ICacheFactory ;
2022use OCP \IConfig ;
@@ -34,6 +36,7 @@ class ManagerTest extends TestCase {
3436 private ICache &MockObject $ cache ;
3537 private LoggerInterface &MockObject $ logger ;
3638 private IUserManager $ manager ;
39+ private ICloudIdManager $ cloudIdManager ;
3740
3841 #[\Override]
3942 protected function setUp (): void {
@@ -44,11 +47,12 @@ protected function setUp(): void {
4447 $ this ->cacheFactory = $ this ->createMock (ICacheFactory::class);
4548 $ this ->cache = $ this ->createMock (ICache::class);
4649 $ this ->logger = $ this ->createMock (LoggerInterface::class);
50+ $ this ->cloudIdManager = $ this ->createMock (ICloudIdManager::class);
4751
4852 $ this ->cacheFactory ->method ('createDistributed ' )
4953 ->willReturn ($ this ->cache );
5054
51- $ this ->manager = new Manager ($ this ->config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger );
55+ $ this ->manager = new Manager ($ this ->config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger , $ this -> cloudIdManager );
5256 }
5357
5458 public function testGetBackends (): void {
@@ -665,7 +669,7 @@ public function testDeleteUser(): void {
665669 ->method ('getAppValue ' )
666670 ->willReturnArgument (2 );
667671
668- $ this ->manager = new Manager ($ config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger );
672+ $ this ->manager = new Manager ($ config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger , $ this -> cloudIdManager );
669673 $ backend = new \Test \Util \User \Dummy ();
670674
671675 $ this ->manager ->registerBackend ($ backend );
@@ -687,7 +691,7 @@ public function testGetByEmail(): void {
687691 });
688692
689693 $ this ->manager = $ this ->getMockBuilder (Manager::class)
690- ->setConstructorArgs ([$ this ->config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger ])
694+ ->setConstructorArgs ([$ this ->config , $ this ->cacheFactory , $ this ->eventDispatcher , $ this ->logger , $ this -> cloudIdManager ])
691695 ->onlyMethods (['getUserConfig ' , 'get ' ])
692696 ->getMock ();
693697 $ this ->manager ->method ('getUserConfig ' )->willReturn ($ userConfig );
@@ -736,4 +740,22 @@ public function testGetAvatarUrlLight(): void {
736740 public function testGetAvatarUrlDark (): void {
737741 $ this ->assertEquals ('http://localhost/index.php/avatar/userid/64/dark ' , $ this ->manager ->getAvatarUrlDark ('userid ' , 64 ));
738742 }
743+
744+ public function testGetDisplayUser (): void {
745+ $ userId = 'test@example.com ' ;
746+
747+ $ cloudId = $ this ->createMock (ICloudId::class);
748+ $ cloudId ->expects ($ this ->once ())
749+ ->method ('getDisplayId ' )
750+ ->willReturn ($ userId );
751+ $ this ->cloudIdManager ->expects ($ this ->once ())
752+ ->method ('resolveCloudId ' )
753+ ->with ($ userId )
754+ ->willReturn ($ cloudId );
755+
756+ $ user = $ this ->manager ->getDisplayUser ($ userId );
757+
758+ $ this ->assertEquals ($ userId , $ user ->getUID ());
759+ $ this ->assertEquals ($ userId , $ user ->getDisplayName ());
760+ }
739761}
0 commit comments