diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-10-14 19:09:55 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-10-15 13:27:58 +0200 |
commit | 2db26d87c444ba385850d63e8d27f3b759102cfe (patch) | |
tree | 20eeff3bfbeec2b83558f09f61f53d90611a7788 | |
parent | 0fca815b4dd601381a909656a1e3e7a7e89714d2 (diff) | |
download | nextcloud-server-2db26d87c444ba385850d63e8d27f3b759102cfe.tar.gz nextcloud-server-2db26d87c444ba385850d63e8d27f3b759102cfe.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 494a345be59..16a911b90ac 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -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); + })); } } diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index d2e48ffa538..e0b6aadf2ac 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -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()); + } } |