Add system config flag to manually set that a subscription is available

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/19812/head
Julius Härtl 5 years ago
parent f65e36a70c
commit dbd63222c8
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
  1. 4
      apps/settings/tests/Controller/AdminSettingsControllerTest.php
  2. 13
      lib/private/Support/Subscription/Registry.php
  3. 18
      tests/lib/Support/Subscription/RegistryTest.php

@ -37,6 +37,7 @@ use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Settings\IManager;
use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@ -99,6 +100,7 @@ class AdminSettingsControllerTest extends TestCase {
public function testIndex() {
$user = $this->createMock(IUser::class);
$registry = $this->createMock(IRegistry::class);
$this->userSession
->method('getUser')
->willReturn($user);
@ -123,7 +125,7 @@ class AdminSettingsControllerTest extends TestCase {
->expects($this->once())
->method('getAdminSettings')
->with('test')
->willReturn([5 => new ServerDevNotice()]);
->willReturn([5 => new ServerDevNotice($registry)]);
$idx = $this->adminSettingsController->index('test');

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OC\Support\Subscription;
use OCP\IConfig;
use OCP\Support\Subscription\Exception\AlreadyRegisteredException;
use OCP\Support\Subscription\IRegistry;
use OCP\Support\Subscription\ISubscription;
@ -37,6 +38,13 @@ class Registry implements IRegistry {
/** @var ISubscription */
private $subscription = null;
/** @var IConfig */
private $config;
public function __construct(IConfig $config) {
$this->config = $config;
}
/**
* Register a subscription instance. In case it is called multiple times the
* first one is used.
@ -71,6 +79,11 @@ class Registry implements IRegistry {
* @since 17.0.0
*/
public function delegateHasValidSubscription(): bool {
// Allow overwriting this manually for environments where the subscription information cannot be fetched
if ($this->config->getSystemValueBool('has_valid_subscription')) {
return true;
}
if ($this->subscription instanceof ISubscription) {
return $this->subscription->hasValidSubscription();
}

@ -23,8 +23,10 @@
namespace Test\Support\Subscription;
use OC\Support\Subscription\Registry;
use OCP\IConfig;
use OCP\Support\Subscription\ISubscription;
use OCP\Support\Subscription\ISupportedApps;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class RegistryTest extends TestCase {
@ -32,10 +34,14 @@ class RegistryTest extends TestCase {
/** @var Registry */
private $registry;
/** @var MockObject|IConfig */
private $config;
protected function setUp(): void {
parent::setUp();
$this->registry = new Registry();
$this->config = $this->createMock(IConfig::class);
$this->registry = new Registry($this->config);
}
/**
@ -74,6 +80,16 @@ class RegistryTest extends TestCase {
$this->assertSame(true, $this->registry->delegateHasValidSubscription());
}
public function testDelegateHasValidSubscriptionConfig() {
/* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_valid_subscription')
->willReturn(true);
$this->assertSame(true, $this->registry->delegateHasValidSubscription());
}
public function testDelegateHasExtendedSupport() {
/* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
$subscription = $this->createMock(ISubscription::class);

Loading…
Cancel
Save