ConfigTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\GlobalScale;
  7. use OC\GlobalScale\Config;
  8. use OCP\IConfig;
  9. use Test\TestCase;
  10. class ConfigTest extends TestCase {
  11. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  12. private $config;
  13. protected function setUp(): void {
  14. parent::setUp();
  15. $this->config = $this->createMock(IConfig::class);
  16. }
  17. /**
  18. * @param array $mockMethods
  19. * @return Config|\PHPUnit\Framework\MockObject\MockObject
  20. */
  21. public function getInstance($mockMethods = []) {
  22. if (!empty($mockMethods)) {
  23. return $this->getMockBuilder(Config::class)
  24. ->setConstructorArgs([$this->config])
  25. ->setMethods($mockMethods)
  26. ->getMock();
  27. }
  28. return new Config($this->config);
  29. }
  30. public function testIsGlobalScaleEnabled(): void {
  31. $gsConfig = $this->getInstance();
  32. $this->config->expects($this->once())->method('getSystemValueBool')
  33. ->with('gs.enabled', false)->willReturn(true);
  34. $result = $gsConfig->isGlobalScaleEnabled();
  35. $this->assertTrue($result);
  36. }
  37. /**
  38. * @dataProvider dataTestOnlyInternalFederation
  39. *
  40. * @param bool $gsEnabled
  41. * @param string $gsFederation
  42. * @param bool $expected
  43. */
  44. public function testOnlyInternalFederation($gsEnabled, $gsFederation, $expected): void {
  45. $gsConfig = $this->getInstance(['isGlobalScaleEnabled']);
  46. $gsConfig->expects($this->any())->method('isGlobalScaleEnabled')->willReturn($gsEnabled);
  47. $this->config->expects($this->any())->method('getSystemValueString')
  48. ->with('gs.federation', 'internal')->willReturn($gsFederation);
  49. $this->assertSame($expected, $gsConfig->onlyInternalFederation());
  50. }
  51. public function dataTestOnlyInternalFederation() {
  52. return [
  53. [true, 'global', false],
  54. [true, 'internal', true],
  55. [false, 'global', false],
  56. [false, 'internal', false]
  57. ];
  58. }
  59. }