From ebd1a7d4b2fca32edb9fd17ebfeaaa646cbbe495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 16 Mar 2017 12:22:02 +0100 Subject: [PATCH] Add new testes to cover more cases Signed-off-by: Arthur Schiwon --- apps/user_ldap/tests/User/UserTest.php | 210 +++++++++++++++++++++++++ 1 file changed, 210 insertions(+) diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index 7a0e40b856..b918285963 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) =