Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] also try syncing quote from preferences if backend provided no quota #31360

Merged
merged 1 commit into from May 4, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -220,7 +220,8 @@ private function syncQuota(Account $a, UserInterface $backend) {
if ($quota !== null) {
$a->setQuota($quota);
}
} else {
}
if ($quota === null) {
list($hasKey, $quota) = $this->readUserConfig($uid, 'files', 'quota');
if ($hasKey) {
$a->setQuota($quota);
@@ -33,6 +33,7 @@
use OCP\IConfig;
use OCP\ILogger;
use OCP\User\IProvidesHomeBackend;
use OCP\User\IProvidesQuotaBackend;
use OCP\UserInterface;
use Test\TestCase;
@@ -226,4 +227,53 @@ public function testRemovedAccountsAreDetected() {
$this->assertEquals(0, count($response[1]));
}
}
public function providesSyncQuota() {
return [
[true, null, null, null],
[true, '1', null, '1'],
[true, null, '2', '2'],
[false, null, null, null],
[false, null, '3', '3'],
];
}
/**
* @dataProvider providesSyncQuota
* @param $backendProvidesQuota
* @param $backendQuota
* @param $preferencesQuota
* @param $expectedQuota
*/
public function testSyncQuota($backendProvidesQuota, $backendQuota, $preferencesQuota, $expectedQuota) {
/** @var UserInterface | \PHPUnit_Framework_MockObject_MockObject $backend */
$a = $this->getMockBuilder(Account::class)->setMethods(['setQuota'])->getMock();
if ($backendProvidesQuota) {
/** @var UserInterface | IProvidesQuotaBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
$backend = $this->createMock([UserInterface::class, IProvidesQuotaBackend::class]);
$backend->expects($this->exactly(1))->method('getQuota')->willReturn($backendQuota);
} else {
$backend = $this->createMock(UserInterface::class);
}
// legacy preferences has a quota value
if ($preferencesQuota) {
$this->config->method('getUserKeys')->willReturn(['quota']);
$this->config->method('getUserValue')->willReturn($preferencesQuota);
} else {
$this->config->method('getUserKeys')->willReturn([]);
}
// Account gets the existing quota
if ($expectedQuota) {
$a->expects($this->exactly(1))->method('setQuota')->with($expectedQuota);
} else {
$a->expects($this->never())->method('setQuota');
}
$s = new SyncService($this->config, $this->logger, $this->mapper);
static::invokePrivate($s, 'syncQuota', [$a, $backend]);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.