]> source.dussan.org Git - nextcloud-server.git/commitdiff
filter null values for UserManager::getByEmail 11976/head
authorGeorg Ehrke <developer@georgehrke.com>
Sun, 14 Oct 2018 17:09:55 +0000 (19:09 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Mon, 22 Oct 2018 13:51:57 +0000 (15:51 +0200)
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
lib/private/User/Manager.php
tests/lib/User/ManagerTest.php

index 54d7d7f96124dd177635c3b94b46c24d85371151..80f504d8888a978353ead7873e4a9d80e420acdd 100644 (file)
@@ -591,8 +591,12 @@ class Manager extends PublicEmitter implements IUserManager {
        public function getByEmail($email) {
                $userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
 
-               return array_map(function($uid) {
+               $users = array_map(function($uid) {
                        return $this->get($uid);
                }, $userIds);
+
+               return array_values(array_filter($users, function($u) {
+                       return ($u instanceof IUser);
+               }));
        }
 }
index d2e48ffa538467e33244bbd6aa2215571d699074..e0b6aadf2ac17015b7bcc74fab9f21156513662f 100644 (file)
@@ -668,4 +668,37 @@ class ManagerTest extends TestCase {
                $manager->get('foo')->delete();
                $this->assertFalse($manager->userExists('foo'));
        }
+
+       public function testGetByEmail() {
+               $config = $this->getMockBuilder(IConfig::class)
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $config
+                       ->expects($this->at(0))
+                       ->method('getUsersForUserValue')
+                       ->with('settings', 'email', 'test@example.com')
+                       ->will($this->returnValue(['uid1', 'uid99', 'uid2']));
+
+               $backend = $this->createMock(\Test\Util\User\Dummy::class);
+               $backend->expects($this->at(0))
+                       ->method('userExists')
+                       ->with($this->equalTo('uid1'))
+                       ->will($this->returnValue(true));
+               $backend->expects($this->at(1))
+                       ->method('userExists')
+                       ->with($this->equalTo('uid99'))
+                       ->will($this->returnValue(false));
+               $backend->expects($this->at(2))
+                       ->method('userExists')
+                       ->with($this->equalTo('uid2'))
+                       ->will($this->returnValue(true));
+
+               $manager = new \OC\User\Manager($config);
+               $manager->registerBackend($backend);
+
+               $users = $manager->getByEmail('test@example.com');
+               $this->assertCount(2, $users);
+               $this->assertEquals('uid1', $users[0]->getUID());
+               $this->assertEquals('uid2', $users[1]->getUID());
+       }
 }