Add new testes to cover more cases

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Juan Pablo Villafáñez 2017-03-16 12:22:02 +01:00 committed by Arthur Schiwon
parent e9b96062e6
commit ebd1a7d4b2
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 210 additions and 0 deletions

View File

@ -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) =