aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User/UserTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/User/UserTest.php')
-rw-r--r--apps/user_ldap/tests/User/UserTest.php481
1 files changed, 169 insertions, 312 deletions
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');