capabilities.php 6.07 KB
Newer Older
1
2
<?php
/**
Roeland Jago Douma's avatar
Roeland Jago Douma committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace OCA\Files_Sharing\Tests;

use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Tests\TestCase;

/**
 * Class FilesSharingCapabilitiesTest
 */
class FilesSharingCapabilitiesTest extends \Test\TestCase {

	/**
	 * Test for the general part in each return statement and assert.
	 * Strip of the general part on the way.
	 *
	 * @param string[] $data Capabilities
	 * @return string[]
	 */
Roeland Jago Douma's avatar
Roeland Jago Douma committed
38
	private function getFilesSharingPart(array $data) {
39
40
41
42
43
44
45
46
47
48
49
50
51
		$this->assertArrayHasKey('capabilities', $data);
		$this->assertArrayHasKey('files_sharing', $data['capabilities']);
		return $data['capabilities']['files_sharing'];
	}

	/**
	 * Create a mock config object and insert the values in $map tot the getAppValue
	 * function. Then obtain the capabilities and extract the first few
	 * levels in the array
	 *
	 * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
	 * @return string[]
	 */
Roeland Jago Douma's avatar
Roeland Jago Douma committed
52
	private function getResults(array $map) {
53
54
55
56
57
58
59
60
		$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
		$stub->method('getAppValue')->will($this->returnValueMap($map));
		$cap = new Capabilities($stub);
		$result = $this->getFilesSharingPart($cap->getCaps()->getData());
		return $result;
	}

	public function testNoLinkSharing() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
61
62
63
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'no'],
		];
64
		$result = $this->getResults($map);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
65
66
		$this->assertInternalType('array', $result['public']);
		$this->assertFalse($result['public']['enabled']);
67
68
69
	}

	public function testOnlyLinkSharing() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
70
71
72
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
		];
73
74
		$result = $this->getResults($map);
		$this->assertInternalType('array', $result['public']);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
75
		$this->assertTrue($result['public']['enabled']);
76
77
78
	}

	public function testLinkPassword() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
79
80
81
82
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_enforce_links_password', 'yes', 'yes'],
		];
83
		$result = $this->getResults($map);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
84
85
86
		$this->assertArrayHasKey('password', $result['public']);
		$this->assertArrayHasKey('enforced', $result['public']['password']);
		$this->assertTrue($result['public']['password']['enforced']);
87
88
89
	}

	public function testLinkNoPassword() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
90
91
92
93
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_enforce_links_password', 'yes', 'no'],
		];
94
		$result = $this->getResults($map);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
95
96
97
		$this->assertArrayHasKey('password', $result['public']);
		$this->assertArrayHasKey('enforced', $result['public']['password']);
		$this->assertFalse($result['public']['password']['enforced']);
98
99
100
	}

	public function testLinkNoExpireDate() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
101
102
103
104
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_default_expire_date', 'yes', 'no'],
		];
105
106
		$result = $this->getResults($map);
		$this->assertArrayHasKey('expire_date', $result['public']);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
107
108
		$this->assertInternalType('array', $result['public']['expire_date']);
		$this->assertFalse($result['public']['expire_date']['enabled']);
109
110
111
	}

	public function testLinkExpireDate() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
112
113
114
115
116
117
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_default_expire_date', 'yes', 'yes'],
			['core', 'shareapi_expire_after_n_days', '7', '7'],
			['core', 'shareapi_enforce_expire_date', 'yes', 'no'],
		];
118
119
120
		$result = $this->getResults($map);
		$this->assertArrayHasKey('expire_date', $result['public']);
		$this->assertInternalType('array', $result['public']['expire_date']);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
121
		$this->assertTrue($result['public']['expire_date']['enabled']);
122
		$this->assertArrayHasKey('days', $result['public']['expire_date']);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
123
		$this->assertFalse($result['public']['expire_date']['enforced']);
124
125
126
	}

	public function testLinkExpireDateEnforced() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
127
128
129
130
131
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_default_expire_date', 'yes', 'yes'],
			['core', 'shareapi_enforce_expire_date', 'yes', 'yes'],
		];
132
133
134
		$result = $this->getResults($map);
		$this->assertArrayHasKey('expire_date', $result['public']);
		$this->assertInternalType('array', $result['public']['expire_date']);
Roeland Jago Douma's avatar
Roeland Jago Douma committed
135
		$this->assertTrue($result['public']['expire_date']['enforced']);
136
137
138
	}

	public function testLinkSendMail() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
139
140
141
142
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_allow_public_notification', 'yes', 'yes'],
		];
143
144
145
146
147
		$result = $this->getResults($map);
		$this->assertTrue($result['public']['send_mail']);
	}

	public function testLinkNoSendMail() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
148
149
150
151
		$map = [
			['core', 'shareapi_allow_links', 'yes', 'yes'],
			['core', 'shareapi_allow_public_notification', 'yes', 'no'],
		];
152
153
154
155
156
		$result = $this->getResults($map);
		$this->assertFalse($result['public']['send_mail']);
	}

	public function testUserSendMail() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
157
158
159
		$map = [
			['core', 'shareapi_allow_mail_notification', 'yes', 'yes'],
		];
160
161
162
163
164
		$result = $this->getResults($map);
		$this->assertTrue($result['user']['send_mail']);
	}

	public function testUserNoSendMail() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
165
166
167
		$map = [
			['core', 'shareapi_allow_mail_notification', 'yes', 'no'],
		];
168
169
170
171
172
		$result = $this->getResults($map);
		$this->assertFalse($result['user']['send_mail']);
	}

	public function testResharing() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
173
174
175
		$map = [
			['core', 'shareapi_allow_resharing', 'yes', 'yes'],
		];
176
177
178
179
180
		$result = $this->getResults($map);
		$this->assertTrue($result['resharing']);
	}

	public function testNoResharing() {
Roeland Jago Douma's avatar
Roeland Jago Douma committed
181
182
183
		$map = [
			['core', 'shareapi_allow_resharing', 'yes', 'no'],
		];
184
185
186
187
		$result = $this->getResults($map);
		$this->assertFalse($result['resharing']);
	}
}