|
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; |
|
11
|
|
|
|
|
12
|
|
|
use Codeception\Actor; |
|
13
|
|
|
use Codeception\Stub; |
|
14
|
|
|
use Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer; |
|
15
|
|
|
use Generated\Shared\Transfer\AclEntityMetadataConfigTransfer; |
|
16
|
|
|
use Generated\Shared\Transfer\AclEntityMetadataTransfer; |
|
17
|
|
|
use Generated\Shared\Transfer\AclEntityParentConnectionMetadataTransfer; |
|
18
|
|
|
use Generated\Shared\Transfer\AclEntityParentMetadataTransfer; |
|
19
|
|
|
use Generated\Shared\Transfer\AclEntityRuleTransfer; |
|
20
|
|
|
use Generated\Shared\Transfer\AclEntitySegmentCriteriaTransfer; |
|
21
|
|
|
use Generated\Shared\Transfer\AclEntitySegmentRequestTransfer; |
|
22
|
|
|
use Generated\Shared\Transfer\AclRoleCriteriaTransfer; |
|
23
|
|
|
use Generated\Shared\Transfer\MerchantProductTransfer; |
|
24
|
|
|
use Generated\Shared\Transfer\MerchantTransfer; |
|
25
|
|
|
use Generated\Shared\Transfer\RolesTransfer; |
|
26
|
|
|
use Generated\Shared\Transfer\RoleTransfer; |
|
27
|
|
|
use Generated\Shared\Transfer\UserTransfer; |
|
28
|
|
|
use Orm\Zed\Merchant\Persistence\SpyMerchant; |
|
29
|
|
|
use Orm\Zed\Merchant\Persistence\SpyMerchantQuery; |
|
30
|
|
|
use Orm\Zed\MerchantCategory\Persistence\SpyMerchantCategory; |
|
31
|
|
|
use Orm\Zed\MerchantProduct\Persistence\SpyMerchantProductAbstract; |
|
32
|
|
|
use Orm\Zed\Product\Persistence\SpyProduct; |
|
33
|
|
|
use Orm\Zed\Product\Persistence\SpyProductAbstract; |
|
34
|
|
|
use Orm\Zed\Product\Persistence\SpyProductAbstractQuery; |
|
35
|
|
|
use Orm\Zed\Product\Persistence\SpyProductQuery; |
|
36
|
|
|
use Orm\Zed\ProductImage\Persistence\SpyProductImage; |
|
37
|
|
|
use Orm\Zed\ProductImage\Persistence\SpyProductImageQuery; |
|
38
|
|
|
use Orm\Zed\ProductImage\Persistence\SpyProductImageSet; |
|
39
|
|
|
use Orm\Zed\ProductImage\Persistence\SpyProductImageSetToProductImage; |
|
40
|
|
|
use Orm\Zed\ProductOffer\Persistence\SpyProductOffer; |
|
41
|
|
|
use Orm\Zed\ProductOffer\Persistence\SpyProductOfferQuery; |
|
42
|
|
|
use PyzTest\Zed\AclEntity\Plugin\AclEntityMetadataConfigExpanderPluginMock; |
|
43
|
|
|
use ReflectionClass; |
|
44
|
|
|
use Spryker\Shared\AclEntity\AclEntityConstants; |
|
45
|
|
|
use Spryker\Zed\AclEntity\Business\Reader\AclEntityMetadataConfigReader; |
|
46
|
|
|
use Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToAclFacadeBridge; |
|
47
|
|
|
use Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToAclFacadeBridgeInterface; |
|
48
|
|
|
use Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToUserFacadeBridge; |
|
49
|
|
|
use Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToUserFacadeBridgeInterface; |
|
50
|
|
|
use Spryker\Zed\AclEntity\Persistence\AclEntityPersistenceFactory; |
|
51
|
|
|
use Spryker\Zed\AclEntity\Persistence\AclEntityRepository; |
|
52
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclModelDirector; |
|
53
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclModelDirectorInterface; |
|
54
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclQueryDirector; |
|
55
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclQueryDirectorInterface; |
|
56
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\Provider\AclEntityRuleProvider; |
|
57
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\Provider\AclRoleProvider; |
|
58
|
|
|
use Spryker\Zed\AclEntity\Persistence\Propel\Provider\AclRoleProviderInterface; |
|
59
|
|
|
use Spryker\Zed\AclEntityExtension\Dependency\Plugin\AclEntityMetadataConfigExpanderPluginInterface; |
|
60
|
|
|
use Spryker\Zed\Kernel\AbstractBundleConfig; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Inherited Methods |
|
64
|
|
|
* |
|
65
|
|
|
* @method void wantToTest($text) |
|
66
|
|
|
* @method void wantTo($text) |
|
67
|
|
|
* @method void execute($callable) |
|
68
|
|
|
* @method void expectTo($prediction) |
|
69
|
|
|
* @method void expect($prediction) |
|
70
|
|
|
* @method void amGoingTo($argumentation) |
|
71
|
|
|
* @method void am($role) |
|
72
|
|
|
* @method void lookForwardTo($achieveValue) |
|
73
|
|
|
* @method void comment($description) |
|
74
|
|
|
* @method void pause() |
|
75
|
|
|
* |
|
76
|
|
|
* @SuppressWarnings(\PyzTest\Zed\AclEntity\PHPMD) |
|
77
|
|
|
*/ |
|
78
|
|
|
class AclQueryDirectorTester extends Actor |
|
79
|
|
|
{ |
|
80
|
|
|
use _generated\AclQueryDirectorTesterActions; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var string |
|
84
|
|
|
*/ |
|
85
|
|
|
public const ACL_ENTITY_SEGMENT_1_NAME = 'segment 1'; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var string |
|
89
|
|
|
*/ |
|
90
|
|
|
public const ACL_ENTITY_SEGMENT_2_NAME = 'segment 2'; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var string |
|
94
|
|
|
*/ |
|
95
|
|
|
public const ACL_ENTITY_SEGMENT_1_REFERENCE = 'ref_segment_1'; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var string |
|
99
|
|
|
*/ |
|
100
|
|
|
public const ACL_ENTITY_SEGMENT_2_REFERENCE = 'ref_segment_2'; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var string |
|
104
|
|
|
*/ |
|
105
|
|
|
public const ACL_ROLE_1_NAME = 'role 1'; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var string |
|
109
|
|
|
*/ |
|
110
|
|
|
public const ACL_ROLE_2_NAME = 'role 2'; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var string |
|
114
|
|
|
*/ |
|
115
|
|
|
public const ACL_ROLE_3_NAME = 'role 3'; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @var string |
|
119
|
|
|
* |
|
120
|
|
|
* @see \SprykerTest\Zed\Category\PageObject\Category::CATEGORY_A |
|
121
|
|
|
*/ |
|
122
|
|
|
public const CATEGORY_1_KEY = 'category-a'; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @var string |
|
126
|
|
|
* |
|
127
|
|
|
* @see \SprykerTest\Zed\Category\PageObject\Category::CATEGORY_B |
|
128
|
|
|
*/ |
|
129
|
|
|
public const CATEGORY_2_KEY = 'category-b'; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return void |
|
133
|
|
|
*/ |
|
134
|
|
|
public function deleteTestData(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$this->deleteRoles( |
|
137
|
|
|
(new AclRoleCriteriaTransfer())->setNames( |
|
138
|
|
|
[static::ACL_ROLE_1_NAME, static::ACL_ROLE_2_NAME, static::ACL_ROLE_3_NAME], |
|
139
|
|
|
), |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
$this->deleteAclEntitySegments( |
|
143
|
|
|
(new AclEntitySegmentCriteriaTransfer()) |
|
144
|
|
|
->addReference(static::ACL_ENTITY_SEGMENT_1_REFERENCE) |
|
145
|
|
|
->addReference(static::ACL_ENTITY_SEGMENT_2_REFERENCE), |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$this->cleanCache(); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
public function cleanCache(): void |
|
155
|
|
|
{ |
|
156
|
|
|
$reflectionResolver = new ReflectionClass(AclEntityMetadataConfigReader::class); |
|
157
|
|
|
$reflectionProperty = $reflectionResolver->getProperty('cache'); |
|
158
|
|
|
$reflectionProperty->setAccessible(true); |
|
159
|
|
|
$reflectionProperty->setValue([]); |
|
160
|
|
|
|
|
161
|
|
|
$reflectionResolver = new ReflectionClass(AclEntityRuleProvider::class); |
|
162
|
|
|
$reflectionProperty = $reflectionResolver->getProperty('aclEntityRuleCollectionTransfer'); |
|
163
|
|
|
$reflectionProperty->setAccessible(true); |
|
164
|
|
|
$reflectionProperty->setValue(null); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer |
|
169
|
|
|
*/ |
|
170
|
|
|
public function createProductImageProductCompositeEntityMetadataHierarchy(): AclEntityMetadataCollectionTransfer |
|
171
|
|
|
{ |
|
172
|
|
|
// SpyProductImage -> SpyProductImageSet -> SpyProduct |
|
173
|
|
|
$aclEntityMetadataCollectionTransfer = new AclEntityMetadataCollectionTransfer(); |
|
174
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
175
|
|
|
SpyProductImage::class, |
|
176
|
|
|
(new AclEntityMetadataTransfer()) |
|
177
|
|
|
->setEntityName(SpyProductImage::class) |
|
178
|
|
|
->setParent( |
|
179
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
180
|
|
|
->setEntityName(SpyProductImageSet::class) |
|
181
|
|
|
->setConnection( |
|
182
|
|
|
(new AclEntityParentConnectionMetadataTransfer()) |
|
183
|
|
|
->setPivotEntityName(SpyProductImageSetToProductImage::class) |
|
184
|
|
|
->setReference('fk_product_image') |
|
185
|
|
|
->setReferencedColumn('fk_product_image_set'), |
|
186
|
|
|
), |
|
187
|
|
|
) |
|
188
|
|
|
->setIsSubEntity(true), |
|
189
|
|
|
); |
|
190
|
|
|
|
|
191
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
192
|
|
|
SpyProductImageSet::class, |
|
193
|
|
|
(new AclEntityMetadataTransfer()) |
|
194
|
|
|
->setEntityName(SpyProductImageSet::class) |
|
195
|
|
|
->setParent( |
|
196
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
197
|
|
|
->setEntityName(SpyProduct::class), |
|
198
|
|
|
) |
|
199
|
|
|
->setIsSubEntity(true), |
|
200
|
|
|
); |
|
201
|
|
|
|
|
202
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
203
|
|
|
SpyProduct::class, |
|
204
|
|
|
(new AclEntityMetadataTransfer())->setEntityName(SpyProduct::class), |
|
205
|
|
|
); |
|
206
|
|
|
|
|
207
|
|
|
return $aclEntityMetadataCollectionTransfer; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer |
|
212
|
|
|
*/ |
|
213
|
|
|
public function createProductAbstractMerchantMetadataHierarchy(): AclEntityMetadataCollectionTransfer |
|
214
|
|
|
{ |
|
215
|
|
|
// SpyProductAbstract -> SpyMerchantProductAbstract -> SpyMerchant |
|
216
|
|
|
$aclEntityMetadataCollectionTransfer = new AclEntityMetadataCollectionTransfer(); |
|
217
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
218
|
|
|
SpyProductAbstract::class, |
|
219
|
|
|
(new AclEntityMetadataTransfer()) |
|
220
|
|
|
->setEntityName(SpyProductAbstract::class) |
|
221
|
|
|
->setParent( |
|
222
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
223
|
|
|
->setEntityName(SpyMerchantProductAbstract::class), |
|
224
|
|
|
), |
|
225
|
|
|
); |
|
226
|
|
|
|
|
227
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
228
|
|
|
SpyMerchantProductAbstract::class, |
|
229
|
|
|
(new AclEntityMetadataTransfer()) |
|
230
|
|
|
->setEntityName(SpyMerchantProductAbstract::class) |
|
231
|
|
|
->setParent( |
|
232
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
233
|
|
|
->setEntityName(SpyMerchant::class), |
|
234
|
|
|
), |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
238
|
|
|
SpyMerchant::class, |
|
239
|
|
|
(new AclEntityMetadataTransfer()) |
|
240
|
|
|
->setEntityName(SpyMerchant::class) |
|
241
|
|
|
->setHasSegmentTable(true), |
|
242
|
|
|
); |
|
243
|
|
|
|
|
244
|
|
|
return $aclEntityMetadataCollectionTransfer; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @return \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer |
|
249
|
|
|
*/ |
|
250
|
|
|
public function createProductOfferMetadataHierarchy(): AclEntityMetadataCollectionTransfer |
|
251
|
|
|
{ |
|
252
|
|
|
// SpyProductOffer -> SpyMerchant |
|
253
|
|
|
$aclEntityMetadataCollectionTransfer = new AclEntityMetadataCollectionTransfer(); |
|
254
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
255
|
|
|
SpyProductOffer::class, |
|
256
|
|
|
(new AclEntityMetadataTransfer()) |
|
257
|
|
|
->setEntityName(SpyProductOffer::class) |
|
258
|
|
|
->setParent( |
|
259
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
260
|
|
|
->setEntityName(SpyMerchant::class) |
|
261
|
|
|
->setConnection( |
|
262
|
|
|
(new AclEntityParentConnectionMetadataTransfer()) |
|
263
|
|
|
->setReference('merchant_reference') |
|
264
|
|
|
->setReferencedColumn('merchant_reference'), |
|
265
|
|
|
), |
|
266
|
|
|
), |
|
267
|
|
|
); |
|
268
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
269
|
|
|
SpyMerchant::class, |
|
270
|
|
|
(new AclEntityMetadataTransfer()) |
|
271
|
|
|
->setEntityName(SpyMerchant::class), |
|
272
|
|
|
); |
|
273
|
|
|
|
|
274
|
|
|
return $aclEntityMetadataCollectionTransfer; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @return \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer |
|
279
|
|
|
*/ |
|
280
|
|
|
public function createProductOfferMerchantHierarchy(): AclEntityMetadataCollectionTransfer |
|
281
|
|
|
{ |
|
282
|
|
|
$aclEntityMetadataCollectionTransfer = new AclEntityMetadataCollectionTransfer(); |
|
283
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
284
|
|
|
SpyProductOffer::class, |
|
285
|
|
|
(new AclEntityMetadataTransfer()) |
|
286
|
|
|
->setEntityName(SpyProductOffer::class) |
|
287
|
|
|
->setParent( |
|
288
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
289
|
|
|
->setEntityName(SpyMerchant::class) |
|
290
|
|
|
->setConnection( |
|
291
|
|
|
(new AclEntityParentConnectionMetadataTransfer()) |
|
292
|
|
|
->setReference('merchant_reference') |
|
293
|
|
|
->setReferencedColumn('merchant_reference'), |
|
294
|
|
|
), |
|
295
|
|
|
), |
|
296
|
|
|
); |
|
297
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
298
|
|
|
SpyMerchant::class, |
|
299
|
|
|
(new AclEntityMetadataTransfer())->setEntityName(SpyMerchant::class), |
|
300
|
|
|
); |
|
301
|
|
|
|
|
302
|
|
|
return $aclEntityMetadataCollectionTransfer; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* @return \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer |
|
307
|
|
|
*/ |
|
308
|
|
|
public function createMerchantCategoryMerchantHierarchy(): AclEntityMetadataCollectionTransfer |
|
309
|
|
|
{ |
|
310
|
|
|
$aclEntityMetadataCollectionTransfer = new AclEntityMetadataCollectionTransfer(); |
|
311
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
312
|
|
|
SpyMerchantCategory::class, |
|
313
|
|
|
(new AclEntityMetadataTransfer()) |
|
314
|
|
|
->setEntityName(SpyMerchantCategory::class) |
|
315
|
|
|
->setParent( |
|
316
|
|
|
(new AclEntityParentMetadataTransfer()) |
|
317
|
|
|
->setEntityName(SpyMerchant::class), |
|
318
|
|
|
), |
|
319
|
|
|
); |
|
320
|
|
|
$aclEntityMetadataCollectionTransfer->addAclEntityMetadata( |
|
321
|
|
|
SpyMerchant::class, |
|
322
|
|
|
(new AclEntityMetadataTransfer())->setEntityName(SpyMerchant::class), |
|
323
|
|
|
); |
|
324
|
|
|
|
|
325
|
|
|
return $aclEntityMetadataCollectionTransfer; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return \Spryker\Zed\AclEntityExtension\Dependency\Plugin\AclEntityMetadataConfigExpanderPluginInterface |
|
330
|
|
|
*/ |
|
331
|
|
|
public function getProductAbstractMerchantAclEntityMetadataConfigExpanderPlugin(): AclEntityMetadataConfigExpanderPluginInterface |
|
332
|
|
|
{ |
|
333
|
|
|
return new AclEntityMetadataConfigExpanderPluginMock(); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param \Generated\Shared\Transfer\RolesTransfer $rolesTransfer |
|
338
|
|
|
* @param \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer|null $aclEntityMetadataCollectionTransfer |
|
339
|
|
|
* @param \Spryker\Zed\Kernel\AbstractBundleConfig|null $bundleConfig |
|
340
|
|
|
* |
|
341
|
|
|
* @return \Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclQueryDirectorInterface |
|
342
|
|
|
*/ |
|
343
|
|
|
public function createAclQueryDirector( |
|
344
|
|
|
RolesTransfer $rolesTransfer, |
|
345
|
|
|
?AclEntityMetadataCollectionTransfer $aclEntityMetadataCollectionTransfer = null, |
|
346
|
|
|
?AbstractBundleConfig $bundleConfig = null, |
|
347
|
|
|
): AclQueryDirectorInterface { |
|
348
|
|
|
$factory = new AclEntityPersistenceFactory(); |
|
349
|
|
|
if ($bundleConfig) { |
|
350
|
|
|
$factory->setConfig($bundleConfig); |
|
351
|
|
|
} |
|
352
|
|
|
$aclEntityMetadataCollectionTransfer = $aclEntityMetadataCollectionTransfer ?: new AclEntityMetadataCollectionTransfer(); |
|
353
|
|
|
$aclEntityConfigTransfer = new AclEntityMetadataConfigTransfer(); |
|
354
|
|
|
$aclEntityConfigTransfer->setAclEntityMetadataCollection($aclEntityMetadataCollectionTransfer); |
|
355
|
|
|
|
|
356
|
|
|
return new AclQueryDirector( |
|
357
|
|
|
$factory->createAclJoinDirector($aclEntityConfigTransfer), |
|
358
|
|
|
new AclEntityRuleProvider($this->getAclRoleProviderMock($rolesTransfer), new AclEntityRepository()), |
|
359
|
|
|
$factory->createAclQueryScopeResolver($aclEntityConfigTransfer), |
|
360
|
|
|
$factory->createAclEntityMetadataReader($aclEntityConfigTransfer), |
|
361
|
|
|
$factory->createAclQueryExpander($aclEntityConfigTransfer), |
|
362
|
|
|
$factory->createAclEntityQueryMerger(), |
|
363
|
|
|
$this->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer, $bundleConfig), |
|
364
|
|
|
); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* @param \Generated\Shared\Transfer\RolesTransfer $rolesTransfer |
|
369
|
|
|
* @param \Generated\Shared\Transfer\AclEntityMetadataCollectionTransfer|null $aclEntityMetadataCollectionTransfer |
|
370
|
|
|
* @param \Spryker\Zed\Kernel\AbstractBundleConfig|null $bundleConfig |
|
371
|
|
|
* |
|
372
|
|
|
* @return \Spryker\Zed\AclEntity\Persistence\Propel\AclDirector\AclModelDirectorInterface |
|
373
|
|
|
*/ |
|
374
|
|
|
public function createAclModelDirector( |
|
375
|
|
|
RolesTransfer $rolesTransfer, |
|
376
|
|
|
?AclEntityMetadataCollectionTransfer $aclEntityMetadataCollectionTransfer = null, |
|
377
|
|
|
?AbstractBundleConfig $bundleConfig = null, |
|
378
|
|
|
): AclModelDirectorInterface { |
|
379
|
|
|
$factory = new AclEntityPersistenceFactory(); |
|
380
|
|
|
if ($bundleConfig) { |
|
381
|
|
|
$factory->setConfig($bundleConfig); |
|
382
|
|
|
} |
|
383
|
|
|
$aclEntityMetadataCollectionTransfer = $aclEntityMetadataCollectionTransfer ?: new AclEntityMetadataCollectionTransfer(); |
|
384
|
|
|
$aclEntityMetadataConfigTransfer = new AclEntityMetadataConfigTransfer(); |
|
385
|
|
|
$aclEntityMetadataConfigTransfer->setAclEntityMetadataCollection($aclEntityMetadataCollectionTransfer); |
|
386
|
|
|
|
|
387
|
|
|
return new AclModelDirector( |
|
388
|
|
|
$factory->createAclEntityMetadataReader($aclEntityMetadataConfigTransfer), |
|
389
|
|
|
new AclEntityRuleProvider($this->getAclRoleProviderMock($rolesTransfer), new AclEntityRepository()), |
|
390
|
|
|
$factory->createAclModelScopeResolver($aclEntityMetadataConfigTransfer), |
|
391
|
|
|
$factory->createAclRelationReader($aclEntityMetadataConfigTransfer), |
|
392
|
|
|
$factory->getPropelServiceContainer(), |
|
393
|
|
|
); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* @param \Generated\Shared\Transfer\MerchantTransfer $merchantTransfer |
|
398
|
|
|
* @param \Generated\Shared\Transfer\RoleTransfer $roleTransfer |
|
399
|
|
|
* |
|
400
|
|
|
* @return void |
|
401
|
|
|
*/ |
|
402
|
|
|
public function createMerchantCategoryRules( |
|
403
|
|
|
MerchantTransfer $merchantTransfer, |
|
404
|
|
|
RoleTransfer $roleTransfer, |
|
405
|
|
|
): void { |
|
406
|
|
|
$aclEntitySegmentMerchant = $this->haveAclEntitySegment( |
|
407
|
|
|
[ |
|
408
|
|
|
AclEntitySegmentRequestTransfer::NAME => static::ACL_ENTITY_SEGMENT_1_NAME, |
|
409
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => static::ACL_ENTITY_SEGMENT_1_REFERENCE, |
|
410
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
|
411
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
|
412
|
|
|
], |
|
413
|
|
|
); |
|
414
|
|
|
$this->haveAclEntityRule( |
|
415
|
|
|
[ |
|
416
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
417
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchantCategory::class, |
|
418
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_INHERITED, |
|
419
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
420
|
|
|
], |
|
421
|
|
|
); |
|
422
|
|
|
$this->haveAclEntityRule( |
|
423
|
|
|
[ |
|
424
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
425
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
|
426
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
|
427
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
428
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $aclEntitySegmentMerchant->getIdAclEntitySegmentOrFail(), |
|
429
|
|
|
], |
|
430
|
|
|
); |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* @param \Generated\Shared\Transfer\MerchantTransfer $merchantTransfer |
|
435
|
|
|
* @param \Generated\Shared\Transfer\RoleTransfer $roleTransfer |
|
436
|
|
|
* |
|
437
|
|
|
* @return void |
|
438
|
|
|
*/ |
|
439
|
|
|
public function createProductOfferRules( |
|
440
|
|
|
MerchantTransfer $merchantTransfer, |
|
441
|
|
|
RoleTransfer $roleTransfer, |
|
442
|
|
|
): void { |
|
443
|
|
|
$aclEntitySegmentMerchant = $this->haveAclEntitySegment( |
|
444
|
|
|
[ |
|
445
|
|
|
AclEntitySegmentRequestTransfer::NAME => static::ACL_ENTITY_SEGMENT_1_NAME, |
|
446
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => static::ACL_ENTITY_SEGMENT_1_REFERENCE, |
|
447
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
|
448
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
|
449
|
|
|
], |
|
450
|
|
|
); |
|
451
|
|
|
$this->haveAclEntityRule( |
|
452
|
|
|
[ |
|
453
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
454
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductOffer::class, |
|
455
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_INHERITED, |
|
456
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
457
|
|
|
], |
|
458
|
|
|
); |
|
459
|
|
|
$this->haveAclEntityRule( |
|
460
|
|
|
[ |
|
461
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
462
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
|
463
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
|
464
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
465
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $aclEntitySegmentMerchant->getIdAclEntitySegmentOrFail(), |
|
466
|
|
|
], |
|
467
|
|
|
); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* @param \Generated\Shared\Transfer\MerchantTransfer $merchantTransfer |
|
472
|
|
|
* @param \Generated\Shared\Transfer\RoleTransfer $roleTransfer |
|
473
|
|
|
* |
|
474
|
|
|
* @return void |
|
475
|
|
|
*/ |
|
476
|
|
|
public function createProductOfferManagerRules(MerchantTransfer $merchantTransfer, RoleTransfer $roleTransfer): void |
|
477
|
|
|
{ |
|
478
|
|
|
$aclEntitySegmentMerchantTransfer = $this->haveAclEntitySegment( |
|
479
|
|
|
[ |
|
480
|
|
|
AclEntitySegmentRequestTransfer::NAME => static::ACL_ENTITY_SEGMENT_1_NAME, |
|
481
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => static::ACL_ENTITY_SEGMENT_1_REFERENCE, |
|
482
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
|
483
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
|
484
|
|
|
], |
|
485
|
|
|
); |
|
486
|
|
|
$this->haveAclEntityRule( |
|
487
|
|
|
[ |
|
488
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
489
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductOffer::class, |
|
490
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_INHERITED, |
|
491
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CRUD, |
|
492
|
|
|
], |
|
493
|
|
|
); |
|
494
|
|
|
$this->haveAclEntityRule( |
|
495
|
|
|
[ |
|
496
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
497
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
|
498
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
|
499
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
500
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $aclEntitySegmentMerchantTransfer |
|
501
|
|
|
->getIdAclEntitySegmentOrFail(), |
|
502
|
|
|
], |
|
503
|
|
|
); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* @param \Generated\Shared\Transfer\MerchantTransfer $merchantTransfer |
|
508
|
|
|
* @param \Generated\Shared\Transfer\RoleTransfer $roleTransfer |
|
509
|
|
|
* |
|
510
|
|
|
* @return void |
|
511
|
|
|
*/ |
|
512
|
|
|
public function createProductOfferViewerRules(MerchantTransfer $merchantTransfer, RoleTransfer $roleTransfer): void |
|
513
|
|
|
{ |
|
514
|
|
|
$aclEntitySegmentMerchantTransfer = $this->haveAclEntitySegment( |
|
515
|
|
|
[ |
|
516
|
|
|
AclEntitySegmentRequestTransfer::NAME => static::ACL_ENTITY_SEGMENT_2_NAME, |
|
517
|
|
|
AclEntitySegmentRequestTransfer::REFERENCE => static::ACL_ENTITY_SEGMENT_2_REFERENCE, |
|
518
|
|
|
AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class, |
|
519
|
|
|
AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()], |
|
520
|
|
|
], |
|
521
|
|
|
); |
|
522
|
|
|
|
|
523
|
|
|
$this->haveAclEntityRule( |
|
524
|
|
|
[ |
|
525
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
526
|
|
|
AclEntityRuleTransfer::ENTITY => SpyProductOffer::class, |
|
527
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_INHERITED, |
|
528
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
529
|
|
|
], |
|
530
|
|
|
); |
|
531
|
|
|
$this->haveAclEntityRule( |
|
532
|
|
|
[ |
|
533
|
|
|
AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRoleOrFail(), |
|
534
|
|
|
AclEntityRuleTransfer::ENTITY => SpyMerchant::class, |
|
535
|
|
|
AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT, |
|
536
|
|
|
AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_READ, |
|
537
|
|
|
AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $aclEntitySegmentMerchantTransfer |
|
538
|
|
|
->getIdAclEntitySegmentOrFail(), |
|
539
|
|
|
], |
|
540
|
|
|
); |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
/** |
|
544
|
|
|
* @return \Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToUserFacadeBridgeInterface |
|
545
|
|
|
*/ |
|
546
|
|
|
protected function getUserFacadeMock(): AclEntityToUserFacadeBridgeInterface |
|
547
|
|
|
{ |
|
548
|
|
|
$this->mockFacadeMethod('hasCurrentUser', true, 'User'); |
|
549
|
|
|
$this->mockFacadeMethod('getCurrentUser', (new UserTransfer())->setIdUser(1), 'User'); |
|
550
|
|
|
|
|
551
|
|
|
/** @var \Spryker\Zed\User\Business\UserFacadeInterface $userFacade */ |
|
552
|
|
|
$userFacade = $this->getFacade('User'); |
|
553
|
|
|
|
|
554
|
|
|
return new AclEntityToUserFacadeBridge($userFacade); |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
/** |
|
558
|
|
|
* @param \Generated\Shared\Transfer\RolesTransfer $rolesTransfer |
|
559
|
|
|
* |
|
560
|
|
|
* @return \Spryker\Zed\AclEntity\Dependency\Facade\AclEntityToAclFacadeBridgeInterface |
|
561
|
|
|
*/ |
|
562
|
|
|
protected function getAclFacadeMock(RolesTransfer $rolesTransfer): AclEntityToAclFacadeBridgeInterface |
|
563
|
|
|
{ |
|
564
|
|
|
/** @var \Spryker\Zed\Acl\Business\AclFacadeInterface $aclFacade */ |
|
565
|
|
|
$aclFacade = $this->mockFacadeMethod('getUserRoles', $rolesTransfer, 'Acl'); |
|
566
|
|
|
|
|
567
|
|
|
return new AclEntityToAclFacadeBridge($aclFacade); |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
/** |
|
571
|
|
|
* @param int $idProductAbstract |
|
572
|
|
|
* |
|
573
|
|
|
* @return \Orm\Zed\Product\Persistence\SpyProductAbstract|null |
|
574
|
|
|
*/ |
|
575
|
|
|
public function findProductAbstractByIdProductAbstract(int $idProductAbstract): ?SpyProductAbstract |
|
576
|
|
|
{ |
|
577
|
|
|
return SpyProductAbstractQuery::create()->filterByPrimaryKey($idProductAbstract)->findOne(); |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
/** |
|
581
|
|
|
* @param int $idProductImage |
|
582
|
|
|
* |
|
583
|
|
|
* @return \Orm\Zed\ProductImage\Persistence\SpyProductImage|null |
|
584
|
|
|
*/ |
|
585
|
|
|
public function findProductImageByIdProductImage(int $idProductImage): ?SpyProductImage |
|
586
|
|
|
{ |
|
587
|
|
|
return SpyProductImageQuery::create()->filterByPrimaryKey($idProductImage)->findOne(); |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
/** |
|
591
|
|
|
* @param int $idMerchant |
|
592
|
|
|
* |
|
593
|
|
|
* @return \Orm\Zed\Merchant\Persistence\SpyMerchant|null |
|
594
|
|
|
*/ |
|
595
|
|
|
public function findMerchantByIdMerchant(int $idMerchant): ?SpyMerchant |
|
596
|
|
|
{ |
|
597
|
|
|
return SpyMerchantQuery::create()->filterByPrimaryKey($idMerchant)->findOne(); |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* @param int $idProduct |
|
602
|
|
|
* |
|
603
|
|
|
* @return \Orm\Zed\Product\Persistence\SpyProduct|null |
|
604
|
|
|
*/ |
|
605
|
|
|
public function findProductConcreteByIdProduct(int $idProduct): ?SpyProduct |
|
606
|
|
|
{ |
|
607
|
|
|
return SpyProductQuery::create()->filterByPrimaryKey($idProduct)->findOne(); |
|
608
|
|
|
} |
|
609
|
|
|
|
|
610
|
|
|
/** |
|
611
|
|
|
* @param int $idProductOffer |
|
612
|
|
|
* |
|
613
|
|
|
* @return \Orm\Zed\ProductOffer\Persistence\SpyProductOffer|null |
|
614
|
|
|
*/ |
|
615
|
|
|
public function findProductOfferByIdProductOffer(int $idProductOffer): ?SpyProductOffer |
|
616
|
|
|
{ |
|
617
|
|
|
return SpyProductOfferQuery::create()->filterByPrimaryKey($idProductOffer)->findOne(); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
/** |
|
621
|
|
|
* @return \Generated\Shared\Transfer\MerchantProductTransfer |
|
622
|
|
|
*/ |
|
623
|
|
|
public function createMerchantProduct(): MerchantProductTransfer |
|
624
|
|
|
{ |
|
625
|
|
|
$merchantTransfer = $this->haveMerchant(); |
|
626
|
|
|
$productConcreteTransfer = $this->haveProduct(); |
|
627
|
|
|
|
|
628
|
|
|
return $this->haveMerchantProduct( |
|
629
|
|
|
[ |
|
630
|
|
|
MerchantProductTransfer::ID_MERCHANT => $merchantTransfer->getIdMerchantOrFail(), |
|
631
|
|
|
MerchantProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstractOrFail(), |
|
632
|
|
|
], |
|
633
|
|
|
); |
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
|
|
/** |
|
637
|
|
|
* @param string $string |
|
638
|
|
|
* |
|
639
|
|
|
* @return string |
|
640
|
|
|
*/ |
|
641
|
|
|
public function purify(string $string): string |
|
642
|
|
|
{ |
|
643
|
|
|
return str_replace(['`', '"'], '', strtolower($string)); |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
/** |
|
647
|
|
|
* @param \Generated\Shared\Transfer\RolesTransfer $rolesTransfer |
|
648
|
|
|
* |
|
649
|
|
|
* @return \Spryker\Zed\AclEntity\Persistence\Propel\Provider\AclRoleProviderInterface |
|
650
|
|
|
*/ |
|
651
|
|
|
protected function getAclRoleProviderMock(RolesTransfer $rolesTransfer): AclRoleProviderInterface |
|
652
|
|
|
{ |
|
653
|
|
|
return Stub::make( |
|
654
|
|
|
AclRoleProvider::class, |
|
655
|
|
|
[ |
|
656
|
|
|
'userFacade' => $this->getUserFacadeMock(), |
|
657
|
|
|
'aclFacade' => $this->getAclFacadeMock($rolesTransfer), |
|
658
|
|
|
'cache' => null, |
|
659
|
|
|
], |
|
660
|
|
|
); |
|
661
|
|
|
} |
|
662
|
|
|
} |
|
663
|
|
|
|