AdminTest.php 3.7 KB

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