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.

279 lines
9.0 KiB

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