From 2b903aa267a1969edea945538ac778a008ea7955 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Aug 2018 16:11:07 +0200 Subject: [PATCH] fix unit tests Signed-off-by: Arthur Schiwon --- apps/user_ldap/tests/User_LDAPTest.php | 57 +++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 447b91decf..693159dc72 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())