fix unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de> # Conflicts: # apps/user_ldap/tests/User_LDAPTest.php
This commit is contained in:
parent
0f958bf595
commit
bd31fe7c9b
|
@ -558,14 +558,17 @@ class User_LDAPTest extends TestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Exception
|
|
||||||
*/
|
|
||||||
public function testUserExistsForDeleted() {
|
public function testUserExistsForDeleted() {
|
||||||
$access = $this->getAccessMock();
|
$access = $this->getAccessMock();
|
||||||
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
||||||
$this->prepareMockForUserExists($access);
|
$this->prepareMockForUserExists($access);
|
||||||
|
|
||||||
|
$mapper = $this->createMock(UserMapping::class);
|
||||||
|
$mapper->expects($this->any())
|
||||||
|
->method('getUUIDByDN')
|
||||||
|
->with('dnOfFormerUser,dc=test')
|
||||||
|
->willReturn('45673458748');
|
||||||
|
|
||||||
$access->expects($this->any())
|
$access->expects($this->any())
|
||||||
->method('readAttribute')
|
->method('readAttribute')
|
||||||
->will($this->returnCallback(function($dn) {
|
->will($this->returnCallback(function($dn) {
|
||||||
|
@ -574,14 +577,25 @@ class User_LDAPTest extends TestCase {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}));
|
}));
|
||||||
|
$access->expects($this->any())
|
||||||
|
->method('getUserMapper')
|
||||||
|
->willReturn($mapper);
|
||||||
|
$access->expects($this->once())
|
||||||
|
->method('getUserDnByUuid')
|
||||||
|
->willThrowException(new \Exception());
|
||||||
|
|
||||||
|
$user = $this->createMock(User::class);
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('getDN')
|
||||||
|
->willReturn('dnOfFormerUser,dc=test');
|
||||||
|
|
||||||
$access->userManager = $this->createMock(Manager::class);
|
$access->userManager = $this->createMock(Manager::class);
|
||||||
$access->userManager->expects($this->atLeastOnce())
|
$access->userManager->expects($this->atLeastOnce())
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($this->createMock(User::class));
|
->willReturn($user);
|
||||||
|
|
||||||
//test for deleted user
|
//test for deleted user
|
||||||
$backend->userExists('formerUser');
|
$this->assertFalse($backend->userExists('formerUser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserExistsForNeverExisting() {
|
public function testUserExistsForNeverExisting() {
|
||||||
|
@ -634,15 +648,18 @@ class User_LDAPTest extends TestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Exception
|
|
||||||
*/
|
|
||||||
public function testUserExistsPublicAPIForDeleted() {
|
public function testUserExistsPublicAPIForDeleted() {
|
||||||
$access = $this->getAccessMock();
|
$access = $this->getAccessMock();
|
||||||
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
||||||
$this->prepareMockForUserExists($access);
|
$this->prepareMockForUserExists($access);
|
||||||
\OC_User::useBackend($backend);
|
\OC_User::useBackend($backend);
|
||||||
|
|
||||||
|
$mapper = $this->createMock(UserMapping::class);
|
||||||
|
$mapper->expects($this->any())
|
||||||
|
->method('getUUIDByDN')
|
||||||
|
->with('dnOfFormerUser,dc=test')
|
||||||
|
->willReturn('45673458748');
|
||||||
|
|
||||||
$access->expects($this->any())
|
$access->expects($this->any())
|
||||||
->method('readAttribute')
|
->method('readAttribute')
|
||||||
->will($this->returnCallback(function($dn) {
|
->will($this->returnCallback(function($dn) {
|
||||||
|
@ -651,13 +668,24 @@ class User_LDAPTest extends TestCase {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}));
|
}));
|
||||||
$access->userManager = $this->createMock(Manager::class);
|
$access->expects($this->any())
|
||||||
|
->method('getUserMapper')
|
||||||
|
->willReturn($mapper);
|
||||||
|
$access->expects($this->once())
|
||||||
|
->method('getUserDnByUuid')
|
||||||
|
->willThrowException(new \Exception());
|
||||||
|
|
||||||
|
$user = $this->createMock(User::class);
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('getDN')
|
||||||
|
->willReturn('dnOfFormerUser,dc=test');
|
||||||
|
|
||||||
$access->userManager->expects($this->atLeastOnce())
|
$access->userManager->expects($this->atLeastOnce())
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($this->createMock(User::class));
|
->willReturn($user);
|
||||||
|
|
||||||
//test for deleted user
|
//test for deleted user
|
||||||
\OCP\User::userExists('formerUser');
|
$this->assertFalse(\OC::$server->getUserManager()->userExists('formerUser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserExistsPublicAPIForNeverExisting() {
|
public function testUserExistsPublicAPIForNeverExisting() {
|
||||||
|
@ -818,6 +846,14 @@ class User_LDAPTest extends TestCase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
$access->connection->expects($this->any())
|
||||||
|
->method('getFromCache')
|
||||||
|
->willReturnCallback(function($key) {
|
||||||
|
if($key === 'userExistsnewyorker') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
$user = $this->createMock(User::class);
|
$user = $this->createMock(User::class);
|
||||||
$user->expects($this->any())
|
$user->expects($this->any())
|
||||||
|
|
Loading…
Reference in New Issue