summaryrefslogtreecommitdiffstats
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.php338
1 files changed, 313 insertions, 25 deletions
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index c261a2abaa2..6961e39d9f0 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -211,15 +211,17 @@ class UserTest extends \Test\TestCase {
$connection->expects($this->at(0))
->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue('23 GB'));
+ ->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('ldapQuotaAttribute'))
- ->will($this->returnValue('myquota'));
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('23 GB'));
+ */
- $connection->expects($this->exactly(2))
+ $connection->expects($this->exactly(1))
->method('__get');
$access->expects($this->once())
@@ -247,7 +249,7 @@ class UserTest extends \Test\TestCase {
$user->updateQuota();
}
- public function testUpdateQuotaDefaultProvided() {
+ public function testUpdateQuotaToDefaultAllProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
$this->getTestInstances();
@@ -256,14 +258,94 @@ class UserTest extends \Test\TestCase {
$connection->expects($this->at(0))
->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue('25 GB'));
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
- $connection->expects($this->at(1))
+ $connection->expects($this->exactly(1))
+ ->method('__get');
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
+ $this->equalTo('myquota'))
+ ->will($this->returnValue(array('default')));
+
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('default');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota();
+ }
+
+ public function testUpdateQuotaToNoneAllProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->at(0))
->method('__get')
->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue('myquota'));
+ $connection->expects($this->exactly(1))
+ ->method('__get');
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
+ $this->equalTo('myquota'))
+ ->will($this->returnValue(array('none')));
+
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('none');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota();
+ }
+
+ public function testUpdateQuotaDefaultProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->at(0))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
+
+ $connection->expects($this->at(1))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('25 GB'));
+
$connection->expects($this->exactly(2))
->method('__get');
@@ -301,15 +383,17 @@ class UserTest extends \Test\TestCase {
$connection->expects($this->at(0))
->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue(''));
+ ->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('ldapQuotaAttribute'))
- ->will($this->returnValue('myquota'));
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue(''));
+ */
- $connection->expects($this->exactly(2))
+ $connection->expects($this->exactly(1))
->method('__get');
$access->expects($this->once())
@@ -346,13 +430,13 @@ class UserTest extends \Test\TestCase {
$connection->expects($this->at(0))
->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue(''));
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
$connection->expects($this->at(1))
->method('__get')
- ->with($this->equalTo('ldapQuotaAttribute'))
- ->will($this->returnValue('myquota'));
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue(''));
$connection->expects($this->exactly(2))
->method('__get');
@@ -363,6 +447,16 @@ class UserTest extends \Test\TestCase {
$this->equalTo('myquota'))
->will($this->returnValue(false));
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('default');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
$config->expects($this->never())
->method('setUserValue');
@@ -384,17 +478,28 @@ class UserTest extends \Test\TestCase {
$connection->expects($this->at(0))
->method('__get')
- ->with($this->equalTo('ldapQuotaDefault'))
+ ->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue(''));
$connection->expects($this->at(1))
->method('__get')
- ->with($this->equalTo('ldapQuotaAttribute'))
+ ->with($this->equalTo('ldapQuotaDefault'))
->will($this->returnValue(''));
$connection->expects($this->exactly(2))
->method('__get');
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('default');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+
$access->expects($this->never())
->method('readAttribute');
@@ -419,23 +524,206 @@ class UserTest extends \Test\TestCase {
$readQuota = '19 GB';
+ $connection->expects($this->never())
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaDefault'));
+
+ $access->expects($this->never())
+ ->method('readAttribute');
+
+ $user = $this->createMock(IUser::class);
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with($readQuota);
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota($readQuota);
+ }
+
+ /**
+ * Unparseable quota will fallback to use the LDAP default
+ */
+ public function testUpdateWrongQuotaAllProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->at(0))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
+
+ $connection->expects($this->at(1))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('23 GB'));
+
+ $connection->expects($this->exactly(2))
+ ->method('__get');
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
+ $this->equalTo('myquota'))
+ ->will($this->returnValue(array('42 GBwos')));
+
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('23 GB');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota();
+ }
+
+ /**
+ * No user quota and wrong default will set 'default' as quota
+ */
+ public function testUpdateWrongDefaultQuotaProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->at(0))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
+
+ $connection->expects($this->at(1))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('23 GBwowowo'));
+
+ $connection->expects($this->exactly(2))
+ ->method('__get');
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
+ $this->equalTo('myquota'))
+ ->will($this->returnValue(false));
+
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('default');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota();
+ }
+
+ /**
+ * Wrong user quota and wrong default will set 'default' as quota
+ */
+ public function testUpdateWrongQuotaAndDefaultAllProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
$connection->expects($this->at(0))
->method('__get')
+ ->with($this->equalTo('ldapQuotaAttribute'))
+ ->will($this->returnValue('myquota'));
+
+ $connection->expects($this->at(1))
+ ->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('23 GBwowowo'));
+
+ $connection->expects($this->exactly(2))
+ ->method('__get');
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
+ $this->equalTo('myquota'))
+ ->will($this->returnValue(array('23 flush')));
+
+ $user = $this->createMock('\OCP\IUser');
+ $user->expects($this->once())
+ ->method('setQuota')
+ ->with('default');
+
+ $userMgr->expects($this->once())
+ ->method('get')
+ ->with('alice')
+ ->will($this->returnValue($user));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+
+ $user->updateQuota();
+ }
+
+ /**
+ * No quota attribute set and wrong default will set 'default' as quota
+ */
+ public function testUpdateWrongDefaultQuotaNotProvided() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->at(0))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaAttribute'))
->will($this->returnValue(''));
- $connection->expects($this->once(1))
+ $connection->expects($this->at(1))
->method('__get')
->with($this->equalTo('ldapQuotaDefault'))
- ->will($this->returnValue(null));
+ ->will($this->returnValue('23 GBwowowo'));
+
+ $connection->expects($this->exactly(2))
+ ->method('__get');
$access->expects($this->never())
->method('readAttribute');
- $user = $this->createMock(IUser::class);
+ $user = $this->createMock('\OCP\IUser');
$user->expects($this->once())
->method('setQuota')
- ->with($readQuota);
+ ->with('default');
$userMgr->expects($this->once())
->method('get')
@@ -448,7 +736,7 @@ class UserTest extends \Test\TestCase {
$user = new User(
$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
- $user->updateQuota($readQuota);
+ $user->updateQuota();
}
//the testUpdateAvatar series also implicitely tests getAvatarImage