AdminTest.php 2.9 KB

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