mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(user_ldap): Fix user_ldap tests by mocking new method exists in manager
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
eb27243056
commit
c3029c70d5
1 changed files with 64 additions and 20 deletions
|
|
@ -303,6 +303,10 @@ class User_LDAPTest extends TestCase {
|
|||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->willReturn($offlineUser);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with($uid)
|
||||
->willReturn(true);
|
||||
|
||||
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
|
||||
|
||||
|
|
@ -490,9 +494,12 @@ class User_LDAPTest extends TestCase {
|
|||
|
||||
$user = $this->createMock(User::class);
|
||||
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->never())
|
||||
->method('get');
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('gunslinger')
|
||||
->willReturn(true);
|
||||
$this->access->expects($this->any())
|
||||
->method('getUserMapper')
|
||||
->willReturn($this->createMock(UserMapping::class));
|
||||
|
|
@ -517,11 +524,12 @@ class User_LDAPTest extends TestCase {
|
|||
->method('getUserMapper')
|
||||
->willReturn($mapper);
|
||||
|
||||
$user = $this->createMock(User::class);
|
||||
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->never())
|
||||
->method('get');
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('formerUser')
|
||||
->willReturn(true);
|
||||
|
||||
//test for deleted user – always returns true as long as we have the user in DB
|
||||
$this->assertTrue($backend->userExists('formerUser'));
|
||||
|
|
@ -564,9 +572,12 @@ class User_LDAPTest extends TestCase {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->never())
|
||||
->method('get');
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('gunslinger')
|
||||
->willReturn(true);
|
||||
$this->access->expects($this->any())
|
||||
->method('getUserMapper')
|
||||
->willReturn($this->createMock(UserMapping::class));
|
||||
|
|
@ -625,7 +636,12 @@ class User_LDAPTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->with('gunslinger')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('gunslinger')
|
||||
->willReturn(true);
|
||||
|
||||
//absolute path
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
|
|
@ -678,6 +694,10 @@ class User_LDAPTest extends TestCase {
|
|||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('ladyofshadows')
|
||||
->willReturn(true);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $backend->getHome('ladyofshadows');
|
||||
|
|
@ -707,14 +727,6 @@ class User_LDAPTest extends TestCase {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
$this->access->connection->expects($this->any())
|
||||
->method('getFromCache')
|
||||
->willReturnCallback(function ($key) {
|
||||
if ($key === 'userExistsnewyorker') {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
$user = $this->createMock(User::class);
|
||||
$user->expects($this->any())
|
||||
|
|
@ -726,7 +738,12 @@ class User_LDAPTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->with('newyorker')
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with('newyorker')
|
||||
->willReturn(true);
|
||||
|
||||
//no path at all – triggers OC default behaviour
|
||||
$result = $backend->getHome('newyorker');
|
||||
|
|
@ -765,7 +782,12 @@ class User_LDAPTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->with($uid)
|
||||
->willReturn($offlineUser);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('exists')
|
||||
->with($uid)
|
||||
->willReturn(true);
|
||||
|
||||
$result = $backend->getHome($uid);
|
||||
$this->assertFalse($result);
|
||||
|
|
@ -865,6 +887,16 @@ class User_LDAPTest extends TestCase {
|
|||
}
|
||||
return null;
|
||||
});
|
||||
$this->userManager->expects($this->any())
|
||||
->method('exists')
|
||||
->willReturnCallback(function ($uid) use ($user1, $user2) {
|
||||
if ($uid === 'gunslinger') {
|
||||
return true;
|
||||
} elseif ($uid === 'newyorker') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$this->access->expects($this->any())
|
||||
->method('getUserMapper')
|
||||
->willReturn($mapper);
|
||||
|
|
@ -948,6 +980,16 @@ class User_LDAPTest extends TestCase {
|
|||
}
|
||||
return null;
|
||||
});
|
||||
$this->userManager->expects($this->any())
|
||||
->method('exists')
|
||||
->willReturnCallback(function ($uid) use ($user1, $user2) {
|
||||
if ($uid === 'gunslinger') {
|
||||
return true;
|
||||
} elseif ($uid === 'newyorker') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$this->access->expects($this->any())
|
||||
->method('getUserMapper')
|
||||
->willReturn($mapper);
|
||||
|
|
@ -958,7 +1000,7 @@ class User_LDAPTest extends TestCase {
|
|||
});
|
||||
|
||||
//with displayName
|
||||
$result = \OC::$server->getUserManager()->get('gunslinger')->getDisplayName();
|
||||
$result = \OC::$server->getUserManager()->get('gunslinger')?->getDisplayName();
|
||||
$this->assertEquals('Roland Deschain', $result);
|
||||
|
||||
//empty displayname retrieved
|
||||
|
|
@ -1052,6 +1094,8 @@ class User_LDAPTest extends TestCase {
|
|||
->method('get')
|
||||
->with($dn)
|
||||
->willReturn($user);
|
||||
$this->userManager->expects($this->never())
|
||||
->method('exists');
|
||||
$this->userManager->expects($this->any())
|
||||
->method('getAttributes')
|
||||
->willReturn(['dn', 'uid', 'mail', 'displayname']);
|
||||
|
|
|
|||
Loading…
Reference in a new issue