You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminTest.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  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\Files_External\Tests\Settings;
  26. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  27. use OCA\Files_External\Service\BackendService;
  28. use OCA\Files_External\Service\GlobalStoragesService;
  29. use OCA\Files_External\Settings\Admin;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\Encryption\IManager;
  32. use Test\TestCase;
  33. class AdminTest extends TestCase {
  34. /** @var Admin */
  35. private $admin;
  36. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  37. private $encryptionManager;
  38. /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject */
  39. private $globalStoragesService;
  40. /** @var BackendService|\PHPUnit\Framework\MockObject\MockObject */
  41. private $backendService;
  42. /** @var GlobalAuth|\PHPUnit\Framework\MockObject\MockObject */
  43. private $globalAuth;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. $this->encryptionManager = $this->createMock(IManager::class);
  47. $this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
  48. $this->backendService = $this->createMock(BackendService::class);
  49. $this->globalAuth = $this->createMock(GlobalAuth::class);
  50. $this->admin = new Admin(
  51. $this->encryptionManager,
  52. $this->globalStoragesService,
  53. $this->backendService,
  54. $this->globalAuth
  55. );
  56. }
  57. public function testGetForm() {
  58. $this->encryptionManager
  59. ->expects($this->once())
  60. ->method('isEnabled')
  61. ->willReturn(false);
  62. $this->globalStoragesService
  63. ->expects($this->once())
  64. ->method('getStorages')
  65. ->willReturn(['a', 'b', 'c']);
  66. $this->backendService
  67. ->expects($this->once())
  68. ->method('getAvailableBackends')
  69. ->willReturn(['d', 'e', 'f']);
  70. $this->backendService
  71. ->expects($this->once())
  72. ->method('getAuthMechanisms')
  73. ->willReturn(['g', 'h', 'i']);
  74. $this->backendService
  75. ->expects($this->once())
  76. ->method('isUserMountingAllowed')
  77. ->willReturn(true);
  78. $this->backendService
  79. ->expects($this->exactly(2))
  80. ->method('getBackends')
  81. ->willReturn([]);
  82. $this->globalAuth
  83. ->expects($this->once())
  84. ->method('getAuth')
  85. ->with('')
  86. ->willReturn('asdf:asdf');
  87. $params = [
  88. 'encryptionEnabled' => false,
  89. 'visibilityType' => BackendService::VISIBILITY_ADMIN,
  90. 'storages' => ['a', 'b', 'c'],
  91. 'backends' => ['d', 'e', 'f'],
  92. 'authMechanisms' => ['g', 'h', 'i'],
  93. 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
  94. 'allowUserMounting' => true,
  95. 'globalCredentials' => 'asdf:asdf',
  96. 'globalCredentialsUid' => '',
  97. ];
  98. $expected = new TemplateResponse('files_external', 'settings', $params, '');
  99. $this->assertEquals($expected, $this->admin->getForm());
  100. }
  101. public function testGetSection() {
  102. $this->assertSame('externalstorages', $this->admin->getSection());
  103. }
  104. public function testGetPriority() {
  105. $this->assertSame(40, $this->admin->getPriority());
  106. }
  107. }