You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StorageConfigTest.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Robin McCorkell <robin@mccorkell.me.uk>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_External\Tests;
  26. use OCA\Files_External\Lib\StorageConfig;
  27. class StorageConfigTest extends \Test\TestCase {
  28. public function testJsonSerialization() {
  29. $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $parameter = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter')
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $parameter
  36. ->expects($this->once())
  37. ->method('getType')
  38. ->willReturn(1);
  39. $backend
  40. ->expects($this->once())
  41. ->method('getParameters')
  42. ->willReturn(['secure' => $parameter]);
  43. $backend->method('getIdentifier')
  44. ->willReturn('storage::identifier');
  45. $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. $authMech->method('getIdentifier')
  49. ->willReturn('auth::identifier');
  50. $storageConfig = new StorageConfig(1);
  51. $storageConfig->setMountPoint('test');
  52. $storageConfig->setBackend($backend);
  53. $storageConfig->setAuthMechanism($authMech);
  54. $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']);
  55. $storageConfig->setPriority(128);
  56. $storageConfig->setApplicableUsers(['user1', 'user2']);
  57. $storageConfig->setApplicableGroups(['group1', 'group2']);
  58. $storageConfig->setMountOptions(['preview' => false]);
  59. $json = $storageConfig->jsonSerialize();
  60. $this->assertSame(1, $json['id']);
  61. $this->assertSame('/test', $json['mountPoint']);
  62. $this->assertSame('storage::identifier', $json['backend']);
  63. $this->assertSame('auth::identifier', $json['authMechanism']);
  64. $this->assertSame('test', $json['backendOptions']['user']);
  65. $this->assertSame('password123', $json['backendOptions']['password']);
  66. $this->assertSame(true, $json['backendOptions']['secure']);
  67. $this->assertSame(128, $json['priority']);
  68. $this->assertSame(['user1', 'user2'], $json['applicableUsers']);
  69. $this->assertSame(['group1', 'group2'], $json['applicableGroups']);
  70. $this->assertSame(['preview' => false], $json['mountOptions']);
  71. }
  72. }