PermissionManagerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 89
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testIsEnabledForUserEnabledNoRestrictions() 0 12 1
A testIsEnabledForUserEnabledNotInGroup() 0 32 1
A testIsEnabledForUserEnabledInGroup() 0 27 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Lukas Reschke <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
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
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace Tests\Richdocuments;
23
24
use OCA\Richdocuments\PermissionManager;
25
use OCP\IConfig;
26
use OCP\IGroupManager;
27
use OCP\IUser;
28
use PHPUnit\Framework\MockObject\MockBuilder;
29
use PHPUnit\Framework\MockObject\MockObject;
30
use Test\TestCase;
31
32
class PermissionManagerTest extends TestCase {
33
	/** @var IConfig|MockObject */
34
	private $config;
35
	/** @var IGroupManager|MockObject */
36
	private $groupManager;
37
	/** @var PermissionManager */
38
	private $permissionManager;
39
40
	public function setUp(): void {
41
		parent::setUp();
42
		$this->config = $this->createMock(IConfig::class);
43
		$this->groupManager = $this->createMock(IGroupManager::class);
44
		$this->permissionManager = new PermissionManager($this->config, $this->groupManager);
45
	}
46
47
	public function testIsEnabledForUserEnabledNoRestrictions() {
48
		/** @var IUser|MockObject $user */
49
		$user = $this->createMock(IUser::class);
50
51
		$this->config
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
			->expects($this->once())
53
			->method('getAppValue')
54
			->with('richdocuments', 'use_groups', '')
55
			->willReturn('');
56
57
		$this->assertTrue($this->permissionManager->isEnabledForUser($user));
58
	}
59
60
	public function testIsEnabledForUserEnabledNotInGroup() {
61
		/** @var IUser|MockBuilder $user */
62
		$user = $this->createMock(IUser::class);
63
		$user
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IUser>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
			->expects($this->once())
65
			->method('getUID')
66
			->willReturn('TestUser');
67
68
		$this->config
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
			->expects($this->once())
70
			->method('getAppValue')
71
			->with('richdocuments', 'use_groups', '')
72
			->willReturn('Enabled1|Enabled2|Enabled3');
73
74
		$this->groupManager
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IGroupManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
			->expects($this->at(0))
76
			->method('isInGroup')
77
			->with('TestUser', 'Enabled1')
78
			->willReturn(false);
79
		$this->groupManager
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IGroupManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
			->expects($this->at(1))
81
			->method('isInGroup')
82
			->with('TestUser', 'Enabled2')
83
			->willReturn(false);
84
		$this->groupManager
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IGroupManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
			->expects($this->at(2))
86
			->method('isInGroup')
87
			->with('TestUser', 'Enabled3')
88
			->willReturn(false);
89
90
		$this->assertFalse($this->permissionManager->isEnabledForUser($user));
91
	}
92
93
	public function testIsEnabledForUserEnabledInGroup() {
94
		/** @var IUser|MockObject $user */
95
		$user = $this->createMock(IUser::class);
96
		$user
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IUser>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
			->expects($this->once())
98
			->method('getUID')
99
			->willReturn('TestUser');
100
101
		$this->config
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
			->expects($this->once())
103
			->method('getAppValue')
104
			->with('richdocuments', 'use_groups', '')
105
			->willReturn('Enabled1|Enabled2|Enabled3');
106
107
		$this->groupManager
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IGroupManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
			->expects($this->at(0))
109
			->method('isInGroup')
110
			->with('TestUser', 'Enabled1')
111
			->willReturn(false);
112
		$this->groupManager
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\IGroupManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
			->expects($this->at(1))
114
			->method('isInGroup')
115
			->with('TestUser', 'Enabled2')
116
			->willReturn(true);
117
118
		$this->assertTrue($this->permissionManager->isEnabledForUser($user));
119
	}
120
}
121