1
0

SharingTest.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Settings\Admin;
  24. use OC\Settings\Admin\Sharing;
  25. use OCP\AppFramework\Http\TemplateResponse;
  26. use OCP\Constants;
  27. use OCP\IConfig;
  28. use OCP\IL10N;
  29. use OCP\Share\IManager;
  30. use Test\TestCase;
  31. class SharingTest extends TestCase {
  32. /** @var Sharing */
  33. private $admin;
  34. /** @var IConfig */
  35. private $config;
  36. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  37. private $l10n;
  38. /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
  39. private $shareManager;
  40. public function setUp() {
  41. parent::setUp();
  42. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  43. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  44. $this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
  45. $this->admin = new Sharing(
  46. $this->config,
  47. $this->l10n,
  48. $this->shareManager
  49. );
  50. }
  51. public function testGetFormWithoutExcludedGroups() {
  52. $this->config
  53. ->expects($this->at(0))
  54. ->method('getAppValue')
  55. ->with('core', 'shareapi_exclude_groups_list', '')
  56. ->willReturn('');
  57. $this->config
  58. ->expects($this->at(1))
  59. ->method('getAppValue')
  60. ->with('core', 'shareapi_allow_group_sharing', 'yes')
  61. ->willReturn('yes');
  62. $this->config
  63. ->expects($this->at(2))
  64. ->method('getAppValue')
  65. ->with('core', 'shareapi_allow_links', 'yes')
  66. ->willReturn('yes');
  67. $this->config
  68. ->expects($this->at(3))
  69. ->method('getAppValue')
  70. ->with('core', 'shareapi_allow_public_upload', 'yes')
  71. ->willReturn('yes');
  72. $this->config
  73. ->expects($this->at(4))
  74. ->method('getAppValue')
  75. ->with('core', 'shareapi_allow_resharing', 'yes')
  76. ->willReturn('yes');
  77. $this->config
  78. ->expects($this->at(5))
  79. ->method('getAppValue')
  80. ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
  81. ->willReturn('yes');
  82. $this->config
  83. ->expects($this->at(6))
  84. ->method('getAppValue')
  85. ->with('core', 'shareapi_enabled', 'yes')
  86. ->willReturn('yes');
  87. $this->config
  88. ->expects($this->at(7))
  89. ->method('getAppValue')
  90. ->with('core', 'shareapi_default_expire_date', 'no')
  91. ->willReturn('no');
  92. $this->config
  93. ->expects($this->at(8))
  94. ->method('getAppValue')
  95. ->with('core', 'shareapi_expire_after_n_days', '7')
  96. ->willReturn('7');
  97. $this->config
  98. ->expects($this->at(9))
  99. ->method('getAppValue')
  100. ->with('core', 'shareapi_enforce_expire_date', 'no')
  101. ->willReturn('no');
  102. $this->config
  103. ->expects($this->at(10))
  104. ->method('getAppValue')
  105. ->with('core', 'shareapi_exclude_groups', 'no')
  106. ->willReturn('no');
  107. $this->config
  108. ->expects($this->at(11))
  109. ->method('getAppValue')
  110. ->with('core', 'shareapi_public_link_disclaimertext', null)
  111. ->willReturn('Lorem ipsum');
  112. $this->config
  113. ->expects($this->at(12))
  114. ->method('getAppValue')
  115. ->with('core', 'shareapi_enable_link_password_by_default', 'no')
  116. ->willReturn('yes');
  117. $this->config
  118. ->expects($this->at(13))
  119. ->method('getAppValue')
  120. ->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
  121. ->willReturn(Constants::PERMISSION_ALL);
  122. $expected = new TemplateResponse(
  123. 'settings',
  124. 'settings/admin/sharing',
  125. [
  126. 'allowGroupSharing' => 'yes',
  127. 'allowLinks' => 'yes',
  128. 'allowPublicUpload' => 'yes',
  129. 'allowResharing' => 'yes',
  130. 'allowShareDialogUserEnumeration' => 'yes',
  131. 'enforceLinkPassword' => false,
  132. 'onlyShareWithGroupMembers' => false,
  133. 'shareAPIEnabled' => 'yes',
  134. 'shareDefaultExpireDateSet' => 'no',
  135. 'shareExpireAfterNDays' => '7',
  136. 'shareEnforceExpireDate' => 'no',
  137. 'shareExcludeGroups' => false,
  138. 'shareExcludedGroupsList' => '',
  139. 'publicShareDisclaimerText' => 'Lorem ipsum',
  140. 'enableLinkPasswordByDefault' => 'yes',
  141. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  142. 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
  143. ],
  144. ''
  145. );
  146. $this->assertEquals($expected, $this->admin->getForm());
  147. }
  148. public function testGetFormWithExcludedGroups() {
  149. $this->config
  150. ->expects($this->at(0))
  151. ->method('getAppValue')
  152. ->with('core', 'shareapi_exclude_groups_list', '')
  153. ->willReturn('["NoSharers","OtherNoSharers"]');
  154. $this->config
  155. ->expects($this->at(1))
  156. ->method('getAppValue')
  157. ->with('core', 'shareapi_allow_group_sharing', 'yes')
  158. ->willReturn('yes');
  159. $this->config
  160. ->expects($this->at(2))
  161. ->method('getAppValue')
  162. ->with('core', 'shareapi_allow_links', 'yes')
  163. ->willReturn('yes');
  164. $this->config
  165. ->expects($this->at(3))
  166. ->method('getAppValue')
  167. ->with('core', 'shareapi_allow_public_upload', 'yes')
  168. ->willReturn('yes');
  169. $this->config
  170. ->expects($this->at(4))
  171. ->method('getAppValue')
  172. ->with('core', 'shareapi_allow_resharing', 'yes')
  173. ->willReturn('yes');
  174. $this->config
  175. ->expects($this->at(5))
  176. ->method('getAppValue')
  177. ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
  178. ->willReturn('yes');
  179. $this->config
  180. ->expects($this->at(6))
  181. ->method('getAppValue')
  182. ->with('core', 'shareapi_enabled', 'yes')
  183. ->willReturn('yes');
  184. $this->config
  185. ->expects($this->at(7))
  186. ->method('getAppValue')
  187. ->with('core', 'shareapi_default_expire_date', 'no')
  188. ->willReturn('no');
  189. $this->config
  190. ->expects($this->at(8))
  191. ->method('getAppValue')
  192. ->with('core', 'shareapi_expire_after_n_days', '7')
  193. ->willReturn('7');
  194. $this->config
  195. ->expects($this->at(9))
  196. ->method('getAppValue')
  197. ->with('core', 'shareapi_enforce_expire_date', 'no')
  198. ->willReturn('no');
  199. $this->config
  200. ->expects($this->at(10))
  201. ->method('getAppValue')
  202. ->with('core', 'shareapi_exclude_groups', 'no')
  203. ->willReturn('yes');
  204. $this->config
  205. ->expects($this->at(11))
  206. ->method('getAppValue')
  207. ->with('core', 'shareapi_public_link_disclaimertext', null)
  208. ->willReturn('Lorem ipsum');
  209. $this->config
  210. ->expects($this->at(12))
  211. ->method('getAppValue')
  212. ->with('core', 'shareapi_enable_link_password_by_default', 'no')
  213. ->willReturn('yes');
  214. $this->config
  215. ->expects($this->at(13))
  216. ->method('getAppValue')
  217. ->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
  218. ->willReturn(Constants::PERMISSION_ALL);
  219. $expected = new TemplateResponse(
  220. 'settings',
  221. 'settings/admin/sharing',
  222. [
  223. 'allowGroupSharing' => 'yes',
  224. 'allowLinks' => 'yes',
  225. 'allowPublicUpload' => 'yes',
  226. 'allowResharing' => 'yes',
  227. 'allowShareDialogUserEnumeration' => 'yes',
  228. 'enforceLinkPassword' => false,
  229. 'onlyShareWithGroupMembers' => false,
  230. 'shareAPIEnabled' => 'yes',
  231. 'shareDefaultExpireDateSet' => 'no',
  232. 'shareExpireAfterNDays' => '7',
  233. 'shareEnforceExpireDate' => 'no',
  234. 'shareExcludeGroups' => true,
  235. 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
  236. 'publicShareDisclaimerText' => 'Lorem ipsum',
  237. 'enableLinkPasswordByDefault' => 'yes',
  238. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  239. 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
  240. ],
  241. ''
  242. );
  243. $this->assertEquals($expected, $this->admin->getForm());
  244. }
  245. public function testGetSection() {
  246. $this->assertSame('sharing', $this->admin->getSection());
  247. }
  248. public function testGetPriority() {
  249. $this->assertSame(0, $this->admin->getPriority());
  250. }
  251. }