ConfigTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\GlobalScale;
  22. use OC\GlobalScale\Config;
  23. use OCP\IConfig;
  24. use Test\TestCase;
  25. class ConfigTest extends TestCase {
  26. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  27. private $config;
  28. protected function setUp(): void {
  29. parent::setUp();
  30. $this->config = $this->createMock(IConfig::class);
  31. }
  32. /**
  33. * @param array $mockMethods
  34. * @return Config|\PHPUnit\Framework\MockObject\MockObject
  35. */
  36. public function getInstance($mockMethods = []) {
  37. if (!empty($mockMethods)) {
  38. return $this->getMockBuilder(Config::class)
  39. ->setConstructorArgs([$this->config])
  40. ->setMethods($mockMethods)
  41. ->getMock();
  42. }
  43. return new Config($this->config);
  44. }
  45. public function testIsGlobalScaleEnabled() {
  46. $gsConfig = $this->getInstance();
  47. $this->config->expects($this->once())->method('getSystemValue')
  48. ->with('gs.enabled', false)->willReturn(true);
  49. $result = $gsConfig->isGlobalScaleEnabled();
  50. $this->assertTrue($result);
  51. }
  52. /**
  53. * @dataProvider dataTestOnlyInternalFederation
  54. *
  55. * @param bool $gsEnabled
  56. * @param string $gsFederation
  57. * @param bool $expected
  58. */
  59. public function testOnlyInternalFederation($gsEnabled, $gsFederation, $expected) {
  60. $gsConfig = $this->getInstance(['isGlobalScaleEnabled']);
  61. $gsConfig->expects($this->any())->method('isGlobalScaleEnabled')->willReturn($gsEnabled);
  62. $this->config->expects($this->any())->method('getSystemValue')
  63. ->with('gs.federation', 'internal')->willReturn($gsFederation);
  64. $this->assertSame($expected, $gsConfig->onlyInternalFederation());
  65. }
  66. public function dataTestOnlyInternalFederation() {
  67. return [
  68. [true, 'global', false],
  69. [true, 'internal', true],
  70. [false, 'global', false],
  71. [false, 'internal', false]
  72. ];
  73. }
  74. }