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

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