1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Spryker Commerce OS. |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
9
|
|
|
|
10
|
|
|
namespace PyzTest\Zed\AclEntity\Persistence\AclDirector; |
11
|
|
|
|
12
|
|
|
use Codeception\Test\Unit; |
13
|
|
|
use Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer; |
14
|
|
|
use Generated\Shared\Transfer\AclEntityMetadataTransfer; |
15
|
|
|
use Generated\Shared\Transfer\AclEntityRuleTransfer; |
16
|
|
|
use Generated\Shared\Transfer\AclEntitySegmentRequestTransfer; |
17
|
|
|
use Generated\Shared\Transfer\MerchantProductTransfer; |
18
|
|
|
use Generated\Shared\Transfer\RolesTransfer; |
19
|
|
|
use Generated\Shared\Transfer\RoleTransfer; |
20
|
|
|
use Orm\Zed\Merchant\Persistence\SpyMerchant; |
21
|
|
|
use Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract; |
22
|
|
|
use Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstractQuery; |
23
|
|
|
use Orm\Zed\Product\Persistence\SpyProduct; |
24
|
|
|
use Orm\Zed\Product\Persistence\SpyProductAbstract; |
25
|
|
|
use Orm\Zed\Product\Persistence\SpyProductAbstractQuery; |
26
|
|
|
use Orm\Zed\Product\Persistence\SpyProductQuery; |
27
|
|
|
use PyzTest\Zed\AclEntity\AclQueryDirectorTester; |
28
|
|
|
use Spryker\Shared\AclEntity\AclEntityConstants; |
29
|
|
|
use Spryker\Zed\AclEntity\AclEntityDependencyProvider; |
30
|
|
|
use Spryker\Zed\AclEntity\Persistence\Exception\OperationNotAuthorizedException; |
31
|
|
|
use Spryker\Zed\Merchant\MerchantDependencyProvider; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Auto-generated group annotations |
35
|
|
|
* |
36
|
|
|
* @group PyzTest |
37
|
|
|
* @group Zed |
38
|
|
|
* @group AclEntity |
39
|
|
|
* @group Persistence |
40
|
|
|
* @group AclDirector |
41
|
|
|
* @group RelationHandlingTest |
42
|
|
|
* Add your own group annotations below this line |
43
|
|
|
*/ |
44
|
|
|
class RelationHandlingTest extends Unit |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var \PyzTest\Zed\AclEntity\AclQueryDirectorTester |
48
|
|
|
*/ |
49
|
|
|
protected $tester; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
protected function setUp(): void |
55
|
|
|
{ |
56
|
|
|
parent::setUp(); |
57
|
|
|
|
58
|
|
|
$this->tester->setDependency(MerchantDependencyProvider::PLUGINS_MERCHANT_POST_CREATE, []); |
59
|
|
|
|
60
|
|
|
$this->tester->deleteTestData(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @group AclEntityCreate |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testInspectCreateWithCreatePermissionForRelation(): void |
69
|
|
|
{ |
70
|
|
|
// Arrange |
71
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
72
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
73
|
|
|
|
74
|
|
|
$this->tester->haveAclEntityRule( |
75
|
|
|
[ |
76
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
77
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
78
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
79
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
80
|
|
|
], |
81
|
|
|
); |
82
|
|
|
$this->tester->haveAclEntityRule( |
83
|
|
|
[ |
84
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
85
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
86
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
87
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
88
|
|
|
], |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
92
|
|
|
|
93
|
|
|
$productEntity = new SpyProduct(); |
94
|
|
|
$productEntity->setSpyProductAbstract(new SpyProductAbstract()); |
95
|
|
|
|
96
|
|
|
// Act, Assert |
97
|
|
|
$aclModelDirector->inspectCreate($productEntity); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @group AclEntityCreate |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function testInspectCreateWithNoCreatePermissionForRelation(): void |
106
|
|
|
{ |
107
|
|
|
// Assert |
108
|
|
|
$this->expectException(OperationNotAuthorizedException::class); |
109
|
|
|
$this->expectExceptionMessage( |
110
|
|
|
'Operation "create" is restricted for Orm\Zed\Product\Persistence\SpyProductAbstract', |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
// Arrange |
114
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
115
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
116
|
|
|
|
117
|
|
|
$this->tester->haveAclEntityRule( |
118
|
|
|
[ |
119
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
120
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
121
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
122
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ |
123
|
|
|
| AclEntityConstants::OPERATION_MASK_CREATE, |
124
|
|
|
], |
125
|
|
|
); |
126
|
|
|
$this->tester->haveAclEntityRule( |
127
|
|
|
[ |
128
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
129
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
130
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
131
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
132
|
|
|
], |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
136
|
|
|
|
137
|
|
|
$productEntity = new SpyProduct(); |
138
|
|
|
$productEntity->setSpyProductAbstract(new SpyProductAbstract()); |
139
|
|
|
|
140
|
|
|
// Act |
141
|
|
|
$aclModelDirector->inspectCreate($productEntity); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @group AclEntityCreate |
146
|
|
|
* @group AclEntityUpdate |
147
|
|
|
* |
148
|
|
|
* @return void |
149
|
|
|
*/ |
150
|
|
|
public function testInspectCreateWithUpdatePermissionForRelation(): void |
151
|
|
|
{ |
152
|
|
|
// Arrange |
153
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
154
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
155
|
|
|
|
156
|
|
|
$productAbstractTransfer = $this->tester->haveProductAbstract(); |
157
|
|
|
|
158
|
|
|
$this->tester->haveAclEntityRule( |
159
|
|
|
[ |
160
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
161
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
162
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
163
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
164
|
|
|
], |
165
|
|
|
); |
166
|
|
|
$this->tester->haveAclEntityRule( |
167
|
|
|
[ |
168
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
169
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
170
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
171
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
172
|
|
|
], |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
176
|
|
|
|
177
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
178
|
|
|
$productAbstractTransfer->getIdProductAbstractOrFail(), |
179
|
|
|
); |
180
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
181
|
|
|
$newProductConcreteEntity = new SpyProduct(); |
182
|
|
|
$newProductConcreteEntity->setSpyProductAbstract($productAbstractEntity); |
183
|
|
|
|
184
|
|
|
// Act, Assert |
185
|
|
|
$aclModelDirector->inspectCreate($newProductConcreteEntity); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @group AclEntityCreate |
190
|
|
|
* @group AclEntityUpdate |
191
|
|
|
* |
192
|
|
|
* @return void |
193
|
|
|
*/ |
194
|
|
|
public function testInspectCreateWithNoUpdatePermissionForRelation(): void |
195
|
|
|
{ |
196
|
|
|
// Assert |
197
|
|
|
$this->expectException(OperationNotAuthorizedException::class); |
198
|
|
|
$this->expectExceptionMessage( |
199
|
|
|
'Operation "update" is restricted for Orm\Zed\Product\Persistence\SpyProductAbstract', |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
// Arrange |
203
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
204
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
205
|
|
|
|
206
|
|
|
$productAbstractTransfer = $this->tester->haveProductAbstract(); |
207
|
|
|
|
208
|
|
|
$this->tester->haveAclEntityRule( |
209
|
|
|
[ |
210
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
211
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
212
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
213
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
214
|
|
|
], |
215
|
|
|
); |
216
|
|
|
$this->tester->haveAclEntityRule( |
217
|
|
|
[ |
218
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
219
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
220
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
221
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
222
|
|
|
], |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
226
|
|
|
|
227
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
228
|
|
|
$productAbstractTransfer->getIdProductAbstractOrFail(), |
229
|
|
|
); |
230
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
231
|
|
|
$newProductConcreteEntity = new SpyProduct(); |
232
|
|
|
$newProductConcreteEntity->setSpyProductAbstract($productAbstractEntity); |
233
|
|
|
|
234
|
|
|
// Act |
235
|
|
|
$aclModelDirector->inspectCreate($newProductConcreteEntity); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @group AclEntityUpdate |
240
|
|
|
* |
241
|
|
|
* @return void |
242
|
|
|
*/ |
243
|
|
|
public function testInspectUpdateWithUpdatePermissionForRelation(): void |
244
|
|
|
{ |
245
|
|
|
// Arrange |
246
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
247
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
248
|
|
|
|
249
|
|
|
$productTransfer = $this->tester->haveProduct(); |
250
|
|
|
|
251
|
|
|
$this->tester->haveAclEntityRule( |
252
|
|
|
[ |
253
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
254
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
255
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
256
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
257
|
|
|
], |
258
|
|
|
); |
259
|
|
|
$this->tester->haveAclEntityRule( |
260
|
|
|
[ |
261
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
262
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
263
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
264
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
265
|
|
|
], |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
269
|
|
|
|
270
|
|
|
$productEntity = $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()); |
271
|
|
|
$productEntity->setSku($productEntity->getSku() . time()); |
272
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
273
|
|
|
$productTransfer->getFkProductAbstractOrFail(), |
274
|
|
|
); |
275
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
276
|
|
|
|
277
|
|
|
// Act, Assert |
278
|
|
|
$aclModelDirector->inspectUpdate($productEntity); |
|
|
|
|
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @group AclEntityUpdate |
283
|
|
|
* |
284
|
|
|
* @return void |
285
|
|
|
*/ |
286
|
|
|
public function testInspectUpdateWithNoUpdatePermissionForRelation(): void |
287
|
|
|
{ |
288
|
|
|
// Assert |
289
|
|
|
$this->expectException(OperationNotAuthorizedException::class); |
290
|
|
|
$this->expectExceptionMessage( |
291
|
|
|
'Operation "update" is restricted for Orm\Zed\Product\Persistence\SpyProductAbstract', |
292
|
|
|
); |
293
|
|
|
|
294
|
|
|
// Arrange |
295
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
296
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
297
|
|
|
|
298
|
|
|
$productTransfer = $this->tester->haveProduct(); |
299
|
|
|
|
300
|
|
|
$this->tester->haveAclEntityRule( |
301
|
|
|
[ |
302
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
303
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
304
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
305
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
306
|
|
|
], |
307
|
|
|
); |
308
|
|
|
|
309
|
|
|
$this->tester->haveAclEntityRule( |
310
|
|
|
[ |
311
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
312
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
313
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
314
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
315
|
|
|
], |
316
|
|
|
); |
317
|
|
|
|
318
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
319
|
|
|
|
320
|
|
|
$productEntity = $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()); |
321
|
|
|
$productEntity->setSku($productEntity->getSku() . time()); |
322
|
|
|
|
323
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
324
|
|
|
$productTransfer->getFkProductAbstractOrFail(), |
325
|
|
|
); |
326
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
327
|
|
|
$productAbstractEntity->addSpyProduct($productEntity); |
328
|
|
|
|
329
|
|
|
// Act |
330
|
|
|
$aclModelDirector->inspectUpdate($productEntity); |
|
|
|
|
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @group AclEntityCreate |
335
|
|
|
* @group AclEntityUpdate |
336
|
|
|
* |
337
|
|
|
* @return void |
338
|
|
|
*/ |
339
|
|
|
public function testInspectUpdateWithCreatePermissionForRelation(): void |
340
|
|
|
{ |
341
|
|
|
// Arrange |
342
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
343
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
344
|
|
|
|
345
|
|
|
$productAbstractTransfer = $this->tester->haveProductAbstract(); |
346
|
|
|
|
347
|
|
|
$this->tester->haveAclEntityRule( |
348
|
|
|
[ |
349
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
350
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
351
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
352
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
353
|
|
|
], |
354
|
|
|
); |
355
|
|
|
$this->tester->haveAclEntityRule( |
356
|
|
|
[ |
357
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
358
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
359
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
360
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE, |
361
|
|
|
], |
362
|
|
|
); |
363
|
|
|
|
364
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
365
|
|
|
|
366
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
367
|
|
|
$productAbstractTransfer->getIdProductAbstract(), |
368
|
|
|
); |
369
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
370
|
|
|
$productAbstractEntity->addSpyProduct(new SpyProduct()); |
371
|
|
|
|
372
|
|
|
// Act, Assert |
373
|
|
|
$aclModelDirector->inspectUpdate($productAbstractEntity); |
|
|
|
|
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @group AclEntityCreate |
378
|
|
|
* @group AclEntityUpdate |
379
|
|
|
* |
380
|
|
|
* @return void |
381
|
|
|
*/ |
382
|
|
|
public function testInspectUpdateWithNoCreatePermissionForRelation(): void |
383
|
|
|
{ |
384
|
|
|
// Assert |
385
|
|
|
$this->expectException(OperationNotAuthorizedException::class); |
386
|
|
|
$this->expectExceptionMessage( |
387
|
|
|
'Operation "create" is restricted for Orm\Zed\Product\Persistence\SpyProduct', |
388
|
|
|
); |
389
|
|
|
|
390
|
|
|
// Arrange |
391
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
392
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
393
|
|
|
|
394
|
|
|
$productAbstractTransfer = $this->tester->haveProductAbstract(); |
395
|
|
|
|
396
|
|
|
$this->tester->haveAclEntityRule( |
397
|
|
|
[ |
398
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
399
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
400
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
401
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_UPDATE, |
402
|
|
|
], |
403
|
|
|
); |
404
|
|
|
$this->tester->haveAclEntityRule( |
405
|
|
|
[ |
406
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
407
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
408
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
409
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
410
|
|
|
], |
411
|
|
|
); |
412
|
|
|
|
413
|
|
|
$aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer); |
414
|
|
|
|
415
|
|
|
$productAbstractEntity = $this->tester->findProductAbstractByIdProductAbstract( |
416
|
|
|
$productAbstractTransfer->getIdProductAbstract(), |
417
|
|
|
); |
418
|
|
|
$productAbstractEntity->setSku($productAbstractEntity->getSku() . time()); |
419
|
|
|
$productAbstractEntity->addSpyProduct(new SpyProduct()); |
420
|
|
|
|
421
|
|
|
// Act, Assert |
422
|
|
|
$aclModelDirector->inspectUpdate($productAbstractEntity); |
|
|
|
|
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @group AclEntityApplyAclRules |
427
|
|
|
* |
428
|
|
|
* @return void |
429
|
|
|
*/ |
430
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForJoinsInGlobalScope(): void |
431
|
|
|
{ |
432
|
|
|
// Arrange |
433
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
434
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
435
|
|
|
|
436
|
|
|
$productConcreteTransfer = $this->tester->haveProduct(); |
437
|
|
|
|
438
|
|
|
$this->tester->haveAclEntityRule( |
439
|
|
|
[ |
440
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
441
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
442
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
443
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
444
|
|
|
], |
445
|
|
|
); |
446
|
|
|
$this->tester->haveAclEntityRule( |
447
|
|
|
[ |
448
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
449
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
450
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
451
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
452
|
|
|
], |
453
|
|
|
); |
454
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
455
|
|
|
|
456
|
|
|
$query = SpyProductQuery::create()->joinWithSpyProductAbstract()->filterBySku( |
457
|
|
|
$productConcreteTransfer->getSkuOrFail(), |
458
|
|
|
); |
459
|
|
|
|
460
|
|
|
// Act |
461
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
462
|
|
|
|
463
|
|
|
// Assert |
464
|
|
|
/** @var \Orm\Zed\Product\Persistence\SpyProduct $productConcreteEntity */ |
465
|
|
|
foreach ($query->find() as $productConcreteEntity) { |
466
|
|
|
$this->assertNotEmpty($productConcreteEntity->getSpyProductAbstract()); |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @group AclEntityApplyAclRules |
472
|
|
|
* |
473
|
|
|
* @return void |
474
|
|
|
*/ |
475
|
|
|
public function testApplyAclRulesOnSelectQueryWithNoReadPermissionForJoinsInGlobalScope(): void |
476
|
|
|
{ |
477
|
|
|
// Arrange |
478
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
479
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
480
|
|
|
|
481
|
|
|
$productTransfer = $this->tester->haveProduct(); |
482
|
|
|
|
483
|
|
|
$this->tester->haveAclEntityRule( |
484
|
|
|
[ |
485
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
486
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProduct::class, |
487
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
488
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
489
|
|
|
], |
490
|
|
|
); |
491
|
|
|
$this->tester->haveAclEntityRule( |
492
|
|
|
[ |
493
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
494
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
495
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
496
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => 0, |
497
|
|
|
], |
498
|
|
|
); |
499
|
|
|
|
500
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
501
|
|
|
|
502
|
|
|
$query = SpyProductQuery::create()->leftJoinWithSpyProductAbstract()->filterBySku( |
503
|
|
|
$productTransfer->getSkuOrFail(), |
504
|
|
|
); |
505
|
|
|
|
506
|
|
|
// Act |
507
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
508
|
|
|
|
509
|
|
|
// Assert |
510
|
|
|
$this->assertNotEmpty($query->count()); |
511
|
|
|
foreach ($query->find()->toArray() as $item) { |
512
|
|
|
$this->assertArrayNotHasKey('SpyProductAbstract', $item); |
513
|
|
|
} |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @group AclEntityApplyAclRules |
518
|
|
|
* |
519
|
|
|
* @return void |
520
|
|
|
*/ |
521
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForJoinsInSegmentScope(): void |
522
|
|
|
{ |
523
|
|
|
// Arrange |
524
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
525
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
526
|
|
|
|
527
|
|
|
$merchantTransfer = $this->tester->haveMerchant(); |
528
|
|
|
$productConcreteTransfer = $this->tester->haveProduct(); |
529
|
|
|
$this->tester->haveMerchantProduct( |
530
|
|
|
[ |
531
|
|
|
MerchantProductTransfer::ID_MERCHANT => $merchantTransfer->getIdMerchantOrFail(), |
532
|
|
|
MerchantProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstractOrFail(), |
533
|
|
|
], |
534
|
|
|
); |
535
|
|
|
|
536
|
|
|
$this->tester->haveAclEntityRule( |
537
|
|
|
[ |
538
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
539
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
540
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
541
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
542
|
|
|
], |
543
|
|
|
); |
544
|
|
|
$segmentTransfer = $this->tester->haveAclEntitySegment( |
545
|
|
|
[ |
546
|
|
|
AclEntitySegmentRequestTransfer::NAME => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_NAME, |
547
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_REFERENCE, |
548
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
549
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
550
|
|
|
], |
551
|
|
|
); |
552
|
|
|
$this->tester->haveAclEntityRule( |
553
|
|
|
[ |
554
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
555
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
556
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
557
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $segmentTransfer->getIdAclEntitySegmentOrFail(), |
558
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
559
|
|
|
], |
560
|
|
|
); |
561
|
|
|
|
562
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
563
|
|
|
|
564
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->leftJoinWithMerchant()->filterByFkMerchant( |
565
|
|
|
$merchantTransfer->getIdMerchantOrFail(), |
566
|
|
|
); |
567
|
|
|
|
568
|
|
|
// Act |
569
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
570
|
|
|
|
571
|
|
|
// Assert |
572
|
|
|
/** @var \Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract $merchantProductEntity */ |
573
|
|
|
foreach ($query->find() as $merchantProductEntity) { |
574
|
|
|
$this->assertNotEmpty($merchantProductEntity->getMerchant()); |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* @group AclEntityApplyAclRules |
580
|
|
|
* |
581
|
|
|
* @return void |
582
|
|
|
*/ |
583
|
|
|
public function testApplyAclRulesOnSelectQueryWithNoReadPermissionForJoin(): void |
584
|
|
|
{ |
585
|
|
|
// Arrange |
586
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
587
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
588
|
|
|
|
589
|
|
|
$this->tester->haveAclEntityRule( |
590
|
|
|
[ |
591
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
592
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
593
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
594
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
595
|
|
|
], |
596
|
|
|
); |
597
|
|
|
|
598
|
|
|
$merchantTransfer = $this->tester->haveMerchant(); |
599
|
|
|
$productConcreteTransfer = $this->tester->haveProduct(); |
600
|
|
|
$this->tester->haveMerchantProduct( |
601
|
|
|
[ |
602
|
|
|
MerchantProductTransfer::ID_MERCHANT => $merchantTransfer->getIdMerchantOrFail(), |
603
|
|
|
MerchantProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstractOrFail(), |
604
|
|
|
], |
605
|
|
|
); |
606
|
|
|
|
607
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector( |
608
|
|
|
$rolesTransfer, |
609
|
|
|
(new AclEntityMetadataCollectionTransfer()) |
610
|
|
|
->addAclEntityMetadata( |
611
|
|
|
SpyMerchant::class, |
612
|
|
|
(new AclEntityMetadataTransfer()) |
613
|
|
|
->setEntityName(SpyMerchant::class) |
614
|
|
|
->setDefaultGlobalOperationMask(0), |
615
|
|
|
), |
616
|
|
|
); |
617
|
|
|
|
618
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->leftJoinWithMerchant()->filterByFkMerchant( |
619
|
|
|
$merchantTransfer->getIdMerchantOrFail(), |
620
|
|
|
); |
621
|
|
|
|
622
|
|
|
// Act |
623
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
624
|
|
|
|
625
|
|
|
// Assert |
626
|
|
|
foreach ($query->find()->toArray() as $item) { |
627
|
|
|
$this->assertArrayNotHasKey('Merchant', $item); |
628
|
|
|
} |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
/** |
632
|
|
|
* @group AclEntityApplyAclRules |
633
|
|
|
* |
634
|
|
|
* @return void |
635
|
|
|
*/ |
636
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForJoinsInDefaultScope(): void |
637
|
|
|
{ |
638
|
|
|
// Arrange |
639
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
640
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
641
|
|
|
|
642
|
|
|
$merchantTransfer = $this->tester->haveMerchant(); |
643
|
|
|
$productConcreteTransfer = $this->tester->haveProduct(); |
644
|
|
|
$this->tester->haveMerchantProduct( |
645
|
|
|
[ |
646
|
|
|
MerchantProductTransfer::ID_MERCHANT => $merchantTransfer->getIdMerchantOrFail(), |
647
|
|
|
MerchantProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstractOrFail(), |
648
|
|
|
], |
649
|
|
|
); |
650
|
|
|
|
651
|
|
|
$this->tester->haveAclEntityRule( |
652
|
|
|
[ |
653
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
654
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
655
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
656
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
657
|
|
|
], |
658
|
|
|
); |
659
|
|
|
|
660
|
|
|
$aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())->addAclEntityMetadata( |
661
|
|
|
SpyMerchant::class, |
662
|
|
|
(new AclEntityMetadataTransfer()) |
663
|
|
|
->setEntityName(SpyMerchant::class) |
664
|
|
|
->setDefaultGlobalOperationMask(AclEntityConstants::OPERATION_MASK_READ), |
665
|
|
|
); |
666
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer); |
667
|
|
|
|
668
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->joinWithMerchant()->filterByFkMerchant( |
669
|
|
|
$merchantTransfer->getIdMerchantOrFail(), |
670
|
|
|
); |
671
|
|
|
|
672
|
|
|
// Act |
673
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
674
|
|
|
|
675
|
|
|
// Assert |
676
|
|
|
/** @var \Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract $merchantProductAbstractEntity */ |
677
|
|
|
foreach ($query->find() as $merchantProductAbstractEntity) { |
678
|
|
|
$this->assertNotEmpty($merchantProductAbstractEntity->getMerchant()); |
679
|
|
|
} |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* @group AclEntityApplyAclRules |
684
|
|
|
* |
685
|
|
|
* @return void |
686
|
|
|
*/ |
687
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForLeftJoin(): void |
688
|
|
|
{ |
689
|
|
|
// Arrange |
690
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
691
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
692
|
|
|
|
693
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
694
|
|
|
|
695
|
|
|
$this->tester->haveAclEntityRule( |
696
|
|
|
[ |
697
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
698
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
699
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
700
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
701
|
|
|
], |
702
|
|
|
); |
703
|
|
|
$this->tester->haveAclEntityRule( |
704
|
|
|
[ |
705
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
706
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
707
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
708
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
709
|
|
|
], |
710
|
|
|
); |
711
|
|
|
|
712
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
713
|
|
|
|
714
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->leftJoinMerchant()->filterByFkMerchant( |
715
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
716
|
|
|
); |
717
|
|
|
|
718
|
|
|
// Act |
719
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
720
|
|
|
|
721
|
|
|
// Assert |
722
|
|
|
/** @var \Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract $merchantProductAbstractEntity */ |
723
|
|
|
foreach ($query->find() as $merchantProductAbstractEntity) { |
724
|
|
|
$this->assertNotEmpty($merchantProductAbstractEntity->getMerchant()); |
725
|
|
|
} |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* @group AclEntityApplyAclRules |
730
|
|
|
* |
731
|
|
|
* @return void |
732
|
|
|
*/ |
733
|
|
|
public function testApplyAclRulesOnSelectQueryWithNoReadPermissionForLeftJoin(): void |
734
|
|
|
{ |
735
|
|
|
// Arrange |
736
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
737
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
738
|
|
|
|
739
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
740
|
|
|
|
741
|
|
|
$this->tester->haveAclEntityRule( |
742
|
|
|
[ |
743
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
744
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
745
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
746
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
747
|
|
|
], |
748
|
|
|
); |
749
|
|
|
|
750
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
751
|
|
|
|
752
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->leftJoinMerchant()->filterByFkMerchant( |
753
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
754
|
|
|
); |
755
|
|
|
|
756
|
|
|
// Act |
757
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
758
|
|
|
|
759
|
|
|
// Assert |
760
|
|
|
foreach ($query->find()->toArray() as $merchantProductAbstract) { |
761
|
|
|
$this->assertArrayNotHasKey('Merchant', $merchantProductAbstract); |
762
|
|
|
} |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
/** |
766
|
|
|
* @group AclEntityApplyAclRules |
767
|
|
|
* |
768
|
|
|
* @return void |
769
|
|
|
*/ |
770
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForInnerJoin(): void |
771
|
|
|
{ |
772
|
|
|
// Arrange |
773
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
774
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
775
|
|
|
|
776
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
777
|
|
|
|
778
|
|
|
$this->tester->haveAclEntityRule( |
779
|
|
|
[ |
780
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
781
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
782
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
783
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
784
|
|
|
], |
785
|
|
|
); |
786
|
|
|
$this->tester->haveAclEntityRule( |
787
|
|
|
[ |
788
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
789
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
790
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
791
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
792
|
|
|
], |
793
|
|
|
); |
794
|
|
|
|
795
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
796
|
|
|
|
797
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->innerJoinMerchant()->filterByFkMerchant( |
798
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
799
|
|
|
); |
800
|
|
|
|
801
|
|
|
// Act |
802
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
803
|
|
|
|
804
|
|
|
// Assert |
805
|
|
|
/** @var \Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract $merchantProductAbstractEntity */ |
806
|
|
|
foreach ($query->find() as $merchantProductAbstractEntity) { |
807
|
|
|
$this->assertNotEmpty($merchantProductAbstractEntity->getMerchant()); |
808
|
|
|
} |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
/** |
812
|
|
|
* @group AclEntityApplyAclRules |
813
|
|
|
* |
814
|
|
|
* @return void |
815
|
|
|
*/ |
816
|
|
|
public function testApplyAclRulesOnSelectQueryWithNoReadPermissionForInnerJoin(): void |
817
|
|
|
{ |
818
|
|
|
// Arrange |
819
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
820
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
821
|
|
|
|
822
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
823
|
|
|
|
824
|
|
|
$this->tester->haveAclEntityRule( |
825
|
|
|
[ |
826
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
827
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
828
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
829
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
830
|
|
|
], |
831
|
|
|
); |
832
|
|
|
|
833
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
834
|
|
|
|
835
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->innerJoinMerchant()->filterByFkMerchant( |
836
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
837
|
|
|
); |
838
|
|
|
|
839
|
|
|
// Act |
840
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
841
|
|
|
|
842
|
|
|
// Assert |
843
|
|
|
foreach ($query->find()->toArray() as $merchantProductAbstract) { |
844
|
|
|
$this->assertArrayNotHasKey('Merchant', $merchantProductAbstract); |
845
|
|
|
} |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
/** |
849
|
|
|
* @group AclEntityApplyAclRules |
850
|
|
|
* |
851
|
|
|
* @return void |
852
|
|
|
*/ |
853
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForRightJoin(): void |
854
|
|
|
{ |
855
|
|
|
// Arrange |
856
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
857
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
858
|
|
|
|
859
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
860
|
|
|
|
861
|
|
|
$this->tester->haveAclEntityRule( |
862
|
|
|
[ |
863
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
864
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
865
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
866
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
867
|
|
|
], |
868
|
|
|
); |
869
|
|
|
$this->tester->haveAclEntityRule( |
870
|
|
|
[ |
871
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
872
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
873
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
874
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
875
|
|
|
], |
876
|
|
|
); |
877
|
|
|
|
878
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
879
|
|
|
|
880
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->innerJoinMerchant()->filterByFkMerchant( |
881
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
882
|
|
|
); |
883
|
|
|
|
884
|
|
|
// Act |
885
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
886
|
|
|
|
887
|
|
|
// Assert |
888
|
|
|
/** @var \Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract $merchantProductAbstractEntity */ |
889
|
|
|
foreach ($query->find() as $merchantProductAbstractEntity) { |
890
|
|
|
$this->assertNotEmpty($merchantProductAbstractEntity->getMerchant()); |
891
|
|
|
} |
892
|
|
|
} |
893
|
|
|
|
894
|
|
|
/** |
895
|
|
|
* @group AclEntityApplyAclRules |
896
|
|
|
* |
897
|
|
|
* @return void |
898
|
|
|
*/ |
899
|
|
|
public function testApplyAclRulesOnSelectQueryWithNoReadPermissionForRightJoin(): void |
900
|
|
|
{ |
901
|
|
|
// Arrange |
902
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
903
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
904
|
|
|
|
905
|
|
|
$merchantProductTransfer = $this->tester->createMerchantProduct(); |
906
|
|
|
|
907
|
|
|
$this->tester->haveAclEntityRule( |
908
|
|
|
[ |
909
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
910
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
911
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
912
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
913
|
|
|
], |
914
|
|
|
); |
915
|
|
|
|
916
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer); |
917
|
|
|
|
918
|
|
|
$query = SpyMerchantProductAbstractQuery::create()->rightJoinMerchant()->filterByFkMerchant( |
919
|
|
|
$merchantProductTransfer->getIdMerchantOrFail(), |
920
|
|
|
); |
921
|
|
|
|
922
|
|
|
// Act |
923
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
924
|
|
|
|
925
|
|
|
// Assert |
926
|
|
|
foreach ($query->find()->toArray() as $merchantProductAbstract) { |
927
|
|
|
$this->assertArrayNotHasKey('Merchant', $merchantProductAbstract); |
928
|
|
|
} |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
/** |
932
|
|
|
* @group AclEntityApplyAclRules |
933
|
|
|
* |
934
|
|
|
* @return void |
935
|
|
|
*/ |
936
|
|
|
public function testApplyAclRulesOnSelectQueryWithReadPermissionForOptionalLeftJoinRelation(): void |
937
|
|
|
{ |
938
|
|
|
// Arrange |
939
|
|
|
$this->tester->setDependency( |
940
|
|
|
AclEntityDependencyProvider::PLUGINS_ACL_ENTITY_METADATA_COLLECTION_EXPANDER, |
941
|
|
|
[ |
942
|
|
|
$this->tester->getProductAbstractMerchantAclEntityMetadataConfigExpanderPlugin(), |
943
|
|
|
], |
944
|
|
|
); |
945
|
|
|
|
946
|
|
|
$roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]); |
947
|
|
|
$rolesTransfer = (new RolesTransfer())->addRole($roleTransfer); |
948
|
|
|
|
949
|
|
|
$merchantTransfer = $this->tester->haveMerchant(); |
950
|
|
|
$segmentTransfer = $this->tester->haveAclEntitySegment( |
951
|
|
|
[ |
952
|
|
|
AclEntitySegmentRequestTransfer::NAME => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_NAME, |
953
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_REFERENCE, |
954
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
955
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
956
|
|
|
], |
957
|
|
|
); |
958
|
|
|
$productAbstract1Transfer = $this->tester->haveProductAbstract(); |
959
|
|
|
$productAbstract2Transfer = $this->tester->haveProductAbstract(); |
960
|
|
|
$this->tester->haveMerchantProduct( |
961
|
|
|
[ |
962
|
|
|
MerchantProductTransfer::ID_MERCHANT => $merchantTransfer->getIdMerchantOrFail(), |
963
|
|
|
MerchantProductTransfer::ID_PRODUCT_ABSTRACT => $productAbstract1Transfer->getIdProductAbstractOrFail(), |
964
|
|
|
], |
965
|
|
|
); |
966
|
|
|
|
967
|
|
|
$this->tester->haveAclEntityRule( |
968
|
|
|
[ |
969
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL, |
970
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductAbstract::class, |
971
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
972
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
973
|
|
|
], |
974
|
|
|
); |
975
|
|
|
$this->tester->haveAclEntityRule( |
976
|
|
|
[ |
977
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_INHERITED, |
978
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantProductAbstract::class, |
979
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
980
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
981
|
|
|
], |
982
|
|
|
); |
983
|
|
|
$this->tester->haveAclEntityRule( |
984
|
|
|
[ |
985
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
986
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
987
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(), |
988
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
989
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $segmentTransfer->getIdAclEntitySegmentOrFail(), |
990
|
|
|
], |
991
|
|
|
); |
992
|
|
|
$aclQueryDirector = $this->tester->createAclQueryDirector( |
993
|
|
|
$rolesTransfer, |
994
|
|
|
$this->tester->createProductAbstractMerchantMetadataHierarchy(), |
995
|
|
|
); |
996
|
|
|
$query = SpyProductAbstractQuery::create() |
997
|
|
|
->leftJoinSpyMerchantProductAbstract() |
998
|
|
|
->filterByIdProductAbstract_In( |
999
|
|
|
[ |
1000
|
|
|
$productAbstract1Transfer->getIdProductAbstractOrFail(), |
1001
|
|
|
$productAbstract2Transfer->getIdProductAbstractOrFail(), |
1002
|
|
|
], |
1003
|
|
|
) |
1004
|
|
|
->orderByIdProductAbstract(); |
1005
|
|
|
|
1006
|
|
|
// Act |
1007
|
|
|
$query = $aclQueryDirector->applyAclRuleOnSelectQuery($query); |
1008
|
|
|
$productAbstractCollection = $query->find(); |
1009
|
|
|
|
1010
|
|
|
// Assert |
1011
|
|
|
$this->assertCount(2, $productAbstractCollection); |
1012
|
|
|
} |
1013
|
|
|
} |
1014
|
|
|
|