diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-11-07 13:19:08 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-11-09 11:10:59 +0100 |
commit | 3ba8b337a41a9142e11d7b959cd9cfd7a47fbcbf (patch) | |
tree | f5a08251ca21e47c834b3196d19d33cc1282fcc7 /apps/user_ldap/tests | |
parent | 8113f26eedd06235cee9ba0456060c25965b837b (diff) | |
download | nextcloud-server-3ba8b337a41a9142e11d7b959cd9cfd7a47fbcbf.tar.gz nextcloud-server-3ba8b337a41a9142e11d7b959cd9cfd7a47fbcbf.zip |
fix unit tests after rebase
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 102 | ||||
-rw-r--r-- | apps/user_ldap/tests/User_LDAPTest.php | 13 |
2 files changed, 67 insertions, 48 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index b3b2d68f94b..e758bc9bd02 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -32,6 +32,7 @@ namespace OCA\User_LDAP\Tests; +use OCA\User_LDAP\GroupPluginManager; use OCP\GroupInterface; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; @@ -159,6 +160,7 @@ class Group_LDAPTest extends \Test\TestCase { } public function testCountUsersWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','countUsersInGroup']) ->getMock(); @@ -173,10 +175,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with('gid', 'search') ->willReturn(42); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->countUsersInGroup('gid', 'search'),42); } @@ -727,6 +729,7 @@ class Group_LDAPTest extends \Test\TestCase { } public function testCreateGroupWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','createGroup']) ->getMock(); @@ -741,10 +744,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with('gid') ->willReturn('result'); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->createGroup('gid'),true); } @@ -753,6 +756,7 @@ class Group_LDAPTest extends \Test\TestCase { * @expectedException \Exception */ public function testCreateGroupFailing() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions', 'createGroup']) ->getMock(); @@ -762,15 +766,16 @@ class Group_LDAPTest extends \Test\TestCase { ->with(GroupInterface::CREATE_GROUP) ->willReturn(false); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $ldap->createGroup('gid'); } public function testDeleteGroupWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','deleteGroup']) ->getMock(); @@ -785,21 +790,19 @@ class Group_LDAPTest extends \Test\TestCase { ->with('gid') ->willReturn('result'); - $access = $this->getAccessMock(); - $mapper = $this->getMockBuilder('\OCA\User_LDAP\Mapping\GroupMapping') ->setMethods(['unmap']) ->disableOriginalConstructor() ->getMock(); + $access = $this->getAccessMock(); $access->expects($this->any()) ->method('getGroupMapper') ->will($this->returnValue($mapper)); - $ldap = new GroupLDAP( - $access, - $pluginManager - ); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->deleteGroup('gid'),'result'); } @@ -808,6 +811,7 @@ class Group_LDAPTest extends \Test\TestCase { * @expectedException \Exception */ public function testDeleteGroupFailing() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions', 'deleteGroup']) ->getMock(); @@ -817,15 +821,16 @@ class Group_LDAPTest extends \Test\TestCase { ->with(GroupInterface::DELETE_GROUP) ->willReturn(false); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $ldap->deleteGroup('gid'); } public function testAddToGroupWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','addToGroup']) ->getMock(); @@ -840,10 +845,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with('uid', 'gid') ->willReturn('result'); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->addToGroup('uid', 'gid'),'result'); } @@ -852,6 +857,7 @@ class Group_LDAPTest extends \Test\TestCase { * @expectedException \Exception */ public function testAddToGroupFailing() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions', 'addToGroup']) ->getMock(); @@ -861,15 +867,16 @@ class Group_LDAPTest extends \Test\TestCase { ->with(GroupInterface::ADD_TO_GROUP) ->willReturn(false); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $ldap->addToGroup('uid', 'gid'); } public function testRemoveFromGroupWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','removeFromGroup']) ->getMock(); @@ -884,10 +891,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with('uid', 'gid') ->willReturn('result'); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->removeFromGroup('uid', 'gid'),'result'); } @@ -896,6 +903,7 @@ class Group_LDAPTest extends \Test\TestCase { * @expectedException \Exception */ public function testRemoveFromGroupFailing() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions', 'removeFromGroup']) ->getMock(); @@ -905,15 +913,16 @@ class Group_LDAPTest extends \Test\TestCase { ->with(GroupInterface::REMOVE_FROM_GROUP) ->willReturn(false); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $ldap->removeFromGroup('uid', 'gid'); } public function testGetGroupDetailsWithPlugin() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions','getGroupDetails']) ->getMock(); @@ -928,10 +937,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with('gid') ->willReturn('result'); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $this->assertEquals($ldap->getGroupDetails('gid'),'result'); } @@ -940,6 +949,7 @@ class Group_LDAPTest extends \Test\TestCase { * @expectedException \Exception */ public function testGetGroupDetailsFailing() { + /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') ->setMethods(['implementsActions', 'getGroupDetails']) ->getMock(); @@ -949,10 +959,10 @@ class Group_LDAPTest extends \Test\TestCase { ->with(GroupInterface::GROUP_DETAILS) ->willReturn(false); - $ldap = new GroupLDAP( - $this->getAccessMock(), - $pluginManager - ); + $access = $this->getAccessMock(); + $access->connection = $this->createMock(Connection::class); + + $ldap = new GroupLDAP($access, $pluginManager); $ldap->getGroupDetails('gid'); } diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 0f48d5b3547..5b53cc3da2c 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -210,9 +210,11 @@ class User_LDAPTest extends TestCase { $access = $this->getAccessMock(); $this->prepareAccessForCheckPassword($access); + $access->userManager->expects($this->any()) + ->method('get') + ->willReturn($user); $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); - ->willReturn($user); \OC_User::useBackend($backend); @@ -266,10 +268,11 @@ class User_LDAPTest extends TestCase { $access = $this->getAccessMock(); $this->prepareAccessForCheckPassword($access); - $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); + $access->userManager->expects($this->any()) ->method('get') ->willReturn($user); + $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); $result = \OCP\User::checkPassword('roland', 'dt19'); @@ -1196,6 +1199,7 @@ class User_LDAPTest extends TestCase { ->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo($username)); $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); + $user = $this->createMock(User::class); $user->expects($this->any()) ->method('getUsername') ->willReturn('alice'); @@ -1363,6 +1367,11 @@ class User_LDAPTest extends TestCase { $access = $this->getAccessMock(); $this->prepareAccessForSetPassword($access); + + $access->userManager->expects($this->any()) + ->method('get') + ->willReturn($this->createMock(User::class)); + $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); $access->userManager->expects($this->any()) ->method('get') |