AdminTest.php 3.7 KB

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