1
0

ProviderTest.php 5.1 KB

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