Skip to content

Commit

Permalink
implement tests for unlimited quota restrictions
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Jul 19, 2021
1 parent d2cf158 commit d4e6a65
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions tests/lib/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,111 @@ public function testSetQuota() {
$user->setQuota('23 TB');
}

public function testGetDefaultUnlimitedQuota() {
/**
* @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend
*/
$backend = $this->createMock(\Test\Util\User\Dummy::class);

/** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */
$emitter = $this->createMock(PublicEmitter::class);
$emitter->expects($this->never())
->method('emit');

$config = $this->createMock(IConfig::class);
$user = new User('foo', $backend, $this->dispatcher, $emitter, $config);
$config->expects($this->at(0))
->method('getUserValue')
->with(
'foo',
'files',
'quota',
'default'
)
->willReturn('default');
$config->expects($this->at(1))
->method('getAppValue')
->with(
'files',
'default_quota',
'none'
)
->willReturn('none');
// allow unlimited quota
$config->expects($this->at(2))
->method('getAppValue')
->with(
'files',
'allow_unlimited_quota',
'1'
)
->willReturn('1');

$quota = $user->getQuota();
$this->assertEquals('none', $quota);
}

public function testGetDefaultUnlimitedQuotaForbidden() {
/**
* @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend
*/
$backend = $this->createMock(\Test\Util\User\Dummy::class);

/** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */
$emitter = $this->createMock(PublicEmitter::class);
$emitter->expects($this->never())
->method('emit');

$config = $this->createMock(IConfig::class);
$user = new User('foo', $backend, $this->dispatcher, $emitter, $config);
$config->expects($this->at(0))
->method('getUserValue')
->with(
'foo',
'files',
'quota',
'default'
)
->willReturn('default');
$config->expects($this->at(1))
->method('getAppValue')
->with(
'files',
'default_quota',
'none'
)
->willReturn('none');
// do not allow unlimited quota
$config->expects($this->at(2))
->method('getAppValue')
->with(
'files',
'allow_unlimited_quota',
'1'
)
->willReturn('0');
$config->expects($this->at(3))
->method('getAppValue')
->with(
'files',
'quota_preset',
'1 GB, 5 GB, 10 GB'
)
->willReturn('1 GB, 5 GB, 10 GB');
// expect seeing 1 GB used as fallback value
$config->expects($this->at(4))
->method('getAppValue')
->with(
'files',
'default_quota',
'1 GB'
)
->willReturn('1 GB');

$quota = $user->getQuota();
$this->assertEquals('1 GB', $quota);
}

public function testSetQuotaAddressNoChange() {
/**
* @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend
Expand Down

0 comments on commit d4e6a65

Please sign in to comment.