diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-10-14 19:09:55 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-10-22 15:54:41 +0200 |
commit | 879538c22f92b0e2b090f5d25f4ac39fdb2a1314 (patch) | |
tree | 3a25815793b7dabf3826277dc8e2ea86d0174bb8 | |
parent | e3a2b9e3e6db6d5b5c32a5e0b345447b20fa15a1 (diff) | |
download | nextcloud-server-879538c22f92b0e2b090f5d25f4ac39fdb2a1314.tar.gz nextcloud-server-879538c22f92b0e2b090f5d25f4ac39fdb2a1314.zip |
filter null values for UserManager::getByEmail
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
-rw-r--r-- | lib/private/User/Manager.php | 6 | ||||
-rw-r--r-- | tests/lib/User/ManagerTest.php | 33 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index abc7a45e6bc..d2a7968b76f 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -533,8 +533,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); + })); } } diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index f6a362a5031..3f82d79663a 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -666,4 +666,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()); + } } |