1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
<?php
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\GroupPluginManager;
use OCP\GroupInterface;
class GroupLDAPPluginTest extends \Test\TestCase {
/**
* @return GroupPluginManager
*/
private function getGroupPluginManager() {
return new GroupPluginManager();
}
public function testImplementsActions() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::CREATE_GROUP);
$plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions'])
->getMock();
$plugin2->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::ADD_TO_GROUP);
$pluginManager->register($plugin);
$pluginManager->register($plugin2);
$this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP);
$this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP));
$this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP));
}
public function testCreateGroup() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'createGroup'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::CREATE_GROUP);
$plugin->expects($this->once())
->method('createGroup')
->with(
$this->equalTo('group')
);
$pluginManager->register($plugin);
$pluginManager->createGroup('group');
}
public function testCreateGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->createGroup('foo');
}
public function testDeleteGroup() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'deleteGroup'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::DELETE_GROUP);
$plugin->expects($this->once())
->method('deleteGroup')
->with(
$this->equalTo('group')
)->willReturn(true);
$pluginManager->register($plugin);
$this->assertTrue($pluginManager->deleteGroup('group'));
}
public function testDeleteGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->deleteGroup('foo');
}
public function testAddToGroup() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'addToGroup'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::ADD_TO_GROUP);
$plugin->expects($this->once())
->method('addToGroup')
->with(
$this->equalTo('uid'),
$this->equalTo('gid')
);
$pluginManager->register($plugin);
$pluginManager->addToGroup('uid', 'gid');
}
public function testAddToGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->addToGroup('foo', 'bar');
}
public function testRemoveFromGroup() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'removeFromGroup'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::REMOVE_FROM_GROUP);
$plugin->expects($this->once())
->method('removeFromGroup')
->with(
$this->equalTo('uid'),
$this->equalTo('gid')
);
$pluginManager->register($plugin);
$pluginManager->removeFromGroup('uid', 'gid');
}
public function testRemoveFromGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->removeFromGroup('foo', 'bar');
}
public function testCountUsersInGroup() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'countUsersInGroup'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::COUNT_USERS);
$plugin->expects($this->once())
->method('countUsersInGroup')
->with(
$this->equalTo('gid'),
$this->equalTo('search')
);
$pluginManager->register($plugin);
$pluginManager->countUsersInGroup('gid', 'search');
}
public function testCountUsersInGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->countUsersInGroup('foo', 'bar');
}
public function testgetGroupDetails() {
$pluginManager = $this->getGroupPluginManager();
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
->setMethods(['respondToActions', 'getGroupDetails'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::GROUP_DETAILS);
$plugin->expects($this->once())
->method('getGroupDetails')
->with(
$this->equalTo('gid')
);
$pluginManager->register($plugin);
$pluginManager->getGroupDetails('gid');
}
public function testgetGroupDetailsNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.');
$pluginManager = $this->getGroupPluginManager();
$pluginManager->getGroupDetails('foo');
}
}
|