Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
fix unit tests
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Aug 15, 2018
commit 2b903aa267a1969edea945538ac778a008ea7955
57 changes: 47 additions & 10 deletions apps/user_ldap/tests/User_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,16 @@ public function testUserExists() {
$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) {
Expand All @@ -530,13 +533,24 @@ public function testUserExistsForDeleted() {
}
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() {
Expand Down Expand Up @@ -588,14 +602,17 @@ public function testUserExistsPublicAPI() {
$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) {
Expand All @@ -604,12 +621,24 @@ public function testUserExistsPublicAPIForDeleted() {
}
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() {
Expand Down Expand Up @@ -762,6 +791,14 @@ public function testGetHomeNoPath() {
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())
Expand Down