diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-08-15 17:11:07 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-08-15 17:11:07 +0300 |
commit | 2b903aa267a1969edea945538ac778a008ea7955 (patch) | |
tree | 1a6475dd259d717bf12331db84a2944ff5355177 /apps/user_ldap/tests | |
parent | b497b0686790c250825b8d631b403bb27d2ba2c8 (diff) |
fix unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/User_LDAPTest.php | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 447b91decff..693159dc72b 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -515,13 +515,16 @@ class User_LDAPTest extends TestCase { $this->assertTrue($result); } - /** - * @expectedException \Exception - */ public function testUserExistsForDeleted() { $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager); $this->prepareMockForUserExists(); + $mapper = $this->createMock(UserMapping::class); + $mapper->expects($this->any()) + ->method('getUUIDByDN') + ->with('dnOfFormerUser,dc=test') + ->willReturn('45673458748'); + $this->access->expects($this->any()) ->method('readAttribute') ->will($this->returnCallback(function($dn) { @@ -530,13 +533,24 @@ class User_LDAPTest extends TestCase { } return false; })); + $this->access->expects($this->any()) + ->method('getUserMapper') + ->willReturn($mapper); + $this->access->expects($this->once()) + ->method('getUserDnByUuid') + ->willThrowException(new \Exception()); + + $user = $this->createMock(User::class); + $user->expects($this->any()) + ->method('getDN') + ->willReturn('dnOfFormerUser,dc=test'); $this->userManager->expects($this->atLeastOnce()) ->method('get') - ->willReturn($this->createMock(User::class)); + ->willReturn($user); //test for deleted user - $backend->userExists('formerUser'); + $this->assertFalse($backend->userExists('formerUser')); } public function testUserExistsForNeverExisting() { @@ -588,14 +602,17 @@ class User_LDAPTest extends TestCase { $this->assertTrue($result); } - /** - * @expectedException \Exception - */ public function testUserExistsPublicAPIForDeleted() { $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager); $this->prepareMockForUserExists(); \OC_User::useBackend($backend); + $mapper = $this->createMock(UserMapping::class); + $mapper->expects($this->any()) + ->method('getUUIDByDN') + ->with('dnOfFormerUser,dc=test') + ->willReturn('45673458748'); + $this->access->expects($this->any()) ->method('readAttribute') ->will($this->returnCallback(function($dn) { @@ -604,12 +621,24 @@ class User_LDAPTest extends TestCase { } return false; })); + $this->access->expects($this->any()) + ->method('getUserMapper') + ->willReturn($mapper); + $this->access->expects($this->once()) + ->method('getUserDnByUuid') + ->willThrowException(new \Exception()); + + $user = $this->createMock(User::class); + $user->expects($this->any()) + ->method('getDN') + ->willReturn('dnOfFormerUser,dc=test'); + $this->userManager->expects($this->atLeastOnce()) ->method('get') - ->willReturn($this->createMock(User::class)); + ->willReturn($user); //test for deleted user - \OC::$server->getUserManager()->userExists('formerUser'); + $this->assertFalse(\OC::$server->getUserManager()->userExists('formerUser')); } public function testUserExistsPublicAPIForNeverExisting() { @@ -762,6 +791,14 @@ 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()) |