AdminTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\Files_External\Tests\Settings;
  7. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  8. use OCA\Files_External\MountConfig;
  9. use OCA\Files_External\Service\BackendService;
  10. use OCA\Files_External\Service\GlobalStoragesService;
  11. use OCA\Files_External\Settings\Admin;
  12. use OCP\AppFramework\Http\TemplateResponse;
  13. use OCP\Encryption\IManager;
  14. use Test\TestCase;
  15. class AdminTest extends TestCase {
  16. /** @var Admin */
  17. private $admin;
  18. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  19. private $encryptionManager;
  20. /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject */
  21. private $globalStoragesService;
  22. /** @var BackendService|\PHPUnit\Framework\MockObject\MockObject */
  23. private $backendService;
  24. /** @var GlobalAuth|\PHPUnit\Framework\MockObject\MockObject */
  25. private $globalAuth;
  26. protected function setUp(): void {
  27. parent::setUp();
  28. $this->encryptionManager = $this->createMock(IManager::class);
  29. $this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
  30. $this->backendService = $this->createMock(BackendService::class);
  31. $this->globalAuth = $this->createMock(GlobalAuth::class);
  32. $this->admin = new Admin(
  33. $this->encryptionManager,
  34. $this->globalStoragesService,
  35. $this->backendService,
  36. $this->globalAuth
  37. );
  38. }
  39. public function testGetForm(): void {
  40. $this->encryptionManager
  41. ->expects($this->once())
  42. ->method('isEnabled')
  43. ->willReturn(false);
  44. $this->globalStoragesService
  45. ->expects($this->once())
  46. ->method('getStorages')
  47. ->willReturn(['a', 'b', 'c']);
  48. $this->backendService
  49. ->expects($this->once())
  50. ->method('getAvailableBackends')
  51. ->willReturn(['d', 'e', 'f']);
  52. $this->backendService
  53. ->expects($this->once())
  54. ->method('getAuthMechanisms')
  55. ->willReturn(['g', 'h', 'i']);
  56. $this->backendService
  57. ->expects($this->once())
  58. ->method('isUserMountingAllowed')
  59. ->willReturn(true);
  60. $this->backendService
  61. ->expects($this->exactly(2))
  62. ->method('getBackends')
  63. ->willReturn([]);
  64. $this->globalAuth
  65. ->expects($this->once())
  66. ->method('getAuth')
  67. ->with('')
  68. ->willReturn('asdf:asdf');
  69. $params = [
  70. 'encryptionEnabled' => false,
  71. 'visibilityType' => BackendService::VISIBILITY_ADMIN,
  72. 'storages' => ['a', 'b', 'c'],
  73. 'backends' => ['d', 'e', 'f'],
  74. 'authMechanisms' => ['g', 'h', 'i'],
  75. 'dependencies' => MountConfig::dependencyMessage($this->backendService->getBackends()),
  76. 'allowUserMounting' => true,
  77. 'globalCredentials' => 'asdf:asdf',
  78. 'globalCredentialsUid' => '',
  79. ];
  80. $expected = new TemplateResponse('files_external', 'settings', $params, '');
  81. $this->assertEquals($expected, $this->admin->getForm());
  82. }
  83. public function testGetSection(): void {
  84. $this->assertSame('externalstorages', $this->admin->getSection());
  85. }
  86. public function testGetPriority(): void {
  87. $this->assertSame(40, $this->admin->getPriority());
  88. }
  89. }