StorageConfigTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Tests;
  8. use OCA\Files_External\Lib\Auth\AuthMechanism;
  9. use OCA\Files_External\Lib\Backend\Backend;
  10. use OCA\Files_External\Lib\DefinitionParameter;
  11. use OCA\Files_External\Lib\StorageConfig;
  12. class StorageConfigTest extends \Test\TestCase {
  13. public function testJsonSerialization() {
  14. $backend = $this->getMockBuilder(Backend::class)
  15. ->disableOriginalConstructor()
  16. ->getMock();
  17. $parameter = $this->getMockBuilder(DefinitionParameter::class)
  18. ->disableOriginalConstructor()
  19. ->getMock();
  20. $parameter
  21. ->expects($this->once())
  22. ->method('getType')
  23. ->willReturn(1);
  24. $backend
  25. ->expects($this->once())
  26. ->method('getParameters')
  27. ->willReturn(['secure' => $parameter]);
  28. $backend->method('getIdentifier')
  29. ->willReturn('storage::identifier');
  30. $authMech = $this->getMockBuilder(AuthMechanism::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $authMech->method('getIdentifier')
  34. ->willReturn('auth::identifier');
  35. $storageConfig = new StorageConfig(1);
  36. $storageConfig->setMountPoint('test');
  37. $storageConfig->setBackend($backend);
  38. $storageConfig->setAuthMechanism($authMech);
  39. $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']);
  40. $storageConfig->setPriority(128);
  41. $storageConfig->setApplicableUsers(['user1', 'user2']);
  42. $storageConfig->setApplicableGroups(['group1', 'group2']);
  43. $storageConfig->setMountOptions(['preview' => false]);
  44. $json = $storageConfig->jsonSerialize();
  45. $this->assertSame(1, $json['id']);
  46. $this->assertSame('/test', $json['mountPoint']);
  47. $this->assertSame('storage::identifier', $json['backend']);
  48. $this->assertSame('auth::identifier', $json['authMechanism']);
  49. $this->assertSame('test', $json['backendOptions']['user']);
  50. $this->assertSame('password123', $json['backendOptions']['password']);
  51. $this->assertSame(true, $json['backendOptions']['secure']);
  52. $this->assertSame(128, $json['priority']);
  53. $this->assertSame(['user1', 'user2'], $json['applicableUsers']);
  54. $this->assertSame(['group1', 'group2'], $json['applicableGroups']);
  55. $this->assertSame(['preview' => false], $json['mountOptions']);
  56. }
  57. }