aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-11-03 17:40:05 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-11-09 11:10:58 +0100
commitfc6b3902af03b770bc1de29cae50fb00022f355d (patch)
treedd345a51a1730c97fc69c168d6d11486ab2e0942
parent59c05d54472aeed458611341970a72e42e5b9e6a (diff)
downloadnextcloud-server-fc6b3902af03b770bc1de29cae50fb00022f355d.tar.gz
nextcloud-server-fc6b3902af03b770bc1de29cae50fb00022f355d.zip
adjust tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/user_ldap/tests/AccessTest.php9
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php33
-rw-r--r--apps/user_ldap/tests/User/UserTest.php481
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php266
-rw-r--r--apps/user_ldap/tests/WizardTest.php27
5 files changed, 413 insertions, 403 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 047fe7c3fb0..b730ccf2b31 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -353,8 +353,9 @@ class AccessTest extends TestCase {
$userMock->expects($this->never())
->method('processAttributes');
- $this->userManager->expects($this->never())
- ->method('get');
+ $this->userManager->expects($this->any())
+ ->method('get')
+ ->willReturn($this->createMock(User::class));
$this->c->expects($this->any())
->method('getConfig')
@@ -402,10 +403,6 @@ class AccessTest extends TestCase {
->will($this->returnValue($userMock));
$configMock = $this->createMock(IConfig::class);
- $configMock->expects($this->once())
- ->method('getAppValue')
- ->with('core', 'backgroundjobs_mode', $this->anything())
- ->willReturn('ajax');
$this->c->expects($this->any())
->method('getConfig')
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index 8eabf2d295a..b3b2d68f94b 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -33,8 +33,11 @@
namespace OCA\User_LDAP\Tests;
use OCP\GroupInterface;
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Group_LDAP as GroupLDAP;
use OCA\User_LDAP\ILDAPWrapper;
+use OCA\User_LDAP\User\Manager;
/**
* Class GroupLDAPTest
@@ -44,6 +47,9 @@ use OCA\User_LDAP\ILDAPWrapper;
* @package OCA\User_LDAP\Tests
*/
class Group_LDAPTest extends \Test\TestCase {
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|Access
+ */
private function getAccessMock() {
static $conMethods;
static $accMethods;
@@ -57,14 +63,8 @@ class Group_LDAPTest extends \Test\TestCase {
->setMethods($conMethods)
->setConstructorArgs([$lw, null, null])
->getMock();
- $um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
- ->disableOriginalConstructor()
- ->getMock();
- $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
- $access = $this->getMockBuilder('\OCA\User_LDAP\Access')
- ->setMethods($accMethods)
- ->setConstructorArgs([$connector, $lw, $um, $helper])
- ->getMock();
+
+ $access = $this->createMock(Access::class);
$access->expects($this->any())
->method('getConnection')
@@ -76,8 +76,13 @@ class Group_LDAPTest extends \Test\TestCase {
private function getPluginManagerMock() {
return $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')->getMock();
}
-
+
+ /**
+ * @param Access|\PHPUnit_Framework_MockObject_MockObject $access
+ */
private function enableGroups($access) {
+ $access->connection = $this->createMock(Connection::class);
+
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
@@ -498,7 +503,6 @@ class Group_LDAPTest extends \Test\TestCase {
$access->connection->expects($this->any())
->method('getFromCache')
->will($this->returnValue(null));
-
$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn, $attr) {
@@ -509,14 +513,13 @@ class Group_LDAPTest extends \Test\TestCase {
}
return array();
}));
-
$access->expects($this->any())
->method('groupname2dn')
->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
-
$access->expects($this->exactly(2))
->method('nextcloudUserNames')
->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']);
+ $access->userManager = $this->createMock(Manager::class);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->usersInGroup('foobar');
@@ -537,7 +540,6 @@ class Group_LDAPTest extends \Test\TestCase {
$access->connection->expects($this->any())
->method('getFromCache')
->will($this->returnValue(null));
-
$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn, $attr) {
@@ -546,14 +548,13 @@ class Group_LDAPTest extends \Test\TestCase {
}
return array();
}));
-
$access->expects($this->any())
->method('groupname2dn')
->will($this->returnValue('cn=foobar,dc=foo,dc=bar'));
-
$access->expects($this->once())
->method('nextcloudUserNames')
->will($this->returnValue(array('lisa', 'bart', 'kira', 'brad')));
+ $access->userManager = $this->createMock(Manager::class);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->usersInGroup('foobar');
@@ -635,6 +636,7 @@ class Group_LDAPTest extends \Test\TestCase {
$access = $this->getAccessMock();
$pluginManager = $this->getPluginManagerMock();
+ $access->connection = $this->createMock(Connection::class);
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
@@ -671,6 +673,7 @@ class Group_LDAPTest extends \Test\TestCase {
$access = $this->getAccessMock();
$pluginManager = $this->getPluginManagerMock();
+ $access->connection = $this->createMock(Connection::class);
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index ede60fef5c0..5e911159285 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -29,6 +29,8 @@
namespace OCA\User_LDAP\Tests\User;
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\Connection;
use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LogWrapper;
@@ -52,6 +54,23 @@ use OCP\Notification\INotification;
* @package OCA\User_LDAP\Tests\User
*/
class UserTest extends \Test\TestCase {
+ /** @var Access|\PHPUnit_Framework_MockObject_MockObject */
+ protected $access;
+ /** @var Connection|\PHPUnit_Framework_MockObject_MockObject */
+ protected $connection;
+
+ public function setUp() {
+ /** @var Access|\PHPUnit_Framework_MockObject_MockObject access */
+ $this->access = $this->createMock(Access::class);
+ $this->connection = $this->createMock(Connection::class);
+
+ $this->access->connection = $this->connection;
+ $this->access->expects($this->any())
+ ->method('getConnection')
+ ->willReturn($this->connection);
+
+ parent::setUp();
+ }
private function getTestInstances() {
$access = $this->createMock(IUserTools::class);
@@ -67,43 +86,6 @@ class UserTest extends \Test\TestCase {
return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
}
- private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc, $userMgr = null, $notiMgr = null) {
- static $conMethods;
- static $accMethods;
- static $umMethods;
-
- if(is_null($conMethods) || is_null($accMethods)) {
- $conMethods = get_class_methods('\OCA\User_LDAP\Connection');
- $accMethods = get_class_methods('\OCA\User_LDAP\Access');
- //getConnection shall not be replaced
- unset($accMethods[array_search('getConnection', $accMethods)]);
- $umMethods = get_class_methods('\OCA\User_LDAP\User\Manager');
- }
- $lw = $this->createMock(ILDAPWrapper::class);
- $im = $this->createMock(Image::class);
- if (is_null($userMgr)) {
- $userMgr = $this->createMock(IUserManager::class);
- }
- if (is_null($notiMgr)) {
- $notiMgr = $this->createMock(INotificationManager::class);
- }
- $um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
- ->setMethods($umMethods)
- ->setConstructorArgs([$cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc, $userMgr, $notiMgr])
- ->getMock();
- $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
- $connector = $this->getMockBuilder('\OCA\User_LDAP\Connection')
- ->setMethods($conMethods)
- ->setConstructorArgs([$lw, null, null])
- ->getMock();
- $access = $this->getMockBuilder('\OCA\User_LDAP\Access')
- ->setMethods($accMethods)
- ->setConstructorArgs([$connector, $lw, $um, $helper])
- ->getMock();
-
- return array($access, $connector);
- }
-
public function testGetDNandUsername() {
list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
@@ -119,18 +101,15 @@ class UserTest extends \Test\TestCase {
}
public function testUpdateEmailProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
-
- $connection->expects($this->once())
+ $this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
->will($this->returnValue('email'));
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('email'))
@@ -150,24 +129,20 @@ class UserTest extends \Test\TestCase {
->method('get')
->willReturn($uuser);
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateEmailNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->once())
+ $this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
->will($this->returnValue('email'));
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('email'))
@@ -180,24 +155,21 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateEmailNotConfigured() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->once())
+ $this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
->will($this->returnValue(''));
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('readAttribute');
$config->expects($this->never())
@@ -207,34 +179,23 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateQuotaAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- /* Having a quota defined, the ldapQuotaDefault won't be used
- $connection->expects($this->at(1))
- ->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue('23 GB'));
- */
-
- $connection->expects($this->exactly(1))
+ $this->connection->expects($this->exactly(1))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -254,27 +215,23 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaToDefaultAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->exactly(1))
+ $this->connection->expects($this->exactly(1))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -294,7 +251,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -303,18 +260,14 @@ class UserTest extends \Test\TestCase {
list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->exactly(1))
+ $this->connection->expects($this->exactly(1))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -334,32 +287,27 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaDefaultProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue('25 GB'));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -379,34 +327,23 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaIndividualProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- /* Having a quota set this won't be used
- $connection->expects($this->at(1))
- ->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue(''));
- */
-
- $connection->expects($this->exactly(1))
+ $this->connection->expects($this->exactly(1))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -426,32 +363,27 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue(''));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -473,29 +405,24 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneConfigured() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue(''));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue(''));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
$user = $this->createMock('\OCP\IUser');
@@ -507,8 +434,7 @@ class UserTest extends \Test\TestCase {
->with('alice')
->will($this->returnValue($user));
-
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('readAttribute');
$config->expects($this->never())
@@ -518,25 +444,22 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaFromValue() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$readQuota = '19 GB';
- $connection->expects($this->never())
+ $this->connection->expects($this->never())
->method('__get')
->with($this->equalTo('ldapQuotaDefault'));
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('readAttribute');
$user = $this->createMock(IUser::class);
@@ -553,7 +476,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota($readQuota);
}
@@ -562,26 +485,21 @@ class UserTest extends \Test\TestCase {
* Unparseable quota will fallback to use the LDAP default
*/
public function testUpdateWrongQuotaAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue('23 GB'));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -601,7 +519,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -610,26 +528,21 @@ class UserTest extends \Test\TestCase {
* No user quota and wrong default will set 'default' as quota
*/
public function testUpdateWrongDefaultQuotaProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue('23 GBwowowo'));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -648,7 +561,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -657,26 +570,21 @@ class UserTest extends \Test\TestCase {
* Wrong user quota and wrong default will set 'default' as quota
*/
public function testUpdateWrongQuotaAndDefaultAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue('23 GBwowowo'));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('myquota'))
@@ -695,7 +603,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -704,26 +612,21 @@ class UserTest extends \Test\TestCase {
* No quota attribute set and wrong default will set 'default' as quota
*/
public function testUpdateWrongDefaultQuotaNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->at(0))
+ $this->connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue(''));
-
- $connection->expects($this->at(1))
+ $this->connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue('23 GBwowowo'));
-
- $connection->expects($this->exactly(2))
+ $this->connection->expects($this->exactly(2))
->method('__get');
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('readAttribute');
$user = $this->createMock('\OCP\IUser');
@@ -739,20 +642,17 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
//the testUpdateAvatar series also implicitely tests getAvatarImage
public function testUpdateAvatarJpegPhotoProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('jpegPhoto'))
@@ -789,32 +689,29 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateAvatarThumbnailPhotoProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $access->expects($this->at(0))
+ $this->access->expects($this->any())
->method('readAttribute')
- ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('jpegPhoto'))
- ->will($this->returnValue(false));
-
- $access->expects($this->at(1))
- ->method('readAttribute')
- ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('thumbnailPhoto'))
- ->will($this->returnValue(array('this is a photo')));
-
- $access->expects($this->exactly(2))
- ->method('readAttribute');
+ ->willReturnCallback(function($dn, $attr) {
+ if($dn === 'uid=alice,dc=foo,dc=bar'
+ && $attr === 'jpegPhoto')
+ {
+ return false;
+ } elseif($dn === 'uid=alice,dc=foo,dc=bar'
+ && $attr === 'thumbnailPhoto')
+ {
+ return ['this is a photo'];
+ }
+ return null;
+ });
$image->expects($this->once())
->method('valid')
@@ -847,32 +744,29 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateAvatarNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $access->expects($this->at(0))
- ->method('readAttribute')
- ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('jpegPhoto'))
- ->will($this->returnValue(false));
-
- $access->expects($this->at(1))
+ $this->access->expects($this->any())
->method('readAttribute')
- ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('thumbnailPhoto'))
- ->will($this->returnValue(false));
-
- $access->expects($this->exactly(2))
- ->method('readAttribute');
+ ->willReturnCallback(function($dn, $attr) {
+ if($dn === 'uid=alice,dc=foo,dc=bar'
+ && $attr === 'jpegPhoto')
+ {
+ return false;
+ } elseif($dn === 'uid=alice,dc=foo,dc=bar'
+ && $attr === 'thumbnailPhoto')
+ {
+ return false;
+ }
+ return null;
+ });
$image->expects($this->never())
->method('valid');
@@ -893,35 +787,29 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateBeforeFirstLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$config->expects($this->at(0))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
$this->equalTo(0))
->will($this->returnValue(0));
-
$config->expects($this->at(1))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
$this->equalTo(0))
->will($this->returnValue(0));
-
$config->expects($this->exactly(2))
->method('getUserValue');
-
$config->expects($this->never())
->method('setUserValue');
@@ -929,35 +817,29 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testUpdateAfterFirstLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$config->expects($this->at(0))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
$this->equalTo(0))
->will($this->returnValue(1));
-
$config->expects($this->at(1))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
$this->equalTo(0))
->will($this->returnValue(0));
-
$config->expects($this->exactly(2))
->method('getUserValue');
-
$config->expects($this->once())
->method('setUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
@@ -969,35 +851,29 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testUpdateNoRefresh() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$config->expects($this->at(0))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
$this->equalTo(0))
->will($this->returnValue(1));
-
$config->expects($this->at(1))
->method('getUserValue')
->with($this->equalTo('alice'), $this->equalTo('user_ldap'),
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
$this->equalTo(0))
->will($this->returnValue(time()));
-
$config->expects($this->exactly(2))
->method('getUserValue');
-
$config->expects($this->never())
->method('setUserValue');
@@ -1005,13 +881,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testMarkLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
$config->expects($this->once())
@@ -1026,16 +902,16 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->markLogin();
}
public function testGetAvatarImageProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('jpegPhoto'))
@@ -1045,7 +921,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$photo = $user->getAvatarImage();
$this->assertSame('this is a photo', $photo);
@@ -1055,12 +931,9 @@ class UserTest extends \Test\TestCase {
}
public function testProcessAttributes() {
- list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$uid = 'alice';
$dn = 'uid=alice';
@@ -1075,15 +948,14 @@ class UserTest extends \Test\TestCase {
);
$userMock = $this->getMockBuilder('OCA\User_LDAP\User\User')
- ->setConstructorArgs(array($uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr))
+ ->setConstructorArgs(array($uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr))
->setMethods($requiredMethods)
->getMock();
- $connection->setConfiguration(array(
+ $this->connection->setConfiguration(array(
'homeFolderNamingRule' => 'homeDirectory'
));
-
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
//->will($this->returnArgument(0));
->will($this->returnCallback(function($name) {
@@ -1094,9 +966,9 @@ class UserTest extends \Test\TestCase {
}));
$record = array(
- strtolower($connection->ldapQuotaAttribute) => array('4096'),
- strtolower($connection->ldapEmailAttribute) => array('alice@wonderland.org'),
- strtolower($connection->ldapUserDisplayName) => array('Aaaaalice'),
+ strtolower($this->connection->ldapQuotaAttribute) => array('4096'),
+ strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'),
+ strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'),
'uid' => array($uid),
'homedirectory' => array('Alice\'s Folder'),
'memberof' => array('cn=groupOne', 'cn=groupTwo'),
@@ -1123,18 +995,15 @@ class UserTest extends \Test\TestCase {
* @dataProvider emptyHomeFolderAttributeValueProvider
*/
public function testGetHomePathNotConfigured($attributeValue) {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
->will($this->returnValue($attributeValue));
- $access->expects($this->never())
+ $this->access->expects($this->never())
->method('readAttribute');
$config->expects($this->never())
@@ -1144,25 +1013,22 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$path = $user->getHomePath();
$this->assertSame($path, false);
}
public function testGetHomePathConfiguredNotAvailableAllowed() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
->will($this->returnValue('attr:foobar'));
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->will($this->returnValue(false));
@@ -1175,7 +1041,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$path = $user->getHomePath();
@@ -1186,18 +1052,15 @@ class UserTest extends \Test\TestCase {
* @expectedException \Exception
*/
public function testGetHomePathConfiguredNotAvailableNotAllowed() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
-
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
->will($this->returnValue('attr:foobar'));
- $access->expects($this->once())
+ $this->access->expects($this->once())
->method('readAttribute')
->will($this->returnValue(false));
@@ -1210,7 +1073,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->getHomePath();
}
@@ -1227,14 +1090,14 @@ class UserTest extends \Test\TestCase {
* @dataProvider displayNameProvider
*/
public function testComposeAndStoreDisplayName($part1, $part2, $expected) {
- list($access, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
$config->expects($this->once())
->method('setUserValue');
$user = new User(
- 'user', 'cn=user', $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ 'user', 'cn=user', $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$displayName = $user->composeAndStoreDisplayName($part1, $part2);
$this->assertSame($expected, $displayName);
@@ -1244,13 +1107,10 @@ class UserTest extends \Test\TestCase {
list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$uid = 'alice';
$dn = 'uid=alice';
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
if($name === 'ldapDefaultPPolicyDN') {
@@ -1262,7 +1122,7 @@ class UserTest extends \Test\TestCase {
return $name;
}));
- $access->expects($this->any())
+ $this->access->expects($this->any())
->method('search')
->will($this->returnCallback(function($filter, $base) {
if($base === 'uid=alice') {
@@ -1306,24 +1166,21 @@ class UserTest extends \Test\TestCase {
->method('notify');
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
- \OC_Hook::clear();//disconnect irrelevant hooks
+ \OC_Hook::clear();//disconnect irrelevant hooks
\OCP\Util::connectHook('OC_User', 'post_login', $user, 'handlePasswordExpiry');
\OC_Hook::emit('OC_User', 'post_login', array('uid' => $uid));
}
public function testHandlePasswordExpiryWarningCustomPolicy() {
- list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
- list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
-
$uid = 'alice';
$dn = 'uid=alice';
- $connection->expects($this->any())
+ $this->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
if($name === 'ldapDefaultPPolicyDN') {
@@ -1335,7 +1192,7 @@ class UserTest extends \Test\TestCase {
return $name;
}));
- $access->expects($this->any())
+ $this->access->expects($this->any())
->method('search')
->will($this->returnCallback(function($filter, $base) {
if($base === 'uid=alice') {
@@ -1380,7 +1237,7 @@ class UserTest extends \Test\TestCase {
->method('notify');
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
\OC_Hook::clear();//disconnect irrelevant hooks
\OCP\Util::connectHook('OC_User', 'post_login', $user, 'handlePasswordExpiry');
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index fbe9953bbb9..0f48d5b3547 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -81,12 +81,6 @@ class User_LDAPTest extends TestCase {
* @return \PHPUnit_Framework_MockObject_MockObject|Access
*/
private function getAccessMock() {
- $lw = $this->createMock(ILDAPWrapper::class);
- $connector = $this->getMockBuilder(Connection::class)
- ->setMethodsExcept(['getConnection'])
- ->setConstructorArgs([$lw, null, null])
- ->getMock();
-
$this->configMock = $this->createMock(IConfig::class);
$this->offlineUser = $this->createMock(OfflineUser::class);
@@ -106,18 +100,16 @@ class User_LDAPTest extends TestCase {
])
->getMock();
- $um->expects($this->any())
- ->method('getDeletedUser')
- ->will($this->returnValue($this->offlineUser));
+ /** @var Connection|\PHPUnit_Framework_MockObject_MockObject $connection */
+ $connection = $this->createMock(Connection::class);
- $helper = new Helper(\OC::$server->getConfig());
-
- $access = $this->getMockBuilder(Access::class)
- ->setMethodsExcept(['getConnection'])
- ->setConstructorArgs([$connector, $lw, $um, $helper])
- ->getMock();
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject $userManager */
+ $userManager = $this->createMock(Manager::class);
- $um->setLdapAccess($access);
+ /** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */
+ $access = $this->createMock(Access::class);
+ $access->connection = $connection;
+ $access->userManager = $userManager;
return $access;
}
@@ -211,11 +203,17 @@ class User_LDAPTest extends TestCase {
}
public function testCheckPasswordUidReturn() {
- $access = $this->getAccessMock();
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('gunslinger');
+ $access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
+ ->willReturn($user);
+
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
@@ -246,11 +244,12 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordNoDisplayName() {
$access = $this->getAccessMock();
-
$this->prepareAccessForCheckPassword($access, true);
- $access->expects($this->once())
- ->method('username2dn')
- ->will($this->returnValue(false));
+
+ $this->prepareAccessForCheckPassword($access);
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn(null);
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
\OC_User::useBackend($backend);
@@ -260,9 +259,17 @@ class User_LDAPTest extends TestCase {
}
public function testCheckPasswordPublicAPI() {
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('gunslinger');
+
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
+ ->method('get')
+ ->willReturn($user);
+
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'dt19');
@@ -308,6 +315,9 @@ class User_LDAPTest extends TestCase {
$access->expects($this->once())
->method('getUserMapper')
->will($this->returnValue($mapping));
+ $access->connection->expects($this->any())
+ ->method('getConnectionResource')
+ ->willReturn('this is an ldap link');
$this->configMock->expects($this->any())
->method('getUserValue')
@@ -320,6 +330,9 @@ class User_LDAPTest extends TestCase {
$this->offlineUser->expects($this->once())
->method('getOCName')
->willReturn($uid);
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($this->offlineUser);
$backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
@@ -516,6 +529,11 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
$this->prepareMockForUserExists($access);
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfRoland,dc=test');
+
$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
@@ -524,6 +542,12 @@ class User_LDAPTest extends TestCase {
}
return false;
}));
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($user);
+ $access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($this->createMock(UserMapping::class));
//test for existing user
$result = $backend->userExists('gunslinger');
@@ -547,8 +571,13 @@ class User_LDAPTest extends TestCase {
return false;
}));
+ $access->userManager = $this->createMock(Manager::class);
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($this->createMock(User::class));
+
//test for deleted user
- $result = $backend->userExists('formerUser');
+ $backend->userExists('formerUser');
}
public function testUserExistsForNeverExisting() {
@@ -576,6 +605,11 @@ class User_LDAPTest extends TestCase {
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfRoland,dc=test');
+
$access->expects($this->any())
->method('readAttribute')
->will($this->returnCallback(function($dn) {
@@ -584,6 +618,12 @@ class User_LDAPTest extends TestCase {
}
return false;
}));
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($user);
+ $access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($this->createMock(UserMapping::class));
//test for existing user
$result = \OCP\User::userExists('gunslinger');
@@ -607,9 +647,13 @@ class User_LDAPTest extends TestCase {
}
return false;
}));
+ $access->userManager = $this->createMock(Manager::class);
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($this->createMock(User::class));
//test for deleted user
- $result = \OCP\User::userExists('formerUser');
+ \OCP\User::userExists('formerUser');
}
public function testUserExistsPublicAPIForNeverExisting() {
@@ -672,7 +716,22 @@ class User_LDAPTest extends TestCase {
}
}));
- //absolut path
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('gunslinger');
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfRoland,dc=test');
+ $user->expects($this->any())
+ ->method('getHomePath')
+ ->willReturn('/tmp/rolandshome/');
+
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($user);
+
+ //absolute path
$result = $backend->getHome('gunslinger');
$this->assertEquals('/tmp/rolandshome/', $result);
}
@@ -687,10 +746,6 @@ class User_LDAPTest extends TestCase {
$dataDir = \OC::$server->getConfig()->getSystemValue(
'datadirectory', \OC::$SERVERROOT.'/data');
- $this->configMock->expects($this->once())
- ->method('getSystemValue')
- ->will($this->returnValue($dataDir));
-
$access->connection->expects($this->any())
->method('__get')
->will($this->returnCallback(function($name) {
@@ -715,6 +770,21 @@ class User_LDAPTest extends TestCase {
}
}));
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('ladyofshadows');
+ $user->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfLadyOfShadows,dc=test');
+ $user->expects($this->any())
+ ->method('getHomePath')
+ ->willReturn($dataDir.'/susannah/');
+
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($user);
+
$result = $backend->getHome('ladyofshadows');
$this->assertEquals($dataDir.'/susannah/', $result);
}
@@ -745,6 +815,18 @@ class User_LDAPTest extends TestCase {
}
}));
+ $user = $this->createMock(User::class);
+ $user->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('newyorker');
+ $user->expects($this->any())
+ ->method('getHomePath')
+ ->willThrowException(new \Exception());
+
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($user);
+
//no path at all – triggers OC default behaviour
$result = $backend->getHome('newyorker');
$this->assertFalse($result);
@@ -786,6 +868,10 @@ class User_LDAPTest extends TestCase {
$this->offlineUser->expects($this->never())
->method('getHomePath');
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($this->offlineUser);
+
$backend->getHome($uid);
}
@@ -852,14 +938,6 @@ class User_LDAPTest extends TestCase {
}
}));
- $userMapper = $this->getMockBuilder('\OCA\User_LDAP\Mapping\UserMapping')
- ->disableOriginalConstructor()
- ->getMock();
-
- $access->expects($this->any())
- ->method('getUserMapper')
- ->will($this->returnValue($userMapper));
-
$access->method('fetchUsersByLoginName')
->willReturn([]);
}
@@ -876,6 +954,42 @@ class User_LDAPTest extends TestCase {
return true;
}));
+ $user1 = $this->createMock(User::class);
+ $user1->expects($this->once())
+ ->method('composeAndStoreDisplayName')
+ ->willReturn('Roland Deschain');
+ $user1->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfRoland,dc=test');
+
+ $user2 = $this->createMock(User::class);
+ $user2->expects($this->never())
+ ->method('composeAndStoreDisplayName');
+ $user2->expects($this->any())
+ ->method('getDN')
+ ->willReturn('another DN');
+
+ $mapper = $this->createMock(UserMapping::class);
+ $mapper->expects($this->any())
+ ->method('getUUIDByDN')
+ ->willReturnCallback(function($dn) { return $dn; });
+
+ $access->userManager->expects($this->any())
+ ->method('get')
+ ->willReturnCallback(function($uid) use ($user1, $user2) {
+ if($uid === 'gunslinger') {
+ return $user1;
+ } else if($uid === 'newyorker') {
+ return $user2;
+ }
+ });
+ $access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($mapper);
+ $access->expects($this->any())
+ ->method('getUserDnByUuid')
+ ->willReturnCallback(function($uuid) { return $uuid . '1'; });
+
//with displayName
$result = $backend->getDisplayName('gunslinger');
$this->assertEquals('Roland Deschain', $result);
@@ -919,6 +1033,42 @@ class User_LDAPTest extends TestCase {
\OC_User::useBackend($backend);
+ $user1 = $this->createMock(User::class);
+ $user1->expects($this->once())
+ ->method('composeAndStoreDisplayName')
+ ->willReturn('Roland Deschain');
+ $user1->expects($this->any())
+ ->method('getDN')
+ ->willReturn('dnOfRoland,dc=test');
+
+ $user2 = $this->createMock(User::class);
+ $user2->expects($this->never())
+ ->method('composeAndStoreDisplayName');
+ $user2->expects($this->any())
+ ->method('getDN')
+ ->willReturn('another DN');
+
+ $mapper = $this->createMock(UserMapping::class);
+ $mapper->expects($this->any())
+ ->method('getUUIDByDN')
+ ->willReturnCallback(function($dn) { return $dn; });
+
+ $access->userManager->expects($this->any())
+ ->method('get')
+ ->willReturnCallback(function($uid) use ($user1, $user2) {
+ if($uid === 'gunslinger') {
+ return $user1;
+ } else if($uid === 'newyorker') {
+ return $user2;
+ }
+ });
+ $access->expects($this->any())
+ ->method('getUserMapper')
+ ->willReturn($mapper);
+ $access->expects($this->any())
+ ->method('getUserDnByUuid')
+ ->willReturnCallback(function($uuid) { return $uuid . '1'; });
+
//with displayName
$result = \OCP\User::getDisplayName('gunslinger');
$this->assertEquals('Roland Deschain', $result);
@@ -1028,11 +1178,11 @@ class User_LDAPTest extends TestCase {
->method('fetchUsersByLoginName')
->with($this->equalTo($loginName))
->willReturn([['dn' => [$dn]]]);
- $access->expects($this->once())
+ $access->expects($this->any())
->method('stringResemblesDN')
->with($this->equalTo($dn))
->willReturn(true);
- $access->expects($this->once())
+ $access->expects($this->any())
->method('dn2username')
->with($this->equalTo($dn))
->willReturn($username);
@@ -1046,6 +1196,15 @@ 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->expects($this->any())
+ ->method('getUsername')
+ ->willReturn('alice');
+
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->with($dn)
+ ->willReturn($user);
+
$name = $backend->loginName2UserName($loginName);
$this->assertSame($username, $name);
@@ -1084,7 +1243,6 @@ class User_LDAPTest extends TestCase {
public function testLoginName2UserNameOfflineUser() {
$loginName = 'Alice';
- $username = 'alice';
$dn = 'uid=alice,dc=what,dc=ever';
$offlineUser = $this->getMockBuilder(OfflineUser::class)
@@ -1096,13 +1254,6 @@ class User_LDAPTest extends TestCase {
->method('fetchUsersByLoginName')
->with($this->equalTo($loginName))
->willReturn([['dn' => [$dn]]]);
- $access->expects($this->once())
- ->method('stringResemblesDN')
- ->with($this->equalTo($dn))
- ->willReturn(true);
- $access->expects($this->once())
- ->method('dn2username')
- ->willReturn(false); // this is fake, but allows us to force-enter the OfflineUser path
$access->connection->expects($this->exactly(2))
->method('getFromCache')
@@ -1112,14 +1263,10 @@ class User_LDAPTest extends TestCase {
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo(false));
- $access->userManager->expects($this->once())
- ->method('getDeletedUser')
- ->will($this->returnValue($offlineUser));
-
- //$config = $this->createMock(IConfig::class);
- $this->configMock->expects($this->once())
- ->method('getUserValue')
- ->willReturn(1);
+ $access->userManager->expects($this->any())
+ ->method('get')
+ ->with($dn)
+ ->willReturn($offlineUser);
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
$name = $backend->loginName2UserName($loginName);
@@ -1192,6 +1339,10 @@ class User_LDAPTest extends TestCase {
}
return true;
}));
+
+ $access->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->willReturn($this->createMock(User::class));
}
/**
@@ -1213,6 +1364,10 @@ class User_LDAPTest extends TestCase {
$this->prepareAccessForSetPassword($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($this->createMock(User::class));
+
\OC_User::useBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt12234$'));
@@ -1220,6 +1375,9 @@ class User_LDAPTest extends TestCase {
public function testSetPasswordValidDisabled() {
$access = $this->getAccessMock();
+ $access->userManager->expects($this->any())
+ ->method('get')
+ ->willReturn($this->createMock(User::class));
$this->prepareAccessForSetPassword($access, false);
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
diff --git a/apps/user_ldap/tests/WizardTest.php b/apps/user_ldap/tests/WizardTest.php
index e7717aad37c..f11f7bec206 100644
--- a/apps/user_ldap/tests/WizardTest.php
+++ b/apps/user_ldap/tests/WizardTest.php
@@ -28,8 +28,11 @@
namespace OCA\User_LDAP\Tests;
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ILDAPWrapper;
use \OCA\User_LDAP\Wizard;
+use Test\TestCase;
/**
* Class Test_Wizard
@@ -38,7 +41,7 @@ use \OCA\User_LDAP\Wizard;
*
* @package OCA\User_LDAP\Tests
*/
-class WizardTest extends \Test\TestCase {
+class WizardTest extends TestCase {
protected function setUp() {
parent::setUp();
//we need to make sure the consts are defined, otherwise tests will fail
@@ -62,30 +65,22 @@ class WizardTest extends \Test\TestCase {
$connMethods = get_class_methods('\OCA\User_LDAP\Connection');
$accMethods = get_class_methods('\OCA\User_LDAP\Access');
}
+ /** @var ILDAPWrapper|\PHPUnit_Framework_MockObject_MockObject $lw */
$lw = $this->createMock(ILDAPWrapper::class);
- $conf = $this->getMockBuilder('\OCA\User_LDAP\Configuration')
+
+ /** @var Configuration|\PHPUnit_Framework_MockObject_MockObject $conf */
+ $conf = $this->getMockBuilder(Configuration::class)
->setMethods($confMethods)
->setConstructorArgs([$lw, null, null])
->getMock();
- $connector = $this->getMockBuilder('\OCA\User_LDAP\Connection')
- ->setMethods($connMethods)
- ->setConstructorArgs([$lw, null, null])
- ->getMock();
-
- $um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
- ->disableOriginalConstructor()
- ->getMock();
- $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
- $access = $this->getMockBuilder('\OCA\User_LDAP\Access')
- ->setMethods($accMethods)
- ->setConstructorArgs([$connector, $lw, $um, $helper])
- ->getMock();
+ /** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */
+ $access = $this->createMock(Access::class);
return array(new Wizard($conf, $lw, $access), $conf, $lw, $access);
}
- private function prepareLdapWrapperForConnections(&$ldap) {
+ private function prepareLdapWrapperForConnections(\PHPUnit_Framework_MockObject_MockObject &$ldap) {
$ldap->expects($this->once())
->method('connect')
//dummy value, usually invalid