ExternalStorageTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 Appelman <robin@icewind.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_Sharing\Tests;
  28. use OC\Federation\CloudId;
  29. use OCP\Http\Client\IClient;
  30. use OCP\Http\Client\IClientService;
  31. use OCP\Http\Client\IResponse;
  32. /**
  33. * Tests for the external Storage class for remote shares.
  34. *
  35. * @group DB
  36. */
  37. class ExternalStorageTest extends \Test\TestCase {
  38. function optionsProvider() {
  39. return array(
  40. array(
  41. 'http://remoteserver:8080/owncloud',
  42. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  43. ),
  44. // extra slash
  45. array(
  46. 'http://remoteserver:8080/owncloud/',
  47. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  48. ),
  49. // extra path
  50. array(
  51. 'http://remoteserver:8080/myservices/owncloud/',
  52. 'http://remoteserver:8080/myservices/owncloud/public.php/webdav/',
  53. ),
  54. // root path
  55. array(
  56. 'http://remoteserver:8080/',
  57. 'http://remoteserver:8080/public.php/webdav/',
  58. ),
  59. // without port
  60. array(
  61. 'http://remoteserver/oc.test',
  62. 'http://remoteserver/oc.test/public.php/webdav/',
  63. ),
  64. // https
  65. array(
  66. 'https://remoteserver/',
  67. 'https://remoteserver/public.php/webdav/',
  68. ),
  69. );
  70. }
  71. private function getTestStorage($uri) {
  72. $certificateManager = \OC::$server->getCertificateManager();
  73. $httpClientService = $this->createMock(IClientService::class);
  74. $client = $this->createMock(IClient::class);
  75. $response = $this->createMock(IResponse::class);
  76. $client
  77. ->expects($this->any())
  78. ->method('get')
  79. ->willReturn($response);
  80. $client
  81. ->expects($this->any())
  82. ->method('post')
  83. ->willReturn($response);
  84. $httpClientService
  85. ->expects($this->any())
  86. ->method('newClient')
  87. ->willReturn($client);
  88. return new TestSharingExternalStorage(
  89. array(
  90. 'cloudId' => new CloudId('testOwner@' . $uri, 'testOwner', $uri),
  91. 'remote' => $uri,
  92. 'owner' => 'testOwner',
  93. 'mountpoint' => 'remoteshare',
  94. 'token' => 'abcdef',
  95. 'password' => '',
  96. 'manager' => null,
  97. 'certificateManager' => $certificateManager,
  98. 'HttpClientService' => $httpClientService,
  99. )
  100. );
  101. }
  102. /**
  103. * @dataProvider optionsProvider
  104. */
  105. public function testStorageMountOptions($inputUri, $baseUri) {
  106. $storage = $this->getTestStorage($inputUri);
  107. $this->assertEquals($baseUri, $storage->getBaseUri());
  108. }
  109. public function testIfTestReturnsTheValue() {
  110. $result = $this->getTestStorage('https://remoteserver')->test();
  111. $this->assertSame(true, $result);
  112. }
  113. }
  114. /**
  115. * Dummy subclass to make it possible to access private members
  116. */
  117. class TestSharingExternalStorage extends \OCA\Files_Sharing\External\Storage {
  118. public function getBaseUri() {
  119. return $this->createBaseUri();
  120. }
  121. public function stat($path) {
  122. if ($path === '') {
  123. return true;
  124. }
  125. return parent::stat($path);
  126. }
  127. }