UserStoragesControllerTest.php 3.1 KB

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