summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User_LDAPTest.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-07-13 14:32:52 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-08-31 23:03:21 +0200
commitab92e2ee14800260da9259a302207d68d57a0f75 (patch)
treee94a9372654927e70fcad758646f2d3720525aa0 /apps/user_ldap/tests/User_LDAPTest.php
parentefedc81c0a2f1539806854f8a73c40fc61b1e13e (diff)
downloadnextcloud-server-ab92e2ee14800260da9259a302207d68d57a0f75.tar.gz
nextcloud-server-ab92e2ee14800260da9259a302207d68d57a0f75.zip
listen to deletion hooks for proper handling, adjust and add tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests/User_LDAPTest.php')
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php58
1 files changed, 34 insertions, 24 deletions
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index ced5009148d..f74a57e25eb 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -35,6 +35,7 @@ use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LogWrapper;
+use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OC\HintException;
@@ -59,7 +60,10 @@ use OCP\Notification\IManager as INotificationManager;
class User_LDAPTest extends TestCase {
protected $backend;
protected $access;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $configMock;
+ /** @var OfflineUser|\PHPUnit_Framework_MockObject_MockObject */
+ protected $offlineUser;
protected function setUp() {
parent::setUp();
@@ -80,10 +84,9 @@ class User_LDAPTest extends TestCase {
$this->configMock = $this->createMock(IConfig::class);
- $offlineUser = $this->getMockBuilder('\OCA\User_LDAP\User\OfflineUser')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->offlineUser = $this->createMock(OfflineUser::class);
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject $um */
$um = $this->getMockBuilder(Manager::class)
->setMethods(['getDeletedUser'])
->setConstructorArgs([
@@ -100,7 +103,7 @@ class User_LDAPTest extends TestCase {
$um->expects($this->any())
->method('getDeletedUser')
- ->will($this->returnValue($offlineUser));
+ ->will($this->returnValue($this->offlineUser));
$helper = new Helper(\OC::$server->getConfig());
@@ -284,10 +287,11 @@ class User_LDAPTest extends TestCase {
}
public function testDeleteUserSuccess() {
+ $uid = 'jeremy';
+ $home = '/var/vhome/jdings/';
+
$access = $this->getAccessMock();
- $mapping = $this->getMockBuilder('\OCA\User_LDAP\Mapping\UserMapping')
- ->disableOriginalConstructor()
- ->getMock();
+ $mapping = $this->createMock(UserMapping::class);
$mapping->expects($this->once())
->method('unmap')
->will($this->returnValue(true));
@@ -295,18 +299,20 @@ class User_LDAPTest extends TestCase {
->method('getUserMapper')
->will($this->returnValue($mapping));
- $config = $this->createMock(IConfig::class);
- $config->expects($this->exactly(2))
+ $this->configMock->expects($this->any())
->method('getUserValue')
- ->will($this->onConsecutiveCalls('1', '/var/vhome/jdings/'));
+ ->with($uid, 'user_ldap', 'isDeleted')
+ ->willReturn('1');
- $backend = new UserLDAP($access, $config, $this->createMock(INotificationManager::class));
+ $this->offlineUser->expects($this->once())
+ ->method('getHomePath')
+ ->willReturn($home);
- $result = $backend->deleteUser('jeremy');
- $this->assertTrue($result);
+ $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class));
- $home = $backend->getHome('jeremy');
- $this->assertSame($home, '/var/vhome/jdings/');
+ $result = $backend->deleteUser($uid);
+ $this->assertTrue($result);
+ $this->assertSame($backend->getHome($uid), $home);
}
/**
@@ -577,11 +583,11 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($result);
}
- public function testDeleteUser() {
+ public function testDeleteUserExisting() {
$access = $this->getAccessMock();
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
- //we do not support deleting users at all
+ //we do not support deleting existing users at all
$result = $backend->deleteUser('gunslinger');
$this->assertFalse($result);
}
@@ -699,8 +705,10 @@ class User_LDAPTest extends TestCase {
* @expectedException \OC\User\NoUserException
*/
public function testGetHomeDeletedUser() {
+ $uid = 'newyorker';
+
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -716,9 +724,7 @@ class User_LDAPTest extends TestCase {
->method('readAttribute')
->will($this->returnValue([]));
- $userMapper = $this->getMockBuilder('\OCA\User_LDAP\Mapping\UserMapping')
- ->disableOriginalConstructor()
- ->getMock();
+ $userMapper = $this->createMock(UserMapping::class);
$access->expects($this->any())
->method('getUserMapper')
@@ -728,9 +734,13 @@ class User_LDAPTest extends TestCase {
->method('getUserValue')
->will($this->returnValue(true));
- //no path at all – triggers OC default behaviour
- $result = $backend->getHome('newyorker');
- $this->assertFalse($result);
+ $this->offlineUser->expects($this->never())
+ ->method('getHomePath');
+ $this->offlineUser->expects($this->once())
+ ->method('getUID')
+ ->willReturn($uid);
+
+ $backend->getHome($uid);
}
private function prepareAccessForGetDisplayName(&$access) {