AdminTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\FederatedFileSharing\Tests\Settings;
  7. use OCA\FederatedFileSharing\FederatedShareProvider;
  8. use OCA\FederatedFileSharing\Settings\Admin;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\GlobalScale\IConfig;
  12. use OCP\IL10N;
  13. use OCP\IURLGenerator;
  14. use Test\TestCase;
  15. class AdminTest extends TestCase {
  16. /** @var Admin */
  17. private $admin;
  18. /** @var \OCA\FederatedFileSharing\FederatedShareProvider */
  19. private $federatedShareProvider;
  20. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  21. private $gsConfig;
  22. /** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
  23. private $initialState;
  24. protected function setUp(): void {
  25. parent::setUp();
  26. $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
  27. $this->gsConfig = $this->createMock(IConfig::class);
  28. $this->initialState = $this->createMock(IInitialState::class);
  29. $urlGenerator = $this->createMock(IURLGenerator::class);
  30. $urlGenerator->expects($this->any())
  31. ->method('linkToDocs')
  32. ->willReturn('doc-link');
  33. $this->admin = new Admin(
  34. $this->federatedShareProvider,
  35. $this->gsConfig,
  36. $this->createMock(IL10N::class),
  37. $urlGenerator,
  38. $this->initialState
  39. );
  40. }
  41. public function sharingStateProvider() {
  42. return [
  43. [
  44. true,
  45. ],
  46. [
  47. false,
  48. ]
  49. ];
  50. }
  51. /**
  52. * @dataProvider sharingStateProvider
  53. * @param bool $state
  54. */
  55. public function testGetForm($state) {
  56. $this->federatedShareProvider
  57. ->expects($this->once())
  58. ->method('isOutgoingServer2serverShareEnabled')
  59. ->willReturn($state);
  60. $this->federatedShareProvider
  61. ->expects($this->once())
  62. ->method('isIncomingServer2serverShareEnabled')
  63. ->willReturn($state);
  64. $this->federatedShareProvider
  65. ->expects($this->once())
  66. ->method('isIncomingServer2serverShareEnabled')
  67. ->willReturn($state);
  68. $this->federatedShareProvider
  69. ->expects($this->once())
  70. ->method('isLookupServerQueriesEnabled')
  71. ->willReturn($state);
  72. $this->federatedShareProvider
  73. ->expects($this->once())
  74. ->method('isLookupServerUploadEnabled')
  75. ->willReturn($state);
  76. $this->federatedShareProvider
  77. ->expects($this->once())
  78. ->method('isFederatedGroupSharingSupported')
  79. ->willReturn($state);
  80. $this->federatedShareProvider
  81. ->expects($this->once())
  82. ->method('isOutgoingServer2serverGroupShareEnabled')
  83. ->willReturn($state);
  84. $this->federatedShareProvider
  85. ->expects($this->once())
  86. ->method('isIncomingServer2serverGroupShareEnabled')
  87. ->willReturn($state);
  88. $this->gsConfig->expects($this->once())->method('onlyInternalFederation')
  89. ->willReturn($state);
  90. $this->initialState->expects($this->exactly(9))
  91. ->method('provideInitialState')
  92. ->withConsecutive(
  93. ['internalOnly', $state],
  94. ['sharingFederatedDocUrl', 'doc-link'],
  95. ['outgoingServer2serverShareEnabled', $state],
  96. ['incomingServer2serverShareEnabled', $state],
  97. ['federatedGroupSharingSupported', $state],
  98. ['outgoingServer2serverGroupShareEnabled', $state],
  99. ['incomingServer2serverGroupShareEnabled', $state],
  100. ['lookupServerEnabled', $state],
  101. ['lookupServerUploadEnabled', $state],
  102. );
  103. $expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');
  104. $this->assertEquals($expected, $this->admin->getForm());
  105. }
  106. public function testGetSection() {
  107. $this->assertSame('sharing', $this->admin->getSection());
  108. }
  109. public function testGetPriority() {
  110. $this->assertSame(20, $this->admin->getPriority());
  111. }
  112. }