AdminTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\FederatedFileSharing\Tests\Settings;
  26. use OCA\FederatedFileSharing\FederatedShareProvider;
  27. use OCA\FederatedFileSharing\Settings\Admin;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\GlobalScale\IConfig;
  30. use Test\TestCase;
  31. class AdminTest extends TestCase {
  32. /** @var Admin */
  33. private $admin;
  34. /** @var \OCA\FederatedFileSharing\FederatedShareProvider */
  35. private $federatedShareProvider;
  36. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  37. private $gsConfig;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
  41. $this->gsConfig = $this->createMock(IConfig::class);
  42. $this->admin = new Admin(
  43. $this->federatedShareProvider,
  44. $this->gsConfig
  45. );
  46. }
  47. public function sharingStateProvider() {
  48. return [
  49. [
  50. true,
  51. ],
  52. [
  53. false,
  54. ]
  55. ];
  56. }
  57. /**
  58. * @dataProvider sharingStateProvider
  59. * @param bool $state
  60. */
  61. public function testGetForm($state) {
  62. $this->federatedShareProvider
  63. ->expects($this->once())
  64. ->method('isOutgoingServer2serverShareEnabled')
  65. ->willReturn($state);
  66. $this->federatedShareProvider
  67. ->expects($this->once())
  68. ->method('isIncomingServer2serverShareEnabled')
  69. ->willReturn($state);
  70. $this->federatedShareProvider
  71. ->expects($this->once())
  72. ->method('isIncomingServer2serverShareEnabled')
  73. ->willReturn($state);
  74. $this->federatedShareProvider
  75. ->expects($this->once())
  76. ->method('isLookupServerQueriesEnabled')
  77. ->willReturn($state);
  78. $this->federatedShareProvider
  79. ->expects($this->once())
  80. ->method('isLookupServerUploadEnabled')
  81. ->willReturn($state);
  82. $this->federatedShareProvider
  83. ->expects($this->once())
  84. ->method('isFederatedGroupSharingSupported')
  85. ->willReturn($state);
  86. $this->federatedShareProvider
  87. ->expects($this->once())
  88. ->method('isOutgoingServer2serverGroupShareEnabled')
  89. ->willReturn($state);
  90. $this->federatedShareProvider
  91. ->expects($this->once())
  92. ->method('isIncomingServer2serverGroupShareEnabled')
  93. ->willReturn($state);
  94. $this->gsConfig->expects($this->once())->method('onlyInternalFederation')
  95. ->willReturn($state);
  96. $params = [
  97. 'internalOnly' => $state,
  98. 'outgoingServer2serverShareEnabled' => $state,
  99. 'incomingServer2serverShareEnabled' => $state,
  100. 'lookupServerEnabled' => $state,
  101. 'lookupServerUploadEnabled' => $state,
  102. 'federatedGroupSharingSupported' => $state,
  103. 'outgoingServer2serverGroupShareEnabled' => $state,
  104. 'incomingServer2serverGroupShareEnabled' => $state,
  105. ];
  106. $expected = new TemplateResponse('federatedfilesharing', 'settings-admin', $params, '');
  107. $this->assertEquals($expected, $this->admin->getForm());
  108. }
  109. public function testGetSection() {
  110. $this->assertSame('sharing', $this->admin->getSection());
  111. }
  112. public function testGetPriority() {
  113. $this->assertSame(20, $this->admin->getPriority());
  114. }
  115. }