summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests
diff options
context:
space:
mode:
authorJuan Pablo Villafáñez <jvillafanez@solidgear.es>2017-03-16 12:22:02 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-03-29 13:32:16 +0200
commitebd1a7d4b2fca32edb9fd17ebfeaaa646cbbe495 (patch)
tree4dd8f5121918f97232a927584bc1b2b3ae250301 /apps/user_ldap/tests
parente9b96062e68d1e09055f4f2e7dac18161c062609 (diff)
downloadnextcloud-server-ebd1a7d4b2fca32edb9fd17ebfeaaa646cbbe495.tar.gz
nextcloud-server-ebd1a7d4b2fca32edb9fd17ebfeaaa646cbbe495.zip
Add new testes to cover more cases
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/User/UserTest.php210
1 files changed, 210 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index 7a0e40b8563..b9182859631 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -367,6 +367,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');
@@ -399,6 +409,17 @@ class UserTest extends \Test\TestCase {
$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');
@@ -449,6 +470,195 @@ class UserTest extends \Test\TestCase {
$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->at(1))
+ ->method('__get')
+ ->with($this->equalTo('ldapQuotaDefault'))
+ ->will($this->returnValue('23 GBwowowo'));
+
+ $connection->expects($this->exactly(2))
+ ->method('__get');
+
+ $access->expects($this->never())
+ ->method('readAttribute');
+
+ $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();
+ }
+
//the testUpdateAvatar series also implicitely tests getAvatarImage
public function testUpdateAvatarJpegPhotoProvided() {
list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =