provider.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 'PRIVATE_DATA' => [
  55. 'version' => 1,
  56. 'endpoints' => [
  57. 'store' => '/ocs/v2.php/privatedata/setattribute',
  58. 'read' => '/ocs/v2.php/privatedata/getattribute',
  59. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  60. ],
  61. ],
  62. ]
  63. );
  64. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  65. }
  66. public function testBuildProviderListWithSharingEnabled() {
  67. $this->appManager
  68. ->expects($this->at(0))
  69. ->method('isEnabledForUser')
  70. ->with('files_sharing')
  71. ->will($this->returnValue(true));
  72. $this->appManager
  73. ->expects($this->at(1))
  74. ->method('isEnabledForUser')
  75. ->with('activity')
  76. ->will($this->returnValue(false));
  77. $this->appManager
  78. ->expects($this->at(2))
  79. ->method('isEnabledForUser')
  80. ->with('provisioning_api')
  81. ->will($this->returnValue(false));
  82. $expected = new \OCP\AppFramework\Http\JSONResponse(
  83. [
  84. 'version' => 2,
  85. 'PRIVATE_DATA' => [
  86. 'version' => 1,
  87. 'endpoints' => [
  88. 'store' => '/ocs/v2.php/privatedata/setattribute',
  89. 'read' => '/ocs/v2.php/privatedata/getattribute',
  90. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  91. ],
  92. ],
  93. 'FEDERATED_SHARING' => [
  94. 'version' => 1,
  95. 'endpoints' => [
  96. 'share' => '/ocs/v2.php/cloud/shares',
  97. 'webdav' => '/public.php/webdav/',
  98. ],
  99. ],
  100. 'SHARING' => [
  101. 'version' => 1,
  102. 'endpoints' => [
  103. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  104. ],
  105. ],
  106. ]
  107. );
  108. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  109. }
  110. public function testBuildProviderListWithEverythingEnabled() {
  111. $this->appManager
  112. ->expects($this->any())
  113. ->method('isEnabledForUser')
  114. ->will($this->returnValue(true));
  115. $expected = new \OCP\AppFramework\Http\JSONResponse(
  116. [
  117. 'version' => 2,
  118. 'PRIVATE_DATA' => [
  119. 'version' => 1,
  120. 'endpoints' => [
  121. 'store' => '/ocs/v2.php/privatedata/setattribute',
  122. 'read' => '/ocs/v2.php/privatedata/getattribute',
  123. 'delete' => '/ocs/v2.php/privatedata/deleteattribute',
  124. ],
  125. ],
  126. 'FEDERATED_SHARING' => [
  127. 'version' => 1,
  128. 'endpoints' => [
  129. 'share' => '/ocs/v2.php/cloud/shares',
  130. 'webdav' => '/public.php/webdav/',
  131. ],
  132. ],
  133. 'SHARING' => [
  134. 'version' => 1,
  135. 'endpoints' => [
  136. 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
  137. ],
  138. ],
  139. 'ACTIVITY' => [
  140. 'version' => 1,
  141. 'endpoints' => [
  142. 'list' => '/ocs/v2.php/cloud/activity',
  143. ],
  144. ],
  145. 'PROVISIONING' => [
  146. 'version' => 1,
  147. 'endpoints' => [
  148. 'user' => '/ocs/v2.php/cloud/users',
  149. 'groups' => '/ocs/v2.php/cloud/groups',
  150. 'apps' => '/ocs/v2.php/cloud/apps',
  151. ],
  152. ],
  153. ]
  154. );
  155. $this->assertEquals($expected, $this->ocsProvider->buildProviderList());
  156. }
  157. }