AdminTest.php 4.4 KB

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