1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use app\fixtures\{ |
4
|
|
|
AuthItemFixture, |
5
|
|
|
OauthAccessTokensFixture, |
6
|
|
|
TransitionPermissionFixture |
7
|
|
|
}; |
8
|
|
|
use Codeception\{Example, Util\HttpCode}; |
9
|
|
|
use roaresearch\yii2\roa\test\AbstractResourceCest; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Cest to transition_permission resource. |
13
|
|
|
* |
14
|
|
|
* @author Carlos (neverabe) Llamosas <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class TransitionPermissionCest extends AbstractResourceCest |
17
|
|
|
{ |
18
|
|
|
protected function authToken(ApiTester $I) |
19
|
|
|
{ |
20
|
|
|
$I->amBearerAuthenticated(OauthAccessTokensFixture::SIMPLE_TOKEN); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @depends TransitionCest:fixtures |
25
|
|
|
*/ |
26
|
|
|
public function fixtures(ApiTester $I) |
27
|
|
|
{ |
28
|
|
|
$I->haveFixtures([ |
29
|
|
|
'auth_item' => AuthItemFixture::class, |
30
|
|
|
'transition_permission' => [ |
31
|
|
|
'class' => TransitionPermissionFixture::class, |
32
|
|
|
'depends' => [], |
33
|
|
|
], |
34
|
|
|
]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ApiTester $I |
39
|
|
|
* @param Example $example |
40
|
|
|
* @dataprovider indexDataProvider |
41
|
|
|
* @depends fixtures |
42
|
|
|
* @before authToken |
43
|
|
|
*/ |
44
|
|
|
public function index(ApiTester $I, Example $example) |
45
|
|
|
{ |
46
|
|
|
$I->wantTo('Retrieve list of Transition Permission records.'); |
47
|
|
|
$this->internalIndex($I, $example); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return array<string,array> for test `index()`. |
52
|
|
|
*/ |
53
|
|
|
protected function indexDataProvider() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'list' => [ |
57
|
|
|
'urlParams' => [ |
58
|
|
|
'workflow_id' => 1, |
59
|
|
|
'stage_id' => 1, |
60
|
|
|
'target_id' => 2, |
61
|
|
|
'expand' => 'sourceStage, transition' |
62
|
|
|
], |
63
|
|
|
'httpCode' => HttpCode::OK, |
64
|
|
|
'headers' => [ |
65
|
|
|
'X-Pagination-Total-Count' => 1, |
66
|
|
|
], |
67
|
|
|
], |
68
|
|
|
'list with target stage' => [ |
69
|
|
|
'urlParams' => [ |
70
|
|
|
'workflow_id' => 2, |
71
|
|
|
'stage_id' => 5, |
72
|
|
|
'target_id' => 7 , |
73
|
|
|
'expand' => 'targetStage' |
74
|
|
|
], |
75
|
|
|
'httpCode' => HttpCode::OK, |
76
|
|
|
'headers' => [ |
77
|
|
|
'X-Pagination-Total-Count' => 1, |
78
|
|
|
], |
79
|
|
|
], |
80
|
|
|
'not found workflow' => [ |
81
|
|
|
'urlParams' => [ |
82
|
|
|
'workflow_id' => 10, |
83
|
|
|
'stage_id' => 1, |
84
|
|
|
'target_id' => 2 |
85
|
|
|
], |
86
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
87
|
|
|
], |
88
|
|
|
'not found stage' => [ |
89
|
|
|
'urlParams' => [ |
90
|
|
|
'workflow_id' => 1, |
91
|
|
|
'stage_id' => 10, |
92
|
|
|
'target_id' => 2 |
93
|
|
|
], |
94
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
95
|
|
|
], |
96
|
|
|
'not found transition' => [ |
97
|
|
|
'urlParams' => [ |
98
|
|
|
'workflow_id' => 1, |
99
|
|
|
'stage_id' => 1, |
100
|
|
|
'target_id' => 10 |
101
|
|
|
], |
102
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
103
|
|
|
], |
104
|
|
|
'filter by name' => [ |
105
|
|
|
'urlParams' => [ |
106
|
|
|
'workflow_id' => 1, |
107
|
|
|
'stage_id' => 1, |
108
|
|
|
'target_id' => 2, |
109
|
|
|
'permission' => 'administrator', |
110
|
|
|
'expand' => 'transition' |
111
|
|
|
], |
112
|
|
|
'httpCode' => HttpCode::OK, |
113
|
|
|
'headers' => [ |
114
|
|
|
'X-Pagination-Total-Count' => 1, |
115
|
|
|
], |
116
|
|
|
], |
117
|
|
|
'rule created_by' => [ |
118
|
|
|
'urlParams' => [ |
119
|
|
|
'workflow_id' => 1, |
120
|
|
|
'stage_id' => 1, |
121
|
|
|
'target_id' => 2, |
122
|
|
|
'created_by' => 'per', |
123
|
|
|
], |
124
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
125
|
|
|
], |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param ApiTester $I |
131
|
|
|
* @param Example $example |
132
|
|
|
* @dataprovider viewDataProvider |
133
|
|
|
* @depends fixtures |
134
|
|
|
* @before authToken |
135
|
|
|
*/ |
136
|
|
|
public function view(ApiTester $I, Example $example) |
137
|
|
|
{ |
138
|
|
|
$I->wantTo('Retrieve Transition Permission single record.'); |
139
|
|
|
$this->internalView($I, $example); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return array<string,array<string,string>> data for test `view()`. |
144
|
|
|
*/ |
145
|
|
|
protected function viewDataProvider() |
146
|
|
|
{ |
147
|
|
|
return [ |
148
|
|
|
'not allowed' => [ |
149
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2/permission/administrator', |
150
|
|
|
'httpCode' => HttpCode::OK, |
151
|
|
|
] |
152
|
|
|
]; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param ApiTester $I |
157
|
|
|
* @param Example $example |
158
|
|
|
* @dataprovider createDataProvider |
159
|
|
|
* @depends fixtures |
160
|
|
|
* @before authToken |
161
|
|
|
*/ |
162
|
|
|
public function create(ApiTester $I, Example $example) |
163
|
|
|
{ |
164
|
|
|
$I->wantTo('Create a Transition Permission record.'); |
165
|
|
|
$this->internalCreate($I, $example); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return array<string,array> data for test `create()`. |
170
|
|
|
*/ |
171
|
|
|
protected function createDataProvider() |
172
|
|
|
{ |
173
|
|
|
return [ |
174
|
|
|
'create transition permission' => [ |
175
|
|
|
'urlParams' => [ |
176
|
|
|
'workflow_id' => 1, |
177
|
|
|
'stage_id' => 1, |
178
|
|
|
'target_id' => 2 |
179
|
|
|
], |
180
|
|
|
'data' => [ |
181
|
|
|
'permission' => 'credit' |
182
|
|
|
], |
183
|
|
|
'httpCode' => HttpCode::CREATED, |
184
|
|
|
], |
185
|
|
|
'required data' => [ |
186
|
|
|
'urlParams' => [ |
187
|
|
|
'workflow_id' => 1, |
188
|
|
|
'stage_id' => 1, |
189
|
|
|
'target_id' => 2 |
190
|
|
|
], |
191
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
192
|
|
|
'validationErrors' => [ |
193
|
|
|
'permission' => 'Permission cannot be blank.' |
194
|
|
|
], |
195
|
|
|
], |
196
|
|
|
'workflow not found' => [ |
197
|
|
|
'urlParams' => [ |
198
|
|
|
'workflow_id' => 10, |
199
|
|
|
'stage_id' => 1, |
200
|
|
|
'target_id' => 2 |
201
|
|
|
], |
202
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
203
|
|
|
], |
204
|
|
|
'stage not found' => [ |
205
|
|
|
'urlParams' => [ |
206
|
|
|
'workflow_id' => 1, |
207
|
|
|
'stage_id' => 19, |
208
|
|
|
'target_id' => 2 |
209
|
|
|
], |
210
|
|
|
'data' => [ |
211
|
|
|
'permission' => 'administrator', |
212
|
|
|
], |
213
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
214
|
|
|
], |
215
|
|
|
'to short' => [ |
216
|
|
|
'urlParams' => [ |
217
|
|
|
'workflow_id' => 1, |
218
|
|
|
'stage_id' => 1, |
219
|
|
|
'target_id' => 2 |
220
|
|
|
], |
221
|
|
|
'data' => [ |
222
|
|
|
'permission' => 'ad' |
223
|
|
|
], |
224
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
225
|
|
|
'validationErrors' => [ |
226
|
|
|
'permission' => 'Permission should contain at least 6 characters.' |
227
|
|
|
], |
228
|
|
|
], |
229
|
|
|
'unique transition permission' => [ |
230
|
|
|
'urlParams' => [ |
231
|
|
|
'workflow_id' => 1, |
232
|
|
|
'stage_id' => 1, |
233
|
|
|
'target_id' => 2 |
234
|
|
|
], |
235
|
|
|
'data' => [ |
236
|
|
|
'permission' => 'administrator' |
237
|
|
|
], |
238
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
239
|
|
|
'validationErrors' => [ |
240
|
|
|
'permission' => 'Permission already set for the transition.' |
241
|
|
|
], |
242
|
|
|
], |
243
|
|
|
]; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param ApiTester $I |
248
|
|
|
* @param Example $example |
249
|
|
|
* @dataprovider updateDataProvider |
250
|
|
|
* @depends fixtures |
251
|
|
|
* @before authToken |
252
|
|
|
*/ |
253
|
|
|
public function update(ApiTester $I, Example $example) |
254
|
|
|
{ |
255
|
|
|
$I->wantTo('Update a Transition Permission record.'); |
256
|
|
|
$this->internalUpdate($I, $example); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return array<string,array<string,string|array<string,string>>> data for test `update()`. |
261
|
|
|
*/ |
262
|
|
|
protected function updateDataProvider() |
263
|
|
|
{ |
264
|
|
|
return [ |
265
|
|
|
'method not allowed' => [ |
266
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2/permission', |
267
|
|
|
'data' => ['permission' => 'update transition'], |
268
|
|
|
'httpCode' => HttpCode::METHOD_NOT_ALLOWED, |
269
|
|
|
], |
270
|
|
|
]; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param ApiTester $I |
275
|
|
|
* @param Example $example |
276
|
|
|
* @dataprovider deleteDataProvider |
277
|
|
|
* @depends fixtures |
278
|
|
|
* @before authToken |
279
|
|
|
*/ |
280
|
|
|
public function delete(ApiTester $I, Example $example) |
281
|
|
|
{ |
282
|
|
|
$I->wantTo('Delete a Transition Permission record.'); |
283
|
|
|
$this->internalDelete($I, $example); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @return array<string,array<string,string|array<string,string>>> data for test `delete()`. |
288
|
|
|
*/ |
289
|
|
|
protected function deleteDataProvider() |
290
|
|
|
{ |
291
|
|
|
return [ |
292
|
|
|
'delete permission administrator' => [ |
293
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2/permission/administrator', |
294
|
|
|
'httpCode' => HttpCode::NO_CONTENT, |
295
|
|
|
], |
296
|
|
|
'cannot be blank' => [ |
297
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2/permission', |
298
|
|
|
'httpCode' => HttpCode::METHOD_NOT_ALLOWED, |
299
|
|
|
], |
300
|
|
|
'transition not found' => [ |
301
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/10/permission/admin', |
302
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
303
|
|
|
], |
304
|
|
|
'stage not found' => [ |
305
|
|
|
'url' => '/w1/workflow/1/stage/10/transition/2/permission/admin', |
306
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
307
|
|
|
], |
308
|
|
|
'workflow not found' => [ |
309
|
|
|
'url' => '/w1/workflow/10/stage/1/transition/2/permission/admin', |
310
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
311
|
|
|
], |
312
|
|
|
]; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @inheritdoc |
317
|
|
|
*/ |
318
|
|
|
protected function recordJsonType(): array |
319
|
|
|
{ |
320
|
|
|
return [ |
321
|
|
|
'source_stage_id' => 'integer:>0', |
322
|
|
|
'target_stage_id' => 'integer:>0', |
323
|
|
|
'permission' => 'string', |
324
|
|
|
|
325
|
|
|
]; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @inheritdoc |
330
|
|
|
*/ |
331
|
|
|
protected function getRoutePattern(): string |
332
|
|
|
{ |
333
|
|
|
return 'w1/workflow/<workflow_id:\d+>/stage/<stage_id:\d+>/transition/<target_id:\d+>/permission'; |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|