SharingTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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\IConfig;
  27. use Test\TestCase;
  28. class SharingTest extends TestCase {
  29. /** @var Sharing */
  30. private $admin;
  31. /** @var IConfig */
  32. private $config;
  33. public function setUp() {
  34. parent::setUp();
  35. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  36. $this->admin = new Sharing(
  37. $this->config
  38. );
  39. }
  40. public function testGetFormWithoutExcludedGroups() {
  41. $this->config
  42. ->expects($this->at(0))
  43. ->method('getAppValue')
  44. ->with('core', 'shareapi_exclude_groups_list', '')
  45. ->willReturn('');
  46. $this->config
  47. ->expects($this->at(1))
  48. ->method('getAppValue')
  49. ->with('core', 'shareapi_allow_group_sharing', 'yes')
  50. ->willReturn('yes');
  51. $this->config
  52. ->expects($this->at(2))
  53. ->method('getAppValue')
  54. ->with('core', 'shareapi_allow_links', 'yes')
  55. ->willReturn('yes');
  56. $this->config
  57. ->expects($this->at(3))
  58. ->method('getAppValue')
  59. ->with('core', 'shareapi_allow_public_upload', 'yes')
  60. ->willReturn('yes');
  61. $this->config
  62. ->expects($this->at(4))
  63. ->method('getAppValue')
  64. ->with('core', 'shareapi_allow_resharing', 'yes')
  65. ->willReturn('yes');
  66. $this->config
  67. ->expects($this->at(5))
  68. ->method('getAppValue')
  69. ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
  70. ->willReturn('yes');
  71. $this->config
  72. ->expects($this->at(6))
  73. ->method('getAppValue')
  74. ->with('core', 'shareapi_enabled', 'yes')
  75. ->willReturn('yes');
  76. $this->config
  77. ->expects($this->at(7))
  78. ->method('getAppValue')
  79. ->with('core', 'shareapi_default_expire_date', 'no')
  80. ->willReturn('no');
  81. $this->config
  82. ->expects($this->at(8))
  83. ->method('getAppValue')
  84. ->with('core', 'shareapi_expire_after_n_days', '7')
  85. ->willReturn('7');
  86. $this->config
  87. ->expects($this->at(9))
  88. ->method('getAppValue')
  89. ->with('core', 'shareapi_enforce_expire_date', 'no')
  90. ->willReturn('no');
  91. $this->config
  92. ->expects($this->at(10))
  93. ->method('getAppValue')
  94. ->with('core', 'shareapi_exclude_groups', 'no')
  95. ->willReturn('no');
  96. $this->config
  97. ->expects($this->at(11))
  98. ->method('getAppValue')
  99. ->with('core', 'shareapi_public_link_disclaimertext', null)
  100. ->willReturn('Lorem ipsum');
  101. $this->config
  102. ->expects($this->at(12))
  103. ->method('getAppValue')
  104. ->with('core', 'shareapi_enable_link_password_by_default', 'no')
  105. ->willReturn('yes');
  106. $expected = new TemplateResponse(
  107. 'settings',
  108. 'settings/admin/sharing',
  109. [
  110. 'allowGroupSharing' => 'yes',
  111. 'allowLinks' => 'yes',
  112. 'allowPublicUpload' => 'yes',
  113. 'allowResharing' => 'yes',
  114. 'allowShareDialogUserEnumeration' => 'yes',
  115. 'enforceLinkPassword' => false,
  116. 'onlyShareWithGroupMembers' => false,
  117. 'shareAPIEnabled' => 'yes',
  118. 'shareDefaultExpireDateSet' => 'no',
  119. 'shareExpireAfterNDays' => '7',
  120. 'shareEnforceExpireDate' => 'no',
  121. 'shareExcludeGroups' => false,
  122. 'shareExcludedGroupsList' => '',
  123. 'publicShareDisclaimerText' => 'Lorem ipsum',
  124. 'enableLinkPasswordByDefault' => 'yes'
  125. ],
  126. ''
  127. );
  128. $this->assertEquals($expected, $this->admin->getForm());
  129. }
  130. public function testGetFormWithExcludedGroups() {
  131. $this->config
  132. ->expects($this->at(0))
  133. ->method('getAppValue')
  134. ->with('core', 'shareapi_exclude_groups_list', '')
  135. ->willReturn('["NoSharers","OtherNoSharers"]');
  136. $this->config
  137. ->expects($this->at(1))
  138. ->method('getAppValue')
  139. ->with('core', 'shareapi_allow_group_sharing', 'yes')
  140. ->willReturn('yes');
  141. $this->config
  142. ->expects($this->at(2))
  143. ->method('getAppValue')
  144. ->with('core', 'shareapi_allow_links', 'yes')
  145. ->willReturn('yes');
  146. $this->config
  147. ->expects($this->at(3))
  148. ->method('getAppValue')
  149. ->with('core', 'shareapi_allow_public_upload', 'yes')
  150. ->willReturn('yes');
  151. $this->config
  152. ->expects($this->at(4))
  153. ->method('getAppValue')
  154. ->with('core', 'shareapi_allow_resharing', 'yes')
  155. ->willReturn('yes');
  156. $this->config
  157. ->expects($this->at(5))
  158. ->method('getAppValue')
  159. ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
  160. ->willReturn('yes');
  161. $this->config
  162. ->expects($this->at(6))
  163. ->method('getAppValue')
  164. ->with('core', 'shareapi_enabled', 'yes')
  165. ->willReturn('yes');
  166. $this->config
  167. ->expects($this->at(7))
  168. ->method('getAppValue')
  169. ->with('core', 'shareapi_default_expire_date', 'no')
  170. ->willReturn('no');
  171. $this->config
  172. ->expects($this->at(8))
  173. ->method('getAppValue')
  174. ->with('core', 'shareapi_expire_after_n_days', '7')
  175. ->willReturn('7');
  176. $this->config
  177. ->expects($this->at(9))
  178. ->method('getAppValue')
  179. ->with('core', 'shareapi_enforce_expire_date', 'no')
  180. ->willReturn('no');
  181. $this->config
  182. ->expects($this->at(10))
  183. ->method('getAppValue')
  184. ->with('core', 'shareapi_exclude_groups', 'no')
  185. ->willReturn('yes');
  186. $this->config
  187. ->expects($this->at(11))
  188. ->method('getAppValue')
  189. ->with('core', 'shareapi_public_link_disclaimertext', null)
  190. ->willReturn('Lorem ipsum');
  191. $this->config
  192. ->expects($this->at(12))
  193. ->method('getAppValue')
  194. ->with('core', 'shareapi_enable_link_password_by_default', 'no')
  195. ->willReturn('yes');
  196. $expected = new TemplateResponse(
  197. 'settings',
  198. 'settings/admin/sharing',
  199. [
  200. 'allowGroupSharing' => 'yes',
  201. 'allowLinks' => 'yes',
  202. 'allowPublicUpload' => 'yes',
  203. 'allowResharing' => 'yes',
  204. 'allowShareDialogUserEnumeration' => 'yes',
  205. 'enforceLinkPassword' => false,
  206. 'onlyShareWithGroupMembers' => false,
  207. 'shareAPIEnabled' => 'yes',
  208. 'shareDefaultExpireDateSet' => 'no',
  209. 'shareExpireAfterNDays' => '7',
  210. 'shareEnforceExpireDate' => 'no',
  211. 'shareExcludeGroups' => true,
  212. 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
  213. 'publicShareDisclaimerText' => 'Lorem ipsum',
  214. 'enableLinkPasswordByDefault' => 'yes'
  215. ],
  216. ''
  217. );
  218. $this->assertEquals($expected, $this->admin->getForm());
  219. }
  220. public function testGetSection() {
  221. $this->assertSame('sharing', $this->admin->getSection());
  222. }
  223. public function testGetPriority() {
  224. $this->assertSame(0, $this->admin->getPriority());
  225. }
  226. }