storageconfigtest.php 2.5 KB

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