ProviderTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@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 Test\OCS;
  22. use OC\OCS\Provider;
  23. class ProviderTest extends \Test\TestCase {
  24. /** @var \OCP\IRequest */
  25. private $request;
  26. /** @var \OCP\App\IAppManager */
  27. private $appManager;
  28. /** @var Provider */
  29. private $ocsProvider;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock();
  33. $this->appManager = $this->getMockBuilder('\\OCP\\App\\IAppManager')->getMock();
  34. $this->ocsProvider = new Provider('ocs_provider', $this->request, $this->appManager);
  35. }
  36. public function testBuildProviderListWithoutAnythingEnabled() {
  37. $this->appManager
  38. ->expects($this->exactly(4))
  39. ->method('isEnabledForUser')
  40. ->withConsecutive(
  41. ['files_sharing'],
  42. ['federation'],
  43. ['activity'],
  44. ['provisioning_api']
  45. )
  46. ->willReturn(false);
  47. $expected = new \OCP\AppFramework\Http\JSONResponse(
  48. [
  49. 'version' => 2,
  50. 'services' => [
  51. 'PRIVATE_DATA' => [
  52. 'version' => 1,
  53. 'endpoints' => [
  54. 'store' => '/ocs/v2.php/privatedata/setattribute',
  55. 'read' => '/ocs/v2.php/privatedata/getattribute',
  56. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  57. ],
  58. ],
  59. ],
  60. ]
  61. );
  62. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  63. }
  64. public function testBuildProviderListWithSharingEnabled() {
  65. $this->appManager
  66. ->expects($this->exactly(4))
  67. ->method('isEnabledForUser')
  68. ->withConsecutive(
  69. ['files_sharing'],
  70. ['federation'],
  71. ['activity'],
  72. ['provisioning_api']
  73. )
  74. ->willReturnOnConsecutiveCalls(
  75. true,
  76. false,
  77. false,
  78. false
  79. );
  80. $expected = new \OCP\AppFramework\Http\JSONResponse(
  81. [
  82. 'version' => 2,
  83. 'services' => [
  84. 'PRIVATE_DATA' => [
  85. 'version' => 1,
  86. 'endpoints' => [
  87. 'store' => '/ocs/v2.php/privatedata/setattribute',
  88. 'read' => '/ocs/v2.php/privatedata/getattribute',
  89. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  90. ],
  91. ],
  92. 'FEDERATED_SHARING' => [
  93. 'version' => 1,
  94. 'endpoints' => [
  95. 'share' => '/ocs/v2.php/cloud/shares',
  96. 'webdav' => '/public.php/webdav/',
  97. ],
  98. ],
  99. 'SHARING' => [
  100. 'version' => 1,
  101. 'endpoints' => [
  102. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  103. ],
  104. ],
  105. ],
  106. ]
  107. );
  108. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  109. }
  110. public function testBuildProviderListWithFederationEnabled() {
  111. $this->appManager
  112. ->expects($this->exactly(4))
  113. ->method('isEnabledForUser')
  114. ->withConsecutive(
  115. ['files_sharing'],
  116. ['federation'],
  117. ['activity'],
  118. ['provisioning_api']
  119. )
  120. ->willReturnOnConsecutiveCalls(
  121. false,
  122. true,
  123. false,
  124. false
  125. );
  126. $expected = new \OCP\AppFramework\Http\JSONResponse(
  127. [
  128. 'version' => 2,
  129. 'services' => [
  130. 'PRIVATE_DATA' => [
  131. 'version' => 1,
  132. 'endpoints' => [
  133. 'store' => '/ocs/v2.php/privatedata/setattribute',
  134. 'read' => '/ocs/v2.php/privatedata/getattribute',
  135. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  136. ],
  137. ],
  138. 'FEDERATED_SHARING' => [
  139. 'version' => 1,
  140. 'endpoints' => [
  141. 'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
  142. 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
  143. 'carddav-user' => 'system'
  144. ],
  145. ],
  146. ],
  147. ]
  148. );
  149. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  150. }
  151. public function testBuildProviderListWithEverythingEnabled() {
  152. $this->appManager
  153. ->expects($this->any())
  154. ->method('isEnabledForUser')
  155. ->willReturn(true);
  156. $expected = new \OCP\AppFramework\Http\JSONResponse(
  157. [
  158. 'version' => 2,
  159. 'services' => [
  160. 'PRIVATE_DATA' => [
  161. 'version' => 1,
  162. 'endpoints' => [
  163. 'store' => '/ocs/v2.php/privatedata/setattribute',
  164. 'read' => '/ocs/v2.php/privatedata/getattribute',
  165. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  166. ],
  167. ],
  168. 'FEDERATED_SHARING' => [
  169. 'version' => 1,
  170. 'endpoints' => [
  171. 'share' => '/ocs/v2.php/cloud/shares',
  172. 'webdav' => '/public.php/webdav/',
  173. 'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
  174. 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
  175. 'carddav-user' => 'system'
  176. ],
  177. ],
  178. 'SHARING' => [
  179. 'version' => 1,
  180. 'endpoints' => [
  181. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  182. ],
  183. ],
  184. 'ACTIVITY' => [
  185. 'version' => 1,
  186. 'endpoints' => [
  187. 'list' => '/ocs/v2.php/cloud/activity',
  188. ],
  189. ],
  190. 'PROVISIONING' => [
  191. 'version' => 1,
  192. 'endpoints' => [
  193. 'user' => '/ocs/v2.php/cloud/users',
  194. 'groups' => '/ocs/v2.php/cloud/groups',
  195. 'apps' => '/ocs/v2.php/cloud/apps',
  196. ],
  197. ],
  198. ],
  199. ]
  200. );
  201. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  202. }
  203. }