Skip to content
Snippets Groups Projects
Commit e07ebdd7 authored by Arthur Schiwon's avatar Arthur Schiwon
Browse files

adjust user backend test

parent e32fa3de
Branches
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ use \OCA\user_ldap\lib\ILDAPWrapper; ...@@ -29,6 +29,7 @@ use \OCA\user_ldap\lib\ILDAPWrapper;
class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
protected $backend; protected $backend;
protected $access;
public function setUp() { public function setUp() {
\OC_User::clearBackends(); \OC_User::clearBackends();
...@@ -38,18 +39,37 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -38,18 +39,37 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
private function getAccessMock() { private function getAccessMock() {
static $conMethods; static $conMethods;
static $accMethods; static $accMethods;
static $umMethods;
static $uMethods;
if(is_null($conMethods) || is_null($accMethods)) { if(is_null($conMethods) || is_null($accMethods) || is_null($umMethods)) {
$conMethods = get_class_methods('\OCA\user_ldap\lib\Connection'); $conMethods = get_class_methods('\OCA\user_ldap\lib\Connection');
$accMethods = get_class_methods('\OCA\user_ldap\lib\Access'); $accMethods = get_class_methods('\OCA\user_ldap\lib\Access');
unset($accMethods[array_search('getConnection', $accMethods)]);
$umMethods = get_class_methods('\OCA\user_ldap\lib\user\Manager');
$uMethods = get_class_methods('\OCA\user_ldap\lib\user\User');
unset($uMethods[array_search('getUsername', $uMethods)]);
unset($uMethods[array_search('getDN', $uMethods)]);
unset($uMethods[array_search('__construct', $uMethods)]);
} }
$lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper'); $lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper');
$connector = $this->getMock('\OCA\user_ldap\lib\Connection', $connector = $this->getMock('\OCA\user_ldap\lib\Connection',
$conMethods, $conMethods,
array($lw, null, null)); array($lw, null, null));
$um = new \OCA\user_ldap\lib\user\Manager(
$this->getMock('\OCP\IConfig'),
$this->getMock('\OCA\user_ldap\lib\FilesystemHelper'),
$this->getMock('\OCA\user_ldap\lib\LogWrapper'),
$this->getMock('\OCP\IAvatarManager'),
$this->getMock('\OCP\Image')
);
$access = $this->getMock('\OCA\user_ldap\lib\Access', $access = $this->getMock('\OCA\user_ldap\lib\Access',
$accMethods, $accMethods,
array($connector, $lw)); array($connector, $lw, $um));
$um->setLdapAccess($access);
return $access; return $access;
} }
...@@ -60,16 +80,16 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -60,16 +80,16 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
->will($this->returnCallback(function($uid) { ->will($this->returnCallback(function($uid) {
switch ($uid) { switch ($uid) {
case 'gunslinger': case 'gunslinger':
return 'dnOfRoland'; return 'dnOfRoland,dc=test';
break; break;
case 'formerUser': case 'formerUser':
return 'dnOfFormerUser'; return 'dnOfFormerUser,dc=test';
break; break;
case 'newyorker': case 'newyorker':
return 'dnOfNewYorker'; return 'dnOfNewYorker,dc=test';
break; break;
case 'ladyofshadows': case 'ladyofshadows':
return 'dnOfLadyOfShadows'; return 'dnOfLadyOfShadows,dc=test';
break; break;
default: default:
return false; return false;
...@@ -102,14 +122,14 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -102,14 +122,14 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
->method('fetchListOfUsers') ->method('fetchListOfUsers')
->will($this->returnCallback(function($filter) { ->will($this->returnCallback(function($filter) {
if($filter === 'roland') { if($filter === 'roland') {
return array('dnOfRoland'); return array('dnOfRoland,dc=test');
} }
return array(); return array();
})); }));
$access->expects($this->any()) $access->expects($this->any())
->method('dn2username') ->method('dn2username')
->with($this->equalTo('dnOfRoland')) ->with($this->equalTo('dnOfRoland,dc=test'))
->will($this->returnValue('gunslinger')); ->will($this->returnValue('gunslinger'));
$access->expects($this->any()) $access->expects($this->any())
...@@ -337,7 +357,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -337,7 +357,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$access->expects($this->any()) $access->expects($this->any())
->method('readAttribute') ->method('readAttribute')
->will($this->returnCallback(function($dn) { ->will($this->returnCallback(function($dn) {
if($dn === 'dnOfRoland') { if($dn === 'dnOfRoland,dc=test') {
return array(); return array();
} }
return false; return false;
...@@ -365,7 +385,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -365,7 +385,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
$access->expects($this->any()) $access->expects($this->any())
->method('readAttribute') ->method('readAttribute')
->will($this->returnCallback(function($dn) { ->will($this->returnCallback(function($dn) {
if($dn === 'dnOfRoland') { if($dn === 'dnOfRoland,dc=test') {
return array(); return array();
} }
return false; return false;
...@@ -411,13 +431,13 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -411,13 +431,13 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
->method('readAttribute') ->method('readAttribute')
->will($this->returnCallback(function($dn, $attr) { ->will($this->returnCallback(function($dn, $attr) {
switch ($dn) { switch ($dn) {
case 'dnOfRoland': case 'dnOfRoland,dc=test':
if($attr === 'testAttribute') { if($attr === 'testAttribute') {
return array('/tmp/rolandshome/'); return array('/tmp/rolandshome/');
} }
return array(); return array();
break; break;
case 'dnOfLadyOfShadows': case 'dnOfLadyOfShadows,dc=test':
if($attr === 'testAttribute') { if($attr === 'testAttribute') {
return array('susannah/'); return array('susannah/');
} }
...@@ -457,7 +477,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase { ...@@ -457,7 +477,7 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
->method('readAttribute') ->method('readAttribute')
->will($this->returnCallback(function($dn, $attr) { ->will($this->returnCallback(function($dn, $attr) {
switch ($dn) { switch ($dn) {
case 'dnOfRoland': case 'dnOfRoland,dc=test':
if($attr === 'displayname') { if($attr === 'displayname') {
return array('Roland Deschain'); return array('Roland Deschain');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment