AdminTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. protected function setUp(): void {
  43. parent::setUp();
  44. $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
  45. $this->gsConfig = $this->createMock(IConfig::class);
  46. $this->initialState = $this->createMock(IInitialState::class);
  47. $urlGenerator = $this->createMock(IURLGenerator::class);
  48. $urlGenerator->expects($this->any())
  49. ->method('linkToDocs')
  50. ->willReturn('doc-link');
  51. $this->admin = new Admin(
  52. $this->federatedShareProvider,
  53. $this->gsConfig,
  54. $this->createMock(IL10N::class),
  55. $urlGenerator,
  56. $this->initialState
  57. );
  58. }
  59. public function sharingStateProvider() {
  60. return [
  61. [
  62. true,
  63. ],
  64. [
  65. false,
  66. ]
  67. ];
  68. }
  69. /**
  70. * @dataProvider sharingStateProvider
  71. * @param bool $state
  72. */
  73. public function testGetForm($state) {
  74. $this->federatedShareProvider
  75. ->expects($this->once())
  76. ->method('isOutgoingServer2serverShareEnabled')
  77. ->willReturn($state);
  78. $this->federatedShareProvider
  79. ->expects($this->once())
  80. ->method('isIncomingServer2serverShareEnabled')
  81. ->willReturn($state);
  82. $this->federatedShareProvider
  83. ->expects($this->once())
  84. ->method('isIncomingServer2serverShareEnabled')
  85. ->willReturn($state);
  86. $this->federatedShareProvider
  87. ->expects($this->once())
  88. ->method('isLookupServerQueriesEnabled')
  89. ->willReturn($state);
  90. $this->federatedShareProvider
  91. ->expects($this->once())
  92. ->method('isLookupServerUploadEnabled')
  93. ->willReturn($state);
  94. $this->federatedShareProvider
  95. ->expects($this->once())
  96. ->method('isFederatedGroupSharingSupported')
  97. ->willReturn($state);
  98. $this->federatedShareProvider
  99. ->expects($this->once())
  100. ->method('isOutgoingServer2serverGroupShareEnabled')
  101. ->willReturn($state);
  102. $this->federatedShareProvider
  103. ->expects($this->once())
  104. ->method('isIncomingServer2serverGroupShareEnabled')
  105. ->willReturn($state);
  106. $this->gsConfig->expects($this->once())->method('onlyInternalFederation')
  107. ->willReturn($state);
  108. $this->initialState->expects($this->exactly(9))
  109. ->method('provideInitialState')
  110. ->withConsecutive(
  111. ['internalOnly', $state],
  112. ['sharingFederatedDocUrl', 'doc-link'],
  113. ['outgoingServer2serverShareEnabled', $state],
  114. ['incomingServer2serverShareEnabled', $state],
  115. ['federatedGroupSharingSupported', $state],
  116. ['outgoingServer2serverGroupShareEnabled', $state],
  117. ['incomingServer2serverGroupShareEnabled', $state],
  118. ['lookupServerEnabled', $state],
  119. ['lookupServerUploadEnabled', $state],
  120. );
  121. $expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');
  122. $this->assertEquals($expected, $this->admin->getForm());
  123. }
  124. public function testGetSection() {
  125. $this->assertSame('sharing', $this->admin->getSection());
  126. }
  127. public function testGetPriority() {
  128. $this->assertSame(20, $this->admin->getPriority());
  129. }
  130. }