1
0

CapabilitiesTest.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_Sharing\Tests;
  28. use OCA\Files_Sharing\Capabilities;
  29. use OCP\IConfig;
  30. /**
  31. * Class CapabilitiesTest
  32. *
  33. * @group DB
  34. */
  35. class CapabilitiesTest extends \Test\TestCase {
  36. /**
  37. * Test for the general part in each return statement and assert.
  38. * Strip of the general part on the way.
  39. *
  40. * @param string[] $data Capabilities
  41. * @return string[]
  42. */
  43. private function getFilesSharingPart(array $data) {
  44. $this->assertArrayHasKey('files_sharing', $data);
  45. return $data['files_sharing'];
  46. }
  47. /**
  48. * Create a mock config object and insert the values in $map to the getAppValue
  49. * function. Then obtain the capabilities and extract the first few
  50. * levels in the array
  51. *
  52. * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
  53. * @return string[]
  54. */
  55. private function getResults(array $map) {
  56. $config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
  57. $config->method('getAppValue')->willReturnMap($map);
  58. $cap = new Capabilities($config);
  59. $result = $this->getFilesSharingPart($cap->getCapabilities());
  60. return $result;
  61. }
  62. public function testEnabledSharingAPI() {
  63. $map = [
  64. ['core', 'shareapi_enabled', 'yes', 'yes'],
  65. ];
  66. $result = $this->getResults($map);
  67. $this->assertTrue($result['api_enabled']);
  68. $this->assertArrayHasKey('public', $result);
  69. $this->assertArrayHasKey('user', $result);
  70. $this->assertArrayHasKey('resharing', $result);
  71. }
  72. public function testDisabledSharingAPI() {
  73. $map = [
  74. ['core', 'shareapi_enabled', 'yes', 'no'],
  75. ];
  76. $result = $this->getResults($map);
  77. $this->assertFalse($result['api_enabled']);
  78. $this->assertFalse($result['public']['enabled']);
  79. $this->assertFalse($result['user']['send_mail']);
  80. $this->assertFalse($result['resharing']);
  81. }
  82. public function testNoLinkSharing() {
  83. $map = [
  84. ['core', 'shareapi_enabled', 'yes', 'yes'],
  85. ['core', 'shareapi_allow_links', 'yes', 'no'],
  86. ];
  87. $result = $this->getResults($map);
  88. $this->assertIsArray($result['public']);
  89. $this->assertFalse($result['public']['enabled']);
  90. }
  91. public function testOnlyLinkSharing() {
  92. $map = [
  93. ['core', 'shareapi_enabled', 'yes', 'yes'],
  94. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  95. ];
  96. $result = $this->getResults($map);
  97. $this->assertIsArray($result['public']);
  98. $this->assertTrue($result['public']['enabled']);
  99. }
  100. public function testLinkPassword() {
  101. $map = [
  102. ['core', 'shareapi_enabled', 'yes', 'yes'],
  103. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  104. ['core', 'shareapi_enforce_links_password', 'no', 'yes'],
  105. ];
  106. $result = $this->getResults($map);
  107. $this->assertArrayHasKey('password', $result['public']);
  108. $this->assertArrayHasKey('enforced', $result['public']['password']);
  109. $this->assertTrue($result['public']['password']['enforced']);
  110. }
  111. public function testLinkNoPassword() {
  112. $map = [
  113. ['core', 'shareapi_enabled', 'yes', 'yes'],
  114. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  115. ['core', 'shareapi_enforce_links_password', 'no', 'no'],
  116. ];
  117. $result = $this->getResults($map);
  118. $this->assertArrayHasKey('password', $result['public']);
  119. $this->assertArrayHasKey('enforced', $result['public']['password']);
  120. $this->assertFalse($result['public']['password']['enforced']);
  121. }
  122. public function testLinkNoExpireDate() {
  123. $map = [
  124. ['core', 'shareapi_enabled', 'yes', 'yes'],
  125. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  126. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  127. ];
  128. $result = $this->getResults($map);
  129. $this->assertArrayHasKey('expire_date', $result['public']);
  130. $this->assertIsArray($result['public']['expire_date']);
  131. $this->assertFalse($result['public']['expire_date']['enabled']);
  132. }
  133. public function testLinkExpireDate() {
  134. $map = [
  135. ['core', 'shareapi_enabled', 'yes', 'yes'],
  136. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  137. ['core', 'shareapi_default_expire_date', 'no', 'yes'],
  138. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  139. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  140. ];
  141. $result = $this->getResults($map);
  142. $this->assertArrayHasKey('expire_date', $result['public']);
  143. $this->assertIsArray($result['public']['expire_date']);
  144. $this->assertTrue($result['public']['expire_date']['enabled']);
  145. $this->assertArrayHasKey('days', $result['public']['expire_date']);
  146. $this->assertFalse($result['public']['expire_date']['enforced']);
  147. }
  148. public function testLinkExpireDateEnforced() {
  149. $map = [
  150. ['core', 'shareapi_enabled', 'yes', 'yes'],
  151. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  152. ['core', 'shareapi_default_expire_date', 'no', 'yes'],
  153. ['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
  154. ];
  155. $result = $this->getResults($map);
  156. $this->assertArrayHasKey('expire_date', $result['public']);
  157. $this->assertIsArray($result['public']['expire_date']);
  158. $this->assertTrue($result['public']['expire_date']['enforced']);
  159. }
  160. public function testLinkSendMail() {
  161. $map = [
  162. ['core', 'shareapi_enabled', 'yes', 'yes'],
  163. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  164. ['core', 'shareapi_allow_public_notification', 'no', 'yes'],
  165. ];
  166. $result = $this->getResults($map);
  167. $this->assertTrue($result['public']['send_mail']);
  168. }
  169. public function testLinkNoSendMail() {
  170. $map = [
  171. ['core', 'shareapi_enabled', 'yes', 'yes'],
  172. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  173. ['core', 'shareapi_allow_public_notification', 'no', 'no'],
  174. ];
  175. $result = $this->getResults($map);
  176. $this->assertFalse($result['public']['send_mail']);
  177. }
  178. public function testResharing() {
  179. $map = [
  180. ['core', 'shareapi_enabled', 'yes', 'yes'],
  181. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  182. ];
  183. $result = $this->getResults($map);
  184. $this->assertTrue($result['resharing']);
  185. }
  186. public function testNoResharing() {
  187. $map = [
  188. ['core', 'shareapi_enabled', 'yes', 'yes'],
  189. ['core', 'shareapi_allow_resharing', 'yes', 'no'],
  190. ];
  191. $result = $this->getResults($map);
  192. $this->assertFalse($result['resharing']);
  193. }
  194. public function testLinkPublicUpload() {
  195. $map = [
  196. ['core', 'shareapi_enabled', 'yes', 'yes'],
  197. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  198. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  199. ];
  200. $result = $this->getResults($map);
  201. $this->assertTrue($result['public']['upload']);
  202. $this->assertTrue($result['public']['upload_files_drop']);
  203. }
  204. public function testLinkNoPublicUpload() {
  205. $map = [
  206. ['core', 'shareapi_enabled', 'yes', 'yes'],
  207. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  208. ['core', 'shareapi_allow_public_upload', 'yes', 'no'],
  209. ];
  210. $result = $this->getResults($map);
  211. $this->assertFalse($result['public']['upload']);
  212. $this->assertFalse($result['public']['upload_files_drop']);
  213. }
  214. public function testNoGroupSharing() {
  215. $map = [
  216. ['core', 'shareapi_enabled', 'yes', 'yes'],
  217. ['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
  218. ];
  219. $result = $this->getResults($map);
  220. $this->assertFalse($result['group_sharing']);
  221. }
  222. public function testGroupSharing() {
  223. $map = [
  224. ['core', 'shareapi_enabled', 'yes', 'yes'],
  225. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  226. ];
  227. $result = $this->getResults($map);
  228. $this->assertTrue($result['group_sharing']);
  229. }
  230. public function testFederatedSharingIncoming() {
  231. $map = [
  232. ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
  233. ];
  234. $result = $this->getResults($map);
  235. $this->assertArrayHasKey('federation', $result);
  236. $this->assertTrue($result['federation']['incoming']);
  237. }
  238. public function testFederatedSharingNoIncoming() {
  239. $map = [
  240. ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
  241. ];
  242. $result = $this->getResults($map);
  243. $this->assertArrayHasKey('federation', $result);
  244. $this->assertFalse($result['federation']['incoming']);
  245. }
  246. public function testFederatedSharingOutgoing() {
  247. $map = [
  248. ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'yes'],
  249. ];
  250. $result = $this->getResults($map);
  251. $this->assertArrayHasKey('federation', $result);
  252. $this->assertTrue($result['federation']['outgoing']);
  253. }
  254. public function testFederatedSharingNoOutgoing() {
  255. $map = [
  256. ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
  257. ];
  258. $result = $this->getResults($map);
  259. $this->assertArrayHasKey('federation', $result);
  260. $this->assertFalse($result['federation']['outgoing']);
  261. }
  262. }