You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigTest.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }