|
| 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 | + |
| 23 | +use OCA\Files_Sharing\Capabilities; |
| 24 | +use OCA\Files_Sharing\Tests\TestCase; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class FilesSharingCapabilitiesTest |
| 28 | + */ |
| 29 | +class FilesSharingCapabilitiesTest extends \Test\TestCase { |
| 30 | + |
| 31 | + /** |
| 32 | + * Test for the general part in each return statement and assert. |
| 33 | + * Strip of the general part on the way. |
| 34 | + * |
| 35 | + * @param string[] $data Capabilities |
| 36 | + * @return string[] |
| 37 | + */ |
| 38 | + private function getFilesSharingPart(array $data) { |
| 39 | + $this->assertArrayHasKey('capabilities', $data); |
| 40 | + $this->assertArrayHasKey('files_sharing', $data['capabilities']); |
| 41 | + return $data['capabilities']['files_sharing']; |
| 42 | + } |
| 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->getCaps()->getData()); |
| 57 | + return $result; |
| 58 | + } |
| 59 | + |
| 60 | + public function testNoLinkSharing() { |
| 61 | + $map = [ |
| 62 | + ['core', 'shareapi_allow_links', 'yes', 'no'], |
| 63 | + ]; |
| 64 | + $result = $this->getResults($map); |
| 65 | + $this->assertInternalType('array', $result['public']); |
| 66 | + $this->assertFalse($result['public']['enabled']); |
| 67 | + } |
| 68 | + |
| 69 | + public function testOnlyLinkSharing() { |
| 70 | + $map = [ |
| 71 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 72 | + ]; |
| 73 | + $result = $this->getResults($map); |
| 74 | + $this->assertInternalType('array', $result['public']); |
| 75 | + $this->assertTrue($result['public']['enabled']); |
| 76 | + } |
| 77 | + |
| 78 | + public function testLinkPassword() { |
| 79 | + $map = [ |
| 80 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 81 | + ['core', 'shareapi_enforce_links_password', 'yes', 'yes'], |
| 82 | + ]; |
| 83 | + $result = $this->getResults($map); |
| 84 | + $this->assertArrayHasKey('password', $result['public']); |
| 85 | + $this->assertArrayHasKey('enforced', $result['public']['password']); |
| 86 | + $this->assertTrue($result['public']['password']['enforced']); |
| 87 | + } |
| 88 | + |
| 89 | + public function testLinkNoPassword() { |
| 90 | + $map = [ |
| 91 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 92 | + ['core', 'shareapi_enforce_links_password', 'yes', 'no'], |
| 93 | + ]; |
| 94 | + $result = $this->getResults($map); |
| 95 | + $this->assertArrayHasKey('password', $result['public']); |
| 96 | + $this->assertArrayHasKey('enforced', $result['public']['password']); |
| 97 | + $this->assertFalse($result['public']['password']['enforced']); |
| 98 | + } |
| 99 | + |
| 100 | + public function testLinkNoExpireDate() { |
| 101 | + $map = [ |
| 102 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 103 | + ['core', 'shareapi_default_expire_date', 'yes', 'no'], |
| 104 | + ]; |
| 105 | + $result = $this->getResults($map); |
| 106 | + $this->assertArrayHasKey('expire_date', $result['public']); |
| 107 | + $this->assertInternalType('array', $result['public']['expire_date']); |
| 108 | + $this->assertFalse($result['public']['expire_date']['enabled']); |
| 109 | + } |
| 110 | + |
| 111 | + public function testLinkExpireDate() { |
| 112 | + $map = [ |
| 113 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 114 | + ['core', 'shareapi_default_expire_date', 'yes', 'yes'], |
| 115 | + ['core', 'shareapi_expire_after_n_days', '7', '7'], |
| 116 | + ['core', 'shareapi_enforce_expire_date', 'yes', 'no'], |
| 117 | + ]; |
| 118 | + $result = $this->getResults($map); |
| 119 | + $this->assertArrayHasKey('expire_date', $result['public']); |
| 120 | + $this->assertInternalType('array', $result['public']['expire_date']); |
| 121 | + $this->assertTrue($result['public']['expire_date']['enabled']); |
| 122 | + $this->assertArrayHasKey('days', $result['public']['expire_date']); |
| 123 | + $this->assertFalse($result['public']['expire_date']['enforced']); |
| 124 | + } |
| 125 | + |
| 126 | + public function testLinkExpireDateEnforced() { |
| 127 | + $map = [ |
| 128 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 129 | + ['core', 'shareapi_default_expire_date', 'yes', 'yes'], |
| 130 | + ['core', 'shareapi_enforce_expire_date', 'yes', 'yes'], |
| 131 | + ]; |
| 132 | + $result = $this->getResults($map); |
| 133 | + $this->assertArrayHasKey('expire_date', $result['public']); |
| 134 | + $this->assertInternalType('array', $result['public']['expire_date']); |
| 135 | + $this->assertTrue($result['public']['expire_date']['enforced']); |
| 136 | + } |
| 137 | + |
| 138 | + public function testLinkSendMail() { |
| 139 | + $map = [ |
| 140 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 141 | + ['core', 'shareapi_allow_public_notification', 'yes', 'yes'], |
| 142 | + ]; |
| 143 | + $result = $this->getResults($map); |
| 144 | + $this->assertTrue($result['public']['send_mail']); |
| 145 | + } |
| 146 | + |
| 147 | + public function testLinkNoSendMail() { |
| 148 | + $map = [ |
| 149 | + ['core', 'shareapi_allow_links', 'yes', 'yes'], |
| 150 | + ['core', 'shareapi_allow_public_notification', 'yes', 'no'], |
| 151 | + ]; |
| 152 | + $result = $this->getResults($map); |
| 153 | + $this->assertFalse($result['public']['send_mail']); |
| 154 | + } |
| 155 | + |
| 156 | + public function testUserSendMail() { |
| 157 | + $map = [ |
| 158 | + ['core', 'shareapi_allow_mail_notification', 'yes', 'yes'], |
| 159 | + ]; |
| 160 | + $result = $this->getResults($map); |
| 161 | + $this->assertTrue($result['user']['send_mail']); |
| 162 | + } |
| 163 | + |
| 164 | + public function testUserNoSendMail() { |
| 165 | + $map = [ |
| 166 | + ['core', 'shareapi_allow_mail_notification', 'yes', 'no'], |
| 167 | + ]; |
| 168 | + $result = $this->getResults($map); |
| 169 | + $this->assertFalse($result['user']['send_mail']); |
| 170 | + } |
| 171 | + |
| 172 | + public function testResharing() { |
| 173 | + $map = [ |
| 174 | + ['core', 'shareapi_allow_resharing', 'yes', 'yes'], |
| 175 | + ]; |
| 176 | + $result = $this->getResults($map); |
| 177 | + $this->assertTrue($result['resharing']); |
| 178 | + } |
| 179 | + |
| 180 | + public function testNoResharing() { |
| 181 | + $map = [ |
| 182 | + ['core', 'shareapi_allow_resharing', 'yes', 'no'], |
| 183 | + ]; |
| 184 | + $result = $this->getResults($map); |
| 185 | + $this->assertFalse($result['resharing']); |
| 186 | + } |
| 187 | +} |
0 commit comments