You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
9.9 KiB

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