ProviderTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. public function setUp() {
  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->at(0))
  39. ->method('isEnabledForUser')
  40. ->with('files_sharing')
  41. ->will($this->returnValue(false));
  42. $this->appManager
  43. ->expects($this->at(1))
  44. ->method('isEnabledForUser')
  45. ->with('federation')
  46. ->will($this->returnValue(false));
  47. $this->appManager
  48. ->expects($this->at(2))
  49. ->method('isEnabledForUser')
  50. ->with('activity')
  51. ->will($this->returnValue(false));
  52. $this->appManager
  53. ->expects($this->at(3))
  54. ->method('isEnabledForUser')
  55. ->with('provisioning_api')
  56. ->will($this->returnValue(false));
  57. $expected = new \OCP\AppFramework\Http\JSONResponse(
  58. [
  59. 'version' => 2,
  60. 'services' => [
  61. 'PRIVATE_DATA' => [
  62. 'version' => 1,
  63. 'endpoints' => [
  64. 'store' => '/ocs/v2.php/privatedata/setattribute',
  65. 'read' => '/ocs/v2.php/privatedata/getattribute',
  66. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  67. ],
  68. ],
  69. ],
  70. ]
  71. );
  72. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  73. }
  74. public function testBuildProviderListWithSharingEnabled() {
  75. $this->appManager
  76. ->expects($this->at(0))
  77. ->method('isEnabledForUser')
  78. ->with('files_sharing')
  79. ->will($this->returnValue(true));
  80. $this->appManager
  81. ->expects($this->at(1))
  82. ->method('isEnabledForUser')
  83. ->with('federation')
  84. ->will($this->returnValue(false));
  85. $this->appManager
  86. ->expects($this->at(2))
  87. ->method('isEnabledForUser')
  88. ->with('activity')
  89. ->will($this->returnValue(false));
  90. $this->appManager
  91. ->expects($this->at(3))
  92. ->method('isEnabledForUser')
  93. ->with('provisioning_api')
  94. ->will($this->returnValue(false));
  95. $expected = new \OCP\AppFramework\Http\JSONResponse(
  96. [
  97. 'version' => 2,
  98. 'services' => [
  99. 'PRIVATE_DATA' => [
  100. 'version' => 1,
  101. 'endpoints' => [
  102. 'store' => '/ocs/v2.php/privatedata/setattribute',
  103. 'read' => '/ocs/v2.php/privatedata/getattribute',
  104. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  105. ],
  106. ],
  107. 'FEDERATED_SHARING' => [
  108. 'version' => 1,
  109. 'endpoints' => [
  110. 'share' => '/ocs/v2.php/cloud/shares',
  111. 'webdav' => '/public.php/webdav/',
  112. ],
  113. ],
  114. 'SHARING' => [
  115. 'version' => 1,
  116. 'endpoints' => [
  117. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  118. ],
  119. ],
  120. ],
  121. ]
  122. );
  123. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  124. }
  125. public function testBuildProviderListWithFederationEnabled() {
  126. $this->appManager
  127. ->expects($this->at(0))
  128. ->method('isEnabledForUser')
  129. ->with('files_sharing')
  130. ->will($this->returnValue(false));
  131. $this->appManager
  132. ->expects($this->at(1))
  133. ->method('isEnabledForUser')
  134. ->with('federation')
  135. ->will($this->returnValue(true));
  136. $this->appManager
  137. ->expects($this->at(2))
  138. ->method('isEnabledForUser')
  139. ->with('activity')
  140. ->will($this->returnValue(false));
  141. $this->appManager
  142. ->expects($this->at(3))
  143. ->method('isEnabledForUser')
  144. ->with('provisioning_api')
  145. ->will($this->returnValue(false));
  146. $expected = new \OCP\AppFramework\Http\JSONResponse(
  147. [
  148. 'version' => 2,
  149. 'services' => [
  150. 'PRIVATE_DATA' => [
  151. 'version' => 1,
  152. 'endpoints' => [
  153. 'store' => '/ocs/v2.php/privatedata/setattribute',
  154. 'read' => '/ocs/v2.php/privatedata/getattribute',
  155. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  156. ],
  157. ],
  158. 'FEDERATED_SHARING' => [
  159. 'version' => 1,
  160. 'endpoints' => [
  161. 'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
  162. 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
  163. 'carddav-user' => 'system'
  164. ],
  165. ],
  166. ],
  167. ]
  168. );
  169. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  170. }
  171. public function testBuildProviderListWithEverythingEnabled() {
  172. $this->appManager
  173. ->expects($this->any())
  174. ->method('isEnabledForUser')
  175. ->will($this->returnValue(true));
  176. $expected = new \OCP\AppFramework\Http\JSONResponse(
  177. [
  178. 'version' => 2,
  179. 'services' => [
  180. 'PRIVATE_DATA' => [
  181. 'version' => 1,
  182. 'endpoints' => [
  183. 'store' => '/ocs/v2.php/privatedata/setattribute',
  184. 'read' => '/ocs/v2.php/privatedata/getattribute',
  185. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  186. ],
  187. ],
  188. 'FEDERATED_SHARING' => [
  189. 'version' => 1,
  190. 'endpoints' => [
  191. 'share' => '/ocs/v2.php/cloud/shares',
  192. 'webdav' => '/public.php/webdav/',
  193. 'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
  194. 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
  195. 'carddav-user' => 'system'
  196. ],
  197. ],
  198. 'SHARING' => [
  199. 'version' => 1,
  200. 'endpoints' => [
  201. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  202. ],
  203. ],
  204. 'ACTIVITY' => [
  205. 'version' => 1,
  206. 'endpoints' => [
  207. 'list' => '/ocs/v2.php/cloud/activity',
  208. ],
  209. ],
  210. 'PROVISIONING' => [
  211. 'version' => 1,
  212. 'endpoints' => [
  213. 'user' => '/ocs/v2.php/cloud/users',
  214. 'groups' => '/ocs/v2.php/cloud/groups',
  215. 'apps' => '/ocs/v2.php/cloud/apps',
  216. ],
  217. ],
  218. ],
  219. ]
  220. );
  221. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  222. }
  223. }