CapabilitiesTest.php 9.2 KB

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