SharingTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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('\OCP\IConfig')->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. $expected = new TemplateResponse(
  102. 'settings',
  103. 'admin/sharing',
  104. [
  105. 'allowGroupSharing' => 'yes',
  106. 'allowLinks' => 'yes',
  107. 'allowPublicUpload' => 'yes',
  108. 'allowResharing' => 'yes',
  109. 'allowShareDialogUserEnumeration' => 'yes',
  110. 'enforceLinkPassword' => false,
  111. 'onlyShareWithGroupMembers' => false,
  112. 'shareAPIEnabled' => 'yes',
  113. 'shareDefaultExpireDateSet' => 'no',
  114. 'shareExpireAfterNDays' => '7',
  115. 'shareEnforceExpireDate' => 'no',
  116. 'shareExcludeGroups' => false,
  117. 'shareExcludedGroupsList' => '',
  118. 'publicShareDisclaimerText' => 'Lorem ipsum',
  119. ],
  120. ''
  121. );
  122. $this->assertEquals($expected, $this->admin->getForm());
  123. }
  124. public function testGetFormWithExcludedGroups() {
  125. $this->config
  126. ->expects($this->at(0))
  127. ->method('getAppValue')
  128. ->with('core', 'shareapi_exclude_groups_list', '')
  129. ->willReturn('["NoSharers","OtherNoSharers"]');
  130. $this->config
  131. ->expects($this->at(1))
  132. ->method('getAppValue')
  133. ->with('core', 'shareapi_allow_group_sharing', 'yes')
  134. ->willReturn('yes');
  135. $this->config
  136. ->expects($this->at(2))
  137. ->method('getAppValue')
  138. ->with('core', 'shareapi_allow_links', 'yes')
  139. ->willReturn('yes');
  140. $this->config
  141. ->expects($this->at(3))
  142. ->method('getAppValue')
  143. ->with('core', 'shareapi_allow_public_upload', 'yes')
  144. ->willReturn('yes');
  145. $this->config
  146. ->expects($this->at(4))
  147. ->method('getAppValue')
  148. ->with('core', 'shareapi_allow_resharing', 'yes')
  149. ->willReturn('yes');
  150. $this->config
  151. ->expects($this->at(5))
  152. ->method('getAppValue')
  153. ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
  154. ->willReturn('yes');
  155. $this->config
  156. ->expects($this->at(6))
  157. ->method('getAppValue')
  158. ->with('core', 'shareapi_enabled', 'yes')
  159. ->willReturn('yes');
  160. $this->config
  161. ->expects($this->at(7))
  162. ->method('getAppValue')
  163. ->with('core', 'shareapi_default_expire_date', 'no')
  164. ->willReturn('no');
  165. $this->config
  166. ->expects($this->at(8))
  167. ->method('getAppValue')
  168. ->with('core', 'shareapi_expire_after_n_days', '7')
  169. ->willReturn('7');
  170. $this->config
  171. ->expects($this->at(9))
  172. ->method('getAppValue')
  173. ->with('core', 'shareapi_enforce_expire_date', 'no')
  174. ->willReturn('no');
  175. $this->config
  176. ->expects($this->at(10))
  177. ->method('getAppValue')
  178. ->with('core', 'shareapi_exclude_groups', 'no')
  179. ->willReturn('yes');
  180. $this->config
  181. ->expects($this->at(11))
  182. ->method('getAppValue')
  183. ->with('core', 'shareapi_public_link_disclaimertext', null)
  184. ->willReturn('Lorem ipsum');
  185. $expected = new TemplateResponse(
  186. 'settings',
  187. 'admin/sharing',
  188. [
  189. 'allowGroupSharing' => 'yes',
  190. 'allowLinks' => 'yes',
  191. 'allowPublicUpload' => 'yes',
  192. 'allowResharing' => 'yes',
  193. 'allowShareDialogUserEnumeration' => 'yes',
  194. 'enforceLinkPassword' => false,
  195. 'onlyShareWithGroupMembers' => false,
  196. 'shareAPIEnabled' => 'yes',
  197. 'shareDefaultExpireDateSet' => 'no',
  198. 'shareExpireAfterNDays' => '7',
  199. 'shareEnforceExpireDate' => 'no',
  200. 'shareExcludeGroups' => true,
  201. 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
  202. 'publicShareDisclaimerText' => 'Lorem ipsum',
  203. ],
  204. ''
  205. );
  206. $this->assertEquals($expected, $this->admin->getForm());
  207. }
  208. public function testGetSection() {
  209. $this->assertSame('sharing', $this->admin->getSection());
  210. }
  211. public function testGetPriority() {
  212. $this->assertSame(0, $this->admin->getPriority());
  213. }
  214. }