|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Enalean, 2016. All Rights Reserved. |
|
4
|
|
|
* Copyright (c) STMicroelectronics, 2012. All Rights Reserved. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is a part of Tuleap. |
|
7
|
|
|
* |
|
8
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
require_once('common/system_event/include/SystemEvent_UGROUP_MODIFY.class.php'); |
|
23
|
|
|
require_once('common/backend/BackendSystem.class.php'); |
|
24
|
|
|
Mock::generatePartial('SystemEvent_UGROUP_MODIFY', |
|
25
|
|
|
'SystemEvent_UGROUP_MODIFY_TestVersion', |
|
26
|
|
|
array('getProject', |
|
27
|
|
|
'getBackend', |
|
28
|
|
|
'done', |
|
29
|
|
|
'processUgroupBinding', |
|
30
|
|
|
'error', |
|
31
|
|
|
'getEventManager', |
|
32
|
|
|
'getParametersAsArray')); |
|
33
|
|
|
Mock::generatePartial( |
|
34
|
|
|
'SystemEvent_UGROUP_MODIFY', |
|
35
|
|
|
'SystemEvent_UGROUP_MODIFY_TestUGroupVersion', |
|
36
|
|
|
array( |
|
37
|
|
|
'getProject', |
|
38
|
|
|
'getBackend', |
|
39
|
|
|
'done', |
|
40
|
|
|
'getUgroupBinding', |
|
41
|
|
|
'error', |
|
42
|
|
|
'getParametersAsArray' |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
Mock::generate('BackendSystem'); |
|
47
|
|
|
Mock::generate('Project'); |
|
48
|
|
|
Mock::generate('BackendSVN'); |
|
49
|
|
|
Mock::generate('UGroupBinding'); |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test for project delete system event |
|
53
|
|
|
*/ |
|
54
|
|
|
class SystemEvent_UGROUP_MODIFY_Test extends TuleapTestCase { |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* ProjectUGroup modify Users fail |
|
58
|
|
|
* |
|
59
|
|
|
* @return Void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testUgroupModifyProcessUgroupModifyFail() { |
|
62
|
|
|
$evt = new SystemEvent_UGROUP_MODIFY_TestVersion(); |
|
63
|
|
|
$evt->__construct('1', SystemEvent::TYPE_UGROUP_MODIFY, SystemEvent::OWNER_ROOT, '1', SystemEvent::PRIORITY_HIGH, SystemEvent::STATUS_RUNNING, $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], ''); |
|
64
|
|
|
$evt->setReturnValue('getParametersAsArray', array(1, 2)); |
|
65
|
|
|
|
|
66
|
|
|
$evt->setReturnValue('processUgroupBinding', false); |
|
67
|
|
|
|
|
68
|
|
|
$project = new MockProject(); |
|
69
|
|
|
$project->setReturnValue('usesSVN', true); |
|
70
|
|
|
$evt->setReturnValue('getProject', $project, array('1')); |
|
71
|
|
|
|
|
72
|
|
|
$backendSVN = new MockBackendSVN(); |
|
73
|
|
|
$backendSVN->expectNever('updateSVNAccess'); |
|
74
|
|
|
$evt->setReturnValue('getBackend', $backendSVN, array('SVN')); |
|
75
|
|
|
|
|
76
|
|
|
$evt->expectNever('getProject'); |
|
77
|
|
|
$evt->expectNever('getBackend'); |
|
78
|
|
|
$evt->expectNever('done'); |
|
79
|
|
|
$evt->expectOnce('error', array("Could not process binding to this user group (2)")); |
|
80
|
|
|
|
|
81
|
|
|
// Launch the event |
|
82
|
|
|
$this->assertFalse($evt->process()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* ProjectUGroup modify SVN fail |
|
87
|
|
|
* |
|
88
|
|
|
* @return Void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function testUgroupModifyProcessSVNFail() { |
|
91
|
|
|
$evt = new SystemEvent_UGROUP_MODIFY_TestVersion(); |
|
92
|
|
|
$evt->__construct('1', SystemEvent::TYPE_UGROUP_MODIFY, SystemEvent::OWNER_ROOT, '1', SystemEvent::PRIORITY_HIGH, SystemEvent::STATUS_RUNNING, $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], ''); |
|
93
|
|
|
$evt->setReturnValue('getParametersAsArray', array(1, 2)); |
|
94
|
|
|
|
|
95
|
|
|
$evt->setReturnValue('processUgroupBinding', true); |
|
96
|
|
|
|
|
97
|
|
|
$project = new MockProject(); |
|
98
|
|
|
$project->setReturnValue('usesSVN', true); |
|
99
|
|
|
$evt->setReturnValue('getProject', $project, 1); |
|
100
|
|
|
|
|
101
|
|
|
$backendSVN = new MockBackendSVN(); |
|
102
|
|
|
$backendSVN->setReturnValue('updateSVNAccess', false); |
|
103
|
|
|
$backendSVN->expectOnce('updateSVNAccess'); |
|
104
|
|
|
$evt->setReturnValue('getBackend', $backendSVN, array('SVN')); |
|
105
|
|
|
|
|
106
|
|
|
$evt->expectOnce('getProject'); |
|
107
|
|
|
$evt->expectOnce('getBackend'); |
|
108
|
|
|
$evt->expectNever('done'); |
|
109
|
|
|
$evt->expectOnce('error', array("Could not update SVN access file (1)")); |
|
110
|
|
|
|
|
111
|
|
|
// Launch the event |
|
112
|
|
|
$this->assertFalse($evt->process()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* ProjectUGroup modify Success |
|
117
|
|
|
* |
|
118
|
|
|
* @return Void |
|
119
|
|
|
*/ |
|
120
|
|
|
public function testUgroupModifyProcessSuccess() { |
|
121
|
|
|
$evt = new SystemEvent_UGROUP_MODIFY_TestVersion(); |
|
122
|
|
|
$evt->__construct('1', SystemEvent::TYPE_UGROUP_MODIFY, SystemEvent::OWNER_ROOT, '1', SystemEvent::PRIORITY_HIGH, SystemEvent::STATUS_RUNNING, $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], ''); |
|
123
|
|
|
$evt->setReturnValue('getParametersAsArray', array(1, 2)); |
|
124
|
|
|
|
|
125
|
|
|
$evt->setReturnValue('processUgroupBinding', true); |
|
126
|
|
|
|
|
127
|
|
|
$project = new MockProject(); |
|
128
|
|
|
$project->setReturnValue('usesSVN', true); |
|
129
|
|
|
$evt->setReturnValue('getProject', $project, 1); |
|
130
|
|
|
|
|
131
|
|
|
$backendSVN = new MockBackendSVN(); |
|
132
|
|
|
$backendSVN->setReturnValue('updateSVNAccess', true); |
|
133
|
|
|
$backendSVN->expectOnce('updateSVNAccess'); |
|
134
|
|
|
$evt->setReturnValue('getBackend', $backendSVN, array('SVN')); |
|
135
|
|
|
|
|
136
|
|
|
$evt->expectOnce('getProject'); |
|
137
|
|
|
$evt->expectOnce('getBackend'); |
|
138
|
|
|
$evt->expectOnce('done'); |
|
139
|
|
|
$evt->expectNever('error'); |
|
140
|
|
|
|
|
141
|
|
|
// Launch the event |
|
142
|
|
|
$this->assertTrue($evt->process()); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function testUpdateSVNOfBindedUgroups() { |
|
146
|
|
|
$evt = new SystemEvent_UGROUP_MODIFY_TestUGroupVersion(); |
|
147
|
|
|
$evt->__construct('1', SystemEvent::TYPE_UGROUP_MODIFY, SystemEvent::OWNER_ROOT, '1', SystemEvent::PRIORITY_HIGH, SystemEvent::STATUS_RUNNING, $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], ''); |
|
148
|
|
|
$evt->setReturnValue('getParametersAsArray', array(1, 2)); |
|
149
|
|
|
|
|
150
|
|
|
$project = mock('Project'); |
|
151
|
|
|
$project->setReturnValue('usesSVN', true); |
|
152
|
|
|
$evt->setReturnValue('getProject', $project); |
|
153
|
|
|
|
|
154
|
|
|
$ugroupbinding = mock('UgroupBinding'); |
|
155
|
|
|
$ugroupbinding->setReturnValue('updateBindedUGroups', true); |
|
156
|
|
|
$ugroupbinding->setReturnValue('removeAllUGroupsBinding', true); |
|
157
|
|
|
$projects = array( |
|
158
|
|
|
1 => array('group_id' => 101), |
|
159
|
|
|
2 => array('group_id' => 102) |
|
160
|
|
|
); |
|
161
|
|
|
$ugroupbinding->setReturnValue('getUGroupsByBindingSource', $projects); |
|
162
|
|
|
$evt->setReturnValue('getUgroupBinding', $ugroupbinding); |
|
163
|
|
|
|
|
164
|
|
|
$backendSVN = mock('BackendSVN'); |
|
165
|
|
|
$backendSVN->setReturnValue('updateSVNAccess', true); |
|
166
|
|
|
$evt->setReturnValue('getBackend', $backendSVN, array('SVN')); |
|
167
|
|
|
|
|
168
|
|
|
$backendSVN->expectCallCount('updateSVNAccess', 3); |
|
169
|
|
|
$evt->expectOnce('done'); |
|
170
|
|
|
$evt->expectNever('error'); |
|
171
|
|
|
|
|
172
|
|
|
// Launch the event |
|
173
|
|
|
$this->assertTrue($evt->process()); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|