diff options
Diffstat (limited to 'apps/user_ldap/tests/LDAPProviderTest.php')
-rw-r--r-- | apps/user_ldap/tests/LDAPProviderTest.php | 419 |
1 files changed, 363 insertions, 56 deletions
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php index 585e0df662b..42a1b0a3c23 100644 --- a/apps/user_ldap/tests/LDAPProviderTest.php +++ b/apps/user_ldap/tests/LDAPProviderTest.php @@ -3,6 +3,9 @@ * * @copyright Copyright (c) 2016, Roger Szabo (roger.szabo@web.de) * + * @author Roger Szabo <roger.szabo@web.de> + * @author Vinicius Brand <vinicius@eita.org.br> + * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -22,6 +25,8 @@ namespace OCA\User_LDAP\Tests; +use OCA\User_LDAP\IGroupLDAP; +use OCP\IConfig; use OCP\IServerContainer; use OCA\User_LDAP\IUserLDAP; @@ -38,21 +43,57 @@ class LDAPProviderTest extends \Test\TestCase { parent::setUp(); } - private function getServerMock(IUserLDAP $backend) { + private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { $server = $this->getMockBuilder('OC\Server') - ->setMethods(['getUserManager', 'getBackends']) + ->setMethods(['getUserManager', 'getBackends', 'getGroupManager']) ->setConstructorArgs(['', new \OC\Config(\OC::$configDir)]) ->getMock(); $server->expects($this->at(1)) ->method('getBackends') - ->willReturn([$backend]); + ->willReturn([$userBackend]); + $server->expects($this->any()) + ->method('getUserManager') + ->willReturn($this->getUserManagerMock($userBackend)); + $server->expects($this->any()) + ->method('getGroupManager') + ->willReturn($this->getGroupManagerMock($groupBackend)); $server->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); return $server; } + + private function getUserManagerMock(IUserLDAP $userBackend) { + $userManager = $this->getMockBuilder('OC\User\Manager') + ->setMethods(['getBackends']) + ->setConstructorArgs([$this->createMock(IConfig::class)]) + ->getMock(); + $userManager->expects($this->any()) + ->method('getBackends') + ->willReturn([$userBackend]); + return $userManager; + } + private function getGroupManagerMock(IGroupLDAP $groupBackend) { + $groupManager = $this->getMockBuilder('OC\Group\Manager') + ->setMethods(['getBackends']) + ->disableOriginalConstructor() + ->getMock(); + $groupManager->expects($this->any()) + ->method('getBackends') + ->willReturn([$groupBackend]); + return $groupManager; + } + + private function getDefaultGroupBackendMock() { + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + return $groupBackend; + } + private function getLDAPProvider(IServerContainer $serverContainer) { $factory = new \OCA\User_LDAP\LDAPProviderFactory($serverContainer); return $factory->getLDAPProvider(); @@ -63,50 +104,100 @@ class LDAPProviderTest extends \Test\TestCase { * @expectedExceptionMessage User id not found in LDAP */ public function testGetUserDNUserIDNotFound() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any())->method('userExists')->willReturn(false); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getUserDN('nonexisting_user'); } public function testGetUserDN() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'username2dn']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->at(0)) + $userBackend->expects($this->at(0)) ->method('userExists') ->willReturn(true); - $backend->expects($this->at(2)) + $userBackend->expects($this->at(2)) ->method('username2dn') ->willReturn('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org', $ldapProvider->getUserDN('existing_user')); } + /** + * @expectedException \Exception + * @expectedExceptionMessage Group id not found in LDAP + */ + public function testGetGroupDNGroupIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->getGroupDN('nonexisting_group'); + } + + public function testGetGroupDN() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->setMethods(['userExists', 'getLDAPAccess', 'username2dn']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists', 'getLDAPAccess', 'groupname2dn']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->at(0)) + ->method('groupExists') + ->willReturn(true); + $groupBackend->expects($this->at(2)) + ->method('groupname2dn') + ->willReturn('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); + $groupBackend->expects($this->any()) + ->method($this->anything()) + ->willReturnSelf(); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org', + $ldapProvider->getGroupDN('existing_group')); + } + public function testGetUserName() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['dn2UserName']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method('dn2UserName') ->willReturn('existing_user'); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('existing_user', @@ -114,12 +205,12 @@ class LDAPProviderTest extends \Test\TestCase { } public function testDNasBaseParameter() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); @@ -130,12 +221,12 @@ class LDAPProviderTest extends \Test\TestCase { } public function testSanitizeDN() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); @@ -150,69 +241,115 @@ class LDAPProviderTest extends \Test\TestCase { * @expectedExceptionMessage User id not found in LDAP */ public function testGetLDAPConnectionUserIDNotFound() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any())->method('userExists')->willReturn(false); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPConnection('nonexisting_user'); } public function testGetLDAPConnection() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getNewLDAPConnection']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method('userExists') ->willReturn(true); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method('getNewLDAPConnection') ->willReturn(true); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertTrue($ldapProvider->getLDAPConnection('existing_user')); } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Group id not found in LDAP + */ + public function testGetGroupLDAPConnectionGroupIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->getGroupLDAPConnection('nonexisting_group'); + } + + public function testGetGroupLDAPConnection() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists','getNewLDAPConnection']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->any()) + ->method('groupExists') + ->willReturn(true); + + $groupBackend->expects($this->any()) + ->method('getNewLDAPConnection') + ->willReturn(true); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $this->assertTrue($ldapProvider->getGroupLDAPConnection('existing_group')); + } /** * @expectedException \Exception * @expectedExceptionMessage User id not found in LDAP */ public function testGetLDAPBaseUsersUserIDNotFound() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any())->method('userExists')->willReturn(false); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPBaseUsers('nonexisting_user'); } public function testGetLDAPBaseUsers() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->at(0)) + $userBackend->expects($this->at(0)) ->method('userExists') ->willReturn(true); - $backend->expects($this->at(3)) + $userBackend->expects($this->at(3)) ->method('getConfiguration') ->willReturn(array('ldap_base_users'=>'ou=users,dc=example,dc=org')); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('ou=users,dc=example,dc=org', $ldapProvider->getLDAPBaseUsers('existing_user')); @@ -223,34 +360,34 @@ class LDAPProviderTest extends \Test\TestCase { * @expectedExceptionMessage User id not found in LDAP */ public function testGetLDAPBaseGroupsUserIDNotFound() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any())->method('userExists')->willReturn(false); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPBaseGroups('nonexisting_user'); } public function testGetLDAPBaseGroups() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->at(0)) + $userBackend->expects($this->at(0)) ->method('userExists') ->willReturn(true); - $backend->expects($this->at(3)) + $userBackend->expects($this->at(3)) ->method('getConfiguration') ->willReturn(array('ldap_base_groups'=>'ou=groups,dc=example,dc=org')); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('ou=groups,dc=example,dc=org', $ldapProvider->getLDAPBaseGroups('existing_user')); @@ -261,62 +398,107 @@ class LDAPProviderTest extends \Test\TestCase { * @expectedExceptionMessage User id not found in LDAP */ public function testClearCacheUserIDNotFound() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any())->method('userExists')->willReturn(false); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->clearCache('nonexisting_user'); } public function testClearCache() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'clearCache']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->at(0)) + $userBackend->expects($this->at(0)) ->method('userExists') ->willReturn(true); - $backend->expects($this->at(3)) + $userBackend->expects($this->at(3)) ->method('clearCache') ->willReturn(true); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->clearCache('existing_user'); $this->assertTrue(TRUE); } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Group id not found in LDAP + */ + public function testClearGroupCacheGroupIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists']) + ->disableOriginalConstructor() + ->getMock(); + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->clearGroupCache('nonexisting_group'); + } + + public function testClearGroupCache() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists', 'getLDAPAccess', 'getConnection', 'clearCache']) + ->disableOriginalConstructor() + ->getMock(); + $groupBackend->expects($this->at(0)) + ->method('groupExists') + ->willReturn(true); + $groupBackend->expects($this->at(3)) + ->method('clearCache') + ->willReturn(true); + $groupBackend->expects($this->any()) + ->method($this->anything()) + ->willReturnSelf(); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->clearGroupCache('existing_group'); + $this->assertTrue(TRUE); + } public function testDnExists() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['dn2UserName']) ->disableOriginalConstructor() ->getMock(); - $backend->expects($this->any()) + $userBackend->expects($this->any()) ->method('dn2UserName') ->willReturn('existing_user'); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); } public function testFlagRecord() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->flagRecord('existing_user'); @@ -324,15 +506,140 @@ class LDAPProviderTest extends \Test\TestCase { } public function testUnflagRecord() { - $backend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $server = $this->getServerMock($backend); + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->unflagRecord('existing_user'); $this->assertTrue(TRUE); } + + /** + * @expectedException \Exception + * @expectedExceptionMessage User id not found in LDAP + */ + public function testGetLDAPDisplayNameFieldUserIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->setMethods(['userExists']) + ->disableOriginalConstructor() + ->getMock(); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->getLDAPDisplayNameField('nonexisting_user'); + } + + public function testGetLDAPDisplayNameField() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration']) + ->disableOriginalConstructor() + ->getMock(); + $userBackend->expects($this->at(0)) + ->method('userExists') + ->willReturn(true); + $userBackend->expects($this->at(3)) + ->method('getConfiguration') + ->willReturn(array('ldap_display_name'=>'displayName')); + $userBackend->expects($this->any()) + ->method($this->anything()) + ->willReturnSelf(); + + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); + + $ldapProvider = $this->getLDAPProvider($server); + $this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user')); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage User id not found in LDAP + */ + public function testGetLDAPEmailFieldUserIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->setMethods(['userExists']) + ->disableOriginalConstructor() + ->getMock(); + $userBackend->expects($this->any())->method('userExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->getLDAPEmailField('nonexisting_user'); + } + + public function testGetLDAPEmailField() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration']) + ->disableOriginalConstructor() + ->getMock(); + $userBackend->expects($this->at(0)) + ->method('userExists') + ->willReturn(true); + $userBackend->expects($this->at(3)) + ->method('getConfiguration') + ->willReturn(array('ldap_email_attr'=>'mail')); + $userBackend->expects($this->any()) + ->method($this->anything()) + ->willReturnSelf(); + + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); + + $ldapProvider = $this->getLDAPProvider($server); + $this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user')); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Group id not found in LDAP + */ + public function testGetLDAPGroupMemberAssocUserIDNotFound() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $ldapProvider->getLDAPGroupMemberAssoc('nonexisting_group'); + } + + public function testgetLDAPGroupMemberAssoc() { + $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') + ->setMethods(['groupExists', 'getLDAPAccess', 'getConnection', 'getConfiguration']) + ->disableOriginalConstructor() + ->getMock(); + + $groupBackend->expects($this->at(0)) + ->method('groupExists') + ->willReturn(true); + $groupBackend->expects($this->any()) + ->method('getConfiguration') + ->willReturn(array('ldap_group_member_assoc_attribute'=>'assoc_type')); + $groupBackend->expects($this->any()) + ->method($this->anything()) + ->willReturnSelf(); + + $server = $this->getServerMock($userBackend, $groupBackend); + + $ldapProvider = $this->getLDAPProvider($server); + $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); + } + } |