UserStoragesControllerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Robin McCorkell <robin@mccorkell.me.uk>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_External\Tests\Controller;
  28. use OCA\Files_External\Controller\UserStoragesController;
  29. use OCA\Files_External\Lib\StorageConfig;
  30. use OCA\Files_External\Service\BackendService;
  31. use OCP\AppFramework\Http;
  32. use OCP\IL10N;
  33. use OCP\ILogger;
  34. use OCP\IRequest;
  35. use OCP\IUserSession;
  36. class UserStoragesControllerTest extends StoragesControllerTest {
  37. /**
  38. * @var array
  39. */
  40. private $oldAllowedBackends;
  41. protected function setUp(): void {
  42. parent::setUp();
  43. $this->service = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService')
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->service->method('getVisibilityType')
  47. ->willReturn(BackendService::VISIBILITY_PERSONAL);
  48. $this->controller = new UserStoragesController(
  49. 'files_external',
  50. $this->createMock(IRequest::class),
  51. $this->createMock(IL10N::class),
  52. $this->service,
  53. $this->createMock(IUserSession::class),
  54. $this->createMock(ILogger::class)
  55. );
  56. }
  57. public function testAddOrUpdateStorageDisallowedBackend() {
  58. $backend = $this->getBackendMock();
  59. $backend->method('isVisibleFor')
  60. ->with(BackendService::VISIBILITY_PERSONAL)
  61. ->willReturn(false);
  62. $authMech = $this->getAuthMechMock();
  63. $storageConfig = new StorageConfig(1);
  64. $storageConfig->setMountPoint('mount');
  65. $storageConfig->setBackend($backend);
  66. $storageConfig->setAuthMechanism($authMech);
  67. $storageConfig->setBackendOptions([]);
  68. $this->service->expects($this->exactly(2))
  69. ->method('createStorage')
  70. ->willReturn($storageConfig);
  71. $this->service->expects($this->never())
  72. ->method('addStorage');
  73. $this->service->expects($this->never())
  74. ->method('updateStorage');
  75. $response = $this->controller->create(
  76. 'mount',
  77. '\OCA\Files_External\Lib\Storage\SMB',
  78. '\Auth\Mechanism',
  79. [],
  80. [],
  81. [],
  82. [],
  83. null
  84. );
  85. $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
  86. $response = $this->controller->update(
  87. 1,
  88. 'mount',
  89. '\OCA\Files_External\Lib\Storage\SMB',
  90. '\Auth\Mechanism',
  91. [],
  92. [],
  93. [],
  94. [],
  95. null
  96. );
  97. $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
  98. }
  99. }