AdminTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Files_External\Tests\Settings;
  27. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  28. use OCA\Files_External\Service\BackendService;
  29. use OCA\Files_External\Service\GlobalStoragesService;
  30. use OCA\Files_External\Settings\Admin;
  31. use OCP\AppFramework\Http\TemplateResponse;
  32. use OCP\Encryption\IManager;
  33. use Test\TestCase;
  34. class AdminTest extends TestCase {
  35. /** @var Admin */
  36. private $admin;
  37. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  38. private $encryptionManager;
  39. /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject */
  40. private $globalStoragesService;
  41. /** @var BackendService|\PHPUnit\Framework\MockObject\MockObject */
  42. private $backendService;
  43. /** @var GlobalAuth|\PHPUnit\Framework\MockObject\MockObject */
  44. private $globalAuth;
  45. protected function setUp(): void {
  46. parent::setUp();
  47. $this->encryptionManager = $this->createMock(IManager::class);
  48. $this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
  49. $this->backendService = $this->createMock(BackendService::class);
  50. $this->globalAuth = $this->createMock(GlobalAuth::class);
  51. $this->admin = new Admin(
  52. $this->encryptionManager,
  53. $this->globalStoragesService,
  54. $this->backendService,
  55. $this->globalAuth
  56. );
  57. }
  58. public function testGetForm() {
  59. $this->encryptionManager
  60. ->expects($this->once())
  61. ->method('isEnabled')
  62. ->willReturn(false);
  63. $this->globalStoragesService
  64. ->expects($this->once())
  65. ->method('getStorages')
  66. ->willReturn(['a', 'b', 'c']);
  67. $this->backendService
  68. ->expects($this->once())
  69. ->method('getAvailableBackends')
  70. ->willReturn(['d', 'e', 'f']);
  71. $this->backendService
  72. ->expects($this->once())
  73. ->method('getAuthMechanisms')
  74. ->willReturn(['g', 'h', 'i']);
  75. $this->backendService
  76. ->expects($this->once())
  77. ->method('isUserMountingAllowed')
  78. ->willReturn(true);
  79. $this->backendService
  80. ->expects($this->exactly(2))
  81. ->method('getBackends')
  82. ->willReturn([]);
  83. $this->globalAuth
  84. ->expects($this->once())
  85. ->method('getAuth')
  86. ->with('')
  87. ->willReturn('asdf:asdf');
  88. $params = [
  89. 'encryptionEnabled' => false,
  90. 'visibilityType' => BackendService::VISIBILITY_ADMIN,
  91. 'storages' => ['a', 'b', 'c'],
  92. 'backends' => ['d', 'e', 'f'],
  93. 'authMechanisms' => ['g', 'h', 'i'],
  94. 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
  95. 'allowUserMounting' => true,
  96. 'globalCredentials' => 'asdf:asdf',
  97. 'globalCredentialsUid' => '',
  98. ];
  99. $expected = new TemplateResponse('files_external', 'settings', $params, '');
  100. $this->assertEquals($expected, $this->admin->getForm());
  101. }
  102. public function testGetSection() {
  103. $this->assertSame('externalstorages', $this->admin->getSection());
  104. }
  105. public function testGetPriority() {
  106. $this->assertSame(40, $this->admin->getPriority());
  107. }
  108. }