summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-10-08 11:41:16 +0200
committerMorris Jobke <hey@morrisjobke.de>2020-12-02 15:20:03 +0100
commitd87705a8941511a4e3bf8f6c97d6e0f36a42799e (patch)
tree5c6d2ba0aed6a6c9b3bc0563ca800de65680bfea /tests
parente25a62c69dc83ba5655577181f4ea41a47c742b5 (diff)
downloadnextcloud-server-d87705a8941511a4e3bf8f6c97d6e0f36a42799e.tar.gz
nextcloud-server-d87705a8941511a4e3bf8f6c97d6e0f36a42799e.zip
Allow subscription to indicate that a userlimit is reached
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Support/Subscription/DummySubscription.php9
-rw-r--r--tests/lib/Support/Subscription/RegistryTest.php83
2 files changed, 89 insertions, 3 deletions
diff --git a/tests/lib/Support/Subscription/DummySubscription.php b/tests/lib/Support/Subscription/DummySubscription.php
index e1f7f5c6b61..f4e7e3484bb 100644
--- a/tests/lib/Support/Subscription/DummySubscription.php
+++ b/tests/lib/Support/Subscription/DummySubscription.php
@@ -30,6 +30,8 @@ class DummySubscription implements \OCP\Support\Subscription\ISubscription {
private $hasValidSubscription;
/** @var bool */
private $hasExtendedSupport;
+ /** @var bool */
+ private $isHardUserLimitReached;
/**
* DummySubscription constructor.
@@ -37,9 +39,10 @@ class DummySubscription implements \OCP\Support\Subscription\ISubscription {
* @param bool $hasValidSubscription
* @param bool $hasExtendedSupport
*/
- public function __construct(bool $hasValidSubscription, bool $hasExtendedSupport) {
+ public function __construct(bool $hasValidSubscription, bool $hasExtendedSupport, bool $isHardUserLimitReached) {
$this->hasValidSubscription = $hasValidSubscription;
$this->hasExtendedSupport = $hasExtendedSupport;
+ $this->isHardUserLimitReached = $isHardUserLimitReached;
}
/**
@@ -55,4 +58,8 @@ class DummySubscription implements \OCP\Support\Subscription\ISubscription {
public function hasExtendedSupport(): bool {
return $this->hasExtendedSupport;
}
+
+ public function isHardUserLimitReached(): bool {
+ return $this->isHardUserLimitReached;
+ }
}
diff --git a/tests/lib/Support/Subscription/RegistryTest.php b/tests/lib/Support/Subscription/RegistryTest.php
index c070f69ae66..58995afcab8 100644
--- a/tests/lib/Support/Subscription/RegistryTest.php
+++ b/tests/lib/Support/Subscription/RegistryTest.php
@@ -25,9 +25,11 @@ namespace Test\Support\Subscription;
use OC\Support\Subscription\Registry;
use OCP\IConfig;
use OCP\IServerContainer;
+use OCP\IUserManager;
use OCP\Support\Subscription\ISubscription;
use OCP\Support\Subscription\ISupportedApps;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class RegistryTest extends TestCase {
@@ -41,12 +43,25 @@ class RegistryTest extends TestCase {
/** @var MockObject|IServerContainer */
private $serverContainer;
+ /** @var MockObject|IUserManager */
+ private $userManager;
+
+ /** @var MockObject|LoggerInterface */
+ private $logger;
+
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->serverContainer = $this->createMock(IServerContainer::class);
- $this->registry = new Registry($this->config, $this->serverContainer);
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->registry = new Registry(
+ $this->config,
+ $this->serverContainer,
+ $this->userManager,
+ $this->logger
+ );
}
/**
@@ -121,10 +136,74 @@ class RegistryTest extends TestCase {
public function testSubscriptionService() {
$this->serverContainer->method('query')
->with(DummySubscription::class)
- ->willReturn(new DummySubscription(true, false));
+ ->willReturn(new DummySubscription(true, false, false));
$this->registry->registerService(DummySubscription::class);
$this->assertTrue($this->registry->delegateHasValidSubscription());
$this->assertFalse($this->registry->delegateHasExtendedSupport());
}
+
+ public function testDelegateIsHardUserLimitReached() {
+ /* @var ISubscription|\PHPUnit\Framework\MockObject\MockObject $subscription */
+ $subscription = $this->createMock(ISubscription::class);
+ $subscription->expects($this->once())
+ ->method('hasValidSubscription')
+ ->willReturn(true);
+ $subscription->expects($this->once())
+ ->method('isHardUserLimitReached')
+ ->willReturn(true);
+ $this->registry->register($subscription);
+
+ $this->assertSame(true, $this->registry->delegateIsHardUserLimitReached());
+ }
+
+ public function testDelegateIsHardUserLimitReachedWithoutSupportApp() {
+ $this->config->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('one-click-instance')
+ ->willReturn(false);
+
+ $this->assertSame(false, $this->registry->delegateIsHardUserLimitReached());
+ }
+
+ public function dataForUserLimitCheck() {
+ return [
+ // $userLimit, $userCount, $disabledUsers, $expectedResult
+ [35, 15, 2, false],
+ [35, 45, 15, false],
+ [35, 45, 5, true],
+ [35, 45, 55, false],
+ ];
+ }
+
+ /**
+ * @dataProvider dataForUserLimitCheck
+ */
+ public function testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount($userLimit, $userCount, $disabledUsers, $expectedResult) {
+ $this->config->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('one-click-instance')
+ ->willReturn(true);
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('one-click-instance.user-limit')
+ ->willReturn($userLimit);
+ $this->config->expects($this->once())
+ ->method('getUsersForUserValue')
+ ->with('core', 'enabled', 'false')
+ ->willReturn(array_fill(0, $disabledUsers, ''));
+ /* @var UserInterface|\PHPUnit\Framework\MockObject\MockObject $dummyBackend */
+ $dummyBackend = $this->createMock(UserInterface::class);
+ $dummyBackend->expects($this->once())
+ ->method('implementsActions')
+ ->willReturn(true);
+ $dummyBackend->expects($this->once())
+ ->method('countUsers')
+ ->willReturn($userCount);
+ $this->userManager->expects($this->once())
+ ->method('getBackends')
+ ->willReturn([$dummyBackend]);
+
+ $this->assertSame($expectedResult, $this->registry->delegateIsHardUserLimitReached());
+ }
}