2017-05-24 03:07:58 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2017-05-24 03:07:58 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-05-24 03:07:58 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\GlobalScale;
|
|
|
|
|
|
|
|
|
|
use OC\GlobalScale\Config;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class ConfigTest extends TestCase {
|
2024-08-23 09:10:27 -04:00
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
2017-05-24 03:07:58 -04:00
|
|
|
private $config;
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2017-05-24 03:07:58 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $mockMethods
|
2020-08-11 15:32:18 -04:00
|
|
|
* @return Config|\PHPUnit\Framework\MockObject\MockObject
|
2017-05-24 03:07:58 -04:00
|
|
|
*/
|
|
|
|
|
public function getInstance($mockMethods = []) {
|
|
|
|
|
if (!empty($mockMethods)) {
|
|
|
|
|
return $this->getMockBuilder(Config::class)
|
|
|
|
|
->setConstructorArgs([$this->config])
|
2025-05-12 11:39:58 -04:00
|
|
|
->onlyMethods($mockMethods)
|
2017-05-24 03:07:58 -04:00
|
|
|
->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Config($this->config);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testIsGlobalScaleEnabled(): void {
|
2017-05-24 03:07:58 -04:00
|
|
|
$gsConfig = $this->getInstance();
|
2023-04-05 11:42:14 -04:00
|
|
|
$this->config->expects($this->once())->method('getSystemValueBool')
|
2017-05-24 03:07:58 -04:00
|
|
|
->with('gs.enabled', false)->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$result = $gsConfig->isGlobalScaleEnabled();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param bool $gsEnabled
|
|
|
|
|
* @param string $gsFederation
|
|
|
|
|
* @param bool $expected
|
|
|
|
|
*/
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('dataTestOnlyInternalFederation')]
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testOnlyInternalFederation($gsEnabled, $gsFederation, $expected): void {
|
2017-05-24 03:07:58 -04:00
|
|
|
$gsConfig = $this->getInstance(['isGlobalScaleEnabled']);
|
|
|
|
|
|
|
|
|
|
$gsConfig->expects($this->any())->method('isGlobalScaleEnabled')->willReturn($gsEnabled);
|
|
|
|
|
|
2023-04-05 11:42:14 -04:00
|
|
|
$this->config->expects($this->any())->method('getSystemValueString')
|
2017-05-24 03:07:58 -04:00
|
|
|
->with('gs.federation', 'internal')->willReturn($gsFederation);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($expected, $gsConfig->onlyInternalFederation());
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 11:39:58 -04:00
|
|
|
public static function dataTestOnlyInternalFederation(): array {
|
2017-05-24 03:07:58 -04:00
|
|
|
return [
|
|
|
|
|
[true, 'global', false],
|
|
|
|
|
[true, 'internal', true],
|
|
|
|
|
[false, 'global', false],
|
|
|
|
|
[false, 'internal', false]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|