summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-11-08 01:51:14 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-11-09 11:10:59 +0100
commit419759e68bcd83be1fe7564824955a897183b76c (patch)
tree55351a5615c1a6a3dac351d1e7634073ec8cf789 /apps/user_ldap/tests
parent3ba8b337a41a9142e11d7b959cd9cfd7a47fbcbf (diff)
downloadnextcloud-server-419759e68bcd83be1fe7564824955a897183b76c.tar.gz
nextcloud-server-419759e68bcd83be1fe7564824955a897183b76c.zip
resolve DI
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/AccessTest.php41
-rw-r--r--apps/user_ldap/tests/Integration/AbstractIntegrationTest.php2
-rw-r--r--apps/user_ldap/tests/Jobs/SyncTest.php40
3 files changed, 41 insertions, 42 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index b730ccf2b31..6c250ff320f 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -48,7 +48,6 @@ use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Image;
-use OCP\IServerContainer;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use Test\TestCase;
@@ -69,8 +68,8 @@ class AccessTest extends TestCase {
private $userManager;
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
private $helper;
- /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
- private $c;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
/** @var Access */
private $access;
@@ -79,14 +78,14 @@ class AccessTest extends TestCase {
$this->ldap = $this->createMock(LDAP::class);
$this->userManager = $this->createMock(Manager::class);
$this->helper = $this->createMock(Helper::class);
- $this->c = $this->createMock(IServerContainer::class);
+ $this->config = $this->createMock(IConfig::class);
$this->access = new Access(
$this->connection,
$this->ldap,
$this->userManager,
$this->helper,
- $this->c
+ $this->config
);
}
@@ -221,9 +220,9 @@ class AccessTest extends TestCase {
*/
public function testStringResemblesDN($case) {
list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock();
- /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
- $c = $this->createMock(IServerContainer::class);
- $access = new Access($con, $lw, $um, $helper, $c);
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
+ $access = new Access($con, $lw, $um, $helper, $config);
$lw->expects($this->exactly(1))
->method('explodeDN')
@@ -243,10 +242,10 @@ class AccessTest extends TestCase {
*/
public function testStringResemblesDNLDAPmod($case) {
list(, $con, $um, $helper) = $this->getConnectorAndLdapMock();
- /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
- $c = $this->createMock(IServerContainer::class);
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
$lw = new LDAP();
- $access = new Access($con, $lw, $um, $helper, $c);
+ $access = new Access($con, $lw, $um, $helper, $config);
if(!function_exists('ldap_explode_dn')) {
$this->markTestSkipped('LDAP Module not available');
@@ -312,10 +311,6 @@ class AccessTest extends TestCase {
->method('get')
->will($this->returnValue($userMock));
- $this->c->expects($this->any())
- ->method('getConfig')
- ->willReturn($this->createMock(IConfig::class));
-
$this->access->batchApplyUserAttributes($data);
}
@@ -357,10 +352,6 @@ class AccessTest extends TestCase {
->method('get')
->willReturn($this->createMock(User::class));
- $this->c->expects($this->any())
- ->method('getConfig')
- ->willReturn($this->createMock(IConfig::class));
-
$this->access->batchApplyUserAttributes($data);
}
@@ -402,12 +393,6 @@ class AccessTest extends TestCase {
->method('get')
->will($this->returnValue($userMock));
- $configMock = $this->createMock(IConfig::class);
-
- $this->c->expects($this->any())
- ->method('getConfig')
- ->willReturn($configMock);
-
$this->access->batchApplyUserAttributes($data);
}
@@ -427,8 +412,8 @@ class AccessTest extends TestCase {
*/
public function testSanitizeDN($attribute) {
list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock();
- /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
- $c = $this->createMock(IServerContainer::class);
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
@@ -441,7 +426,7 @@ class AccessTest extends TestCase {
$attribute => array('count' => 1, $dnFromServer)
)));
- $access = new Access($con, $lw, $um, $helper, $c);
+ $access = new Access($con, $lw, $um, $helper, $config);
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
$this->assertSame($values[0], strtolower($dnFromServer));
}
diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
index 64bd2df3885..8d29df6ede6 100644
--- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
+++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
@@ -140,7 +140,7 @@ abstract class AbstractIntegrationTest {
* initializes the Access test instance
*/
protected function initAccess() {
- $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server);
+ $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig());
}
/**
diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index 6b11c6145e8..f8a44de87e8 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -28,16 +28,17 @@ use OCA\User_LDAP\Jobs\Sync;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
+use OCP\IAvatarManager;
use OCP\IConfig;
-use OCP\IServerContainer;
+use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Notification\IManager;
use Test\TestCase;
class SyncTest extends TestCase {
/** @var array */
protected $arguments;
- /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
- protected $c;
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
protected $helper;
/** @var LDAP|\PHPUnit_Framework_MockObject_MockObject */
@@ -48,22 +49,40 @@ class SyncTest extends TestCase {
protected $mapper;
/** @var Sync */
protected $sync;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $avatarManager;
+ /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
+ protected $dbc;
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $ncUserManager;
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $notificationManager;
public function setUp() {
parent::setUp();
- $this->c = $this->createMock(IServerContainer::class);
$this->helper = $this->createMock(Helper::class);
$this->ldapWrapper = $this->createMock(LDAP::class);
$this->userManager = $this->createMock(Manager::class);
$this->mapper = $this->createMock(UserMapping::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->avatarManager = $this->createMock(IAvatarManager::class);
+ $this->dbc = $this->createMock(IDBConnection::class);
+ $this->ncUserManager = $this->createMock(IUserManager::class);
+ $this->notificationManager = $this->createMock(IManager::class);
$this->arguments = [
- 'c' => $this->c,
'helper' => $this->helper,
'ldapWrapper' => $this->ldapWrapper,
'userManager' => $this->userManager,
'mapper' => $this->mapper,
+ 'config' => $this->config,
+ 'avatarManager' => $this->avatarManager,
+ 'dbc' => $this->dbc,
+ 'ncUserManager' => $this->ncUserManager,
+ 'notificationManager' => $this->notificationManager,
];
$this->sync = new Sync();
@@ -93,8 +112,7 @@ class SyncTest extends TestCase {
* @dataProvider intervalDataProvider
*/
public function testUpdateInterval($userCount, $pagingSize1, $pagingSize2) {
- $config = $this->createMock(IConfig::class);
- $config->expects($this->once())
+ $this->config->expects($this->once())
->method('setAppValue')
->with('user_ldap', 'background_sync_interval', $this->anything())
->willReturnCallback(function($a, $k, $interval) {
@@ -102,7 +120,7 @@ class SyncTest extends TestCase {
$this->assertTrue($interval <= SYNC::MAX_INTERVAL);
return true;
});
- $config->expects($this->atLeastOnce())
+ $this->config->expects($this->atLeastOnce())
->method('getAppKeys')
->willReturn([
'blabla',
@@ -111,14 +129,10 @@ class SyncTest extends TestCase {
'installed',
's07ldap_paging_size'
]);
- $config->expects($this->exactly(2))
+ $this->config->expects($this->exactly(2))
->method('getAppValue')
->willReturnOnConsecutiveCalls($pagingSize1, $pagingSize2);
- $this->c->expects($this->any())
- ->method('getConfig')
- ->willReturn($config);
-
$this->mapper->expects($this->atLeastOnce())
->method('count')
->willReturn($userCount);