capabilities.php 6.5 KB

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