Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
filter null values for UserManager::getByEmail
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke committed Oct 22, 2018
commit 879538c22f92b0e2b090f5d25f4ac39fdb2a1314
6 changes: 5 additions & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,12 @@ private function getSeenUserIds($limit = null, $offset = null) {
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);
}));
}
}
33 changes: 33 additions & 0 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,37 @@ public function testDeleteUser() {
$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', '[email protected]')
->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('[email protected]');
$this->assertCount(2, $users);
$this->assertEquals('uid1', $users[0]->getUID());
$this->assertEquals('uid2', $users[1]->getUID());
}
}