storageconfigtest.php 2.4 KB

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