StorageConfigTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin McCorkell <robin@mccorkell.me.uk>
  9. * @author Vincent Petry <vincent@nextcloud.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;
  27. use OCA\Files_External\Lib\Auth\AuthMechanism;
  28. use OCA\Files_External\Lib\Backend\Backend;
  29. use OCA\Files_External\Lib\DefinitionParameter;
  30. use OCA\Files_External\Lib\StorageConfig;
  31. class StorageConfigTest extends \Test\TestCase {
  32. public function testJsonSerialization() {
  33. $backend = $this->getMockBuilder(Backend::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $parameter = $this->getMockBuilder(DefinitionParameter::class)
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $parameter
  40. ->expects($this->once())
  41. ->method('getType')
  42. ->willReturn(1);
  43. $backend
  44. ->expects($this->once())
  45. ->method('getParameters')
  46. ->willReturn(['secure' => $parameter]);
  47. $backend->method('getIdentifier')
  48. ->willReturn('storage::identifier');
  49. $authMech = $this->getMockBuilder(AuthMechanism::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $authMech->method('getIdentifier')
  53. ->willReturn('auth::identifier');
  54. $storageConfig = new StorageConfig(1);
  55. $storageConfig->setMountPoint('test');
  56. $storageConfig->setBackend($backend);
  57. $storageConfig->setAuthMechanism($authMech);
  58. $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']);
  59. $storageConfig->setPriority(128);
  60. $storageConfig->setApplicableUsers(['user1', 'user2']);
  61. $storageConfig->setApplicableGroups(['group1', 'group2']);
  62. $storageConfig->setMountOptions(['preview' => false]);
  63. $json = $storageConfig->jsonSerialize();
  64. $this->assertSame(1, $json['id']);
  65. $this->assertSame('/test', $json['mountPoint']);
  66. $this->assertSame('storage::identifier', $json['backend']);
  67. $this->assertSame('auth::identifier', $json['authMechanism']);
  68. $this->assertSame('test', $json['backendOptions']['user']);
  69. $this->assertSame('password123', $json['backendOptions']['password']);
  70. $this->assertSame(true, $json['backendOptions']['secure']);
  71. $this->assertSame(128, $json['priority']);
  72. $this->assertSame(['user1', 'user2'], $json['applicableUsers']);
  73. $this->assertSame(['group1', 'group2'], $json['applicableGroups']);
  74. $this->assertSame(['preview' => false], $json['mountOptions']);
  75. }
  76. }