|
|
|
@ -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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|