provider.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. class OcsProviderTest extends \Test\TestCase {
  22. /** @var \OCP\IRequest */
  23. private $request;
  24. /** @var \OCP\App\IAppManager */
  25. private $appManager;
  26. /** @var Provider */
  27. private $ocsProvider;
  28. public function setUp() {
  29. parent::setUp();
  30. require_once '../ocs-provider/provider.php';
  31. $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock();
  32. $this->appManager = $this->getMockBuilder('\\OCP\\App\\IAppManager')->getMock();
  33. $this->ocsProvider = new Provider('ocs_provider', $this->request, $this->appManager);
  34. }
  35. public function testBuildProviderListWithoutAnythingEnabled() {
  36. $this->appManager
  37. ->expects($this->at(0))
  38. ->method('isEnabledForUser')
  39. ->with('files_sharing')
  40. ->will($this->returnValue(false));
  41. $this->appManager
  42. ->expects($this->at(1))
  43. ->method('isEnabledForUser')
  44. ->with('activity')
  45. ->will($this->returnValue(false));
  46. $this->appManager
  47. ->expects($this->at(2))
  48. ->method('isEnabledForUser')
  49. ->with('provisioning_api')
  50. ->will($this->returnValue(false));
  51. $expected = new \OCP\AppFramework\Http\JSONResponse(
  52. [
  53. 'version' => 2,
  54. 'services' => [
  55. 'PRIVATE_DATA' => [
  56. 'version' => 1,
  57. 'endpoints' => [
  58. 'store' => '/ocs/v2.php/privatedata/setattribute',
  59. 'read' => '/ocs/v2.php/privatedata/getattribute',
  60. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  61. ],
  62. ],
  63. ],
  64. ]
  65. );
  66. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  67. }
  68. public function testBuildProviderListWithSharingEnabled() {
  69. $this->appManager
  70. ->expects($this->at(0))
  71. ->method('isEnabledForUser')
  72. ->with('files_sharing')
  73. ->will($this->returnValue(true));
  74. $this->appManager
  75. ->expects($this->at(1))
  76. ->method('isEnabledForUser')
  77. ->with('activity')
  78. ->will($this->returnValue(false));
  79. $this->appManager
  80. ->expects($this->at(2))
  81. ->method('isEnabledForUser')
  82. ->with('provisioning_api')
  83. ->will($this->returnValue(false));
  84. $expected = new \OCP\AppFramework\Http\JSONResponse(
  85. [
  86. 'version' => 2,
  87. 'services' => [
  88. 'PRIVATE_DATA' => [
  89. 'version' => 1,
  90. 'endpoints' => [
  91. 'store' => '/ocs/v2.php/privatedata/setattribute',
  92. 'read' => '/ocs/v2.php/privatedata/getattribute',
  93. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  94. ],
  95. ],
  96. 'FEDERATED_SHARING' => [
  97. 'version' => 1,
  98. 'endpoints' => [
  99. 'share' => '/ocs/v2.php/cloud/shares',
  100. 'webdav' => '/public.php/webdav/',
  101. ],
  102. ],
  103. 'SHARING' => [
  104. 'version' => 1,
  105. 'endpoints' => [
  106. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  107. ],
  108. ],
  109. ],
  110. ]
  111. );
  112. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  113. }
  114. public function testBuildProviderListWithEverythingEnabled() {
  115. $this->appManager
  116. ->expects($this->any())
  117. ->method('isEnabledForUser')
  118. ->will($this->returnValue(true));
  119. $expected = new \OCP\AppFramework\Http\JSONResponse(
  120. [
  121. 'version' => 2,
  122. 'services' => [
  123. 'PRIVATE_DATA' => [
  124. 'version' => 1,
  125. 'endpoints' => [
  126. 'store' => '/ocs/v2.php/privatedata/setattribute',
  127. 'read' => '/ocs/v2.php/privatedata/getattribute',
  128. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  129. ],
  130. ],
  131. 'FEDERATED_SHARING' => [
  132. 'version' => 1,
  133. 'endpoints' => [
  134. 'share' => '/ocs/v2.php/cloud/shares',
  135. 'webdav' => '/public.php/webdav/',
  136. ],
  137. ],
  138. 'SHARING' => [
  139. 'version' => 1,
  140. 'endpoints' => [
  141. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  142. ],
  143. ],
  144. 'ACTIVITY' => [
  145. 'version' => 1,
  146. 'endpoints' => [
  147. 'list' => '/ocs/v2.php/cloud/activity',
  148. ],
  149. ],
  150. 'PROVISIONING' => [
  151. 'version' => 1,
  152. 'endpoints' => [
  153. 'user' => '/ocs/v2.php/cloud/users',
  154. 'groups' => '/ocs/v2.php/cloud/groups',
  155. 'apps' => '/ocs/v2.php/cloud/apps',
  156. ],
  157. ],
  158. ],
  159. ]
  160. );
  161. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  162. }
  163. }