testInspectUpdateWithUpdatePermissionInGlobalLevel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 0
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\AclEntitySegmentCriteriaTransfer;
17
use Generated\Shared\Transfer\AclEntitySegmentRequestTransfer;
18
use Generated\Shared\Transfer\AclRoleCriteriaTransfer;
19
use Generated\Shared\Transfer\RolesTransfer;
20
use Generated\Shared\Transfer\RoleTransfer;
21
use Orm\Zed\Merchant\Persistence\SpyMerchant;
22
use Orm\Zed\Product\Persistence\SpyProduct;
23
use Orm\Zed\Product\Persistence\SpyProductQuery;
24
use Orm\Zed\Store\Persistence\SpyStore;
25
use Pyz\Zed\Merchant\MerchantDependencyProvider;
26
use PyzTest\Zed\AclEntity\AclQueryDirectorTester;
27
use Spryker\Shared\AclEntity\AclEntityConstants;
28
use Spryker\Zed\AclEntity\Persistence\Exception\OperationNotAuthorizedException;
29
30
/**
31
 * Auto-generated group annotations
32
 *
33
 * @group PyzTest
34
 * @group Zed
35
 * @group AclEntity
36
 * @group Persistence
37
 * @group AclDirector
38
 * @group DefaultAclQueryScopeTest
39
 * Add your own group annotations below this line
40
 */
41
class DefaultAclQueryScopeTest extends Unit
42
{
43
    /**
44
     * @var \PyzTest\Zed\AclEntity\AclQueryDirectorTester
45
     */
46
    protected $tester;
47
48
    /**
49
     * @return void
50
     */
51
    protected function setUp(): void
52
    {
53
        parent::setUp();
54
55
        $this->tester->setDependency(MerchantDependencyProvider::PLUGINS_MERCHANT_POST_CREATE, []);
56
57
        $this->tester->deleteRoles(
58
            (new AclRoleCriteriaTransfer())->setNames([AclQueryDirectorTester::ACL_ROLE_1_NAME]),
59
        );
60
61
        $this->tester->cleanCache();
62
    }
63
64
    /**
65
     * @group AclEntitySegmentScope
66
     * @group AclEntityUpdate
67
     *
68
     * @return void
69
     */
70
    public function testSegmentScopePrecedenceDefaultScope(): void
71
    {
72
        // Arrange
73
        $this->tester->deleteAclEntitySegments(
74
            (new AclEntitySegmentCriteriaTransfer())
75
                ->setReferences([AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_REFERENCE]),
76
        );
77
78
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
79
        $merchantTransfer = $this->tester->haveMerchant();
80
        $aclEntitySegmentTransfer = $this->tester->haveAclEntitySegment([
81
            AclEntitySegmentRequestTransfer::NAME => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_NAME,
82
            AclEntitySegmentRequestTransfer::REFERENCE => AclQueryDirectorTester::ACL_ENTITY_SEGMENT_1_REFERENCE,
83
            AclEntitySegmentRequestTransfer::ENTITY => SpyMerchant::class,
84
            AclEntitySegmentRequestTransfer::ENTITY_IDS => [$merchantTransfer->getIdMerchantOrFail()],
85
        ]);
86
87
        $this->tester->haveAclEntityRule(
88
            [
89
                AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_SEGMENT,
90
                AclEntityRuleTransfer::ENTITY => SpyMerchant::class,
91
                AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(),
92
                AclEntityRuleTransfer::ID_ACL_ENTITY_SEGMENT => $aclEntitySegmentTransfer->getIdAclEntitySegment(),
93
                AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CRUD,
94
            ],
95
        );
96
97
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
98
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer);
99
100
        // Act, Assert
101
        $aclModelDirector->inspectUpdate(
102
            $this->tester->findMerchantByIdMerchant($merchantTransfer->getIdMerchantOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findMerch...>getIdMerchantOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectUpdate() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
            /** @scrutinizer ignore-type */ $this->tester->findMerchantByIdMerchant($merchantTransfer->getIdMerchantOrFail()),
Loading history...
103
        );
104
    }
105
106
    /**
107
     * @group AclEntityApplyAclRules
108
     *
109
     * @return void
110
     */
111
    public function testApplyAclRulesWithReadPermissionOnEntityLevel(): void
112
    {
113
        // Arrange
114
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
115
        $productTransfer = $this->tester->haveProduct();
116
117
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
118
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
119
            ->addAclEntityMetadata(
120
                SpyProduct::class,
121
                (new AclEntityMetadataTransfer())
122
                    ->setEntityName(SpyProduct::class)
123
                    ->setDefaultGlobalOperationMask(AclEntityConstants::OPERATION_MASK_READ),
124
            );
125
        $aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
126
        $query = SpyProductQuery::create()->filterByIdProduct($productTransfer->getIdProductConcrete());
127
128
        // Act
129
        $aclQueryDirector->applyAclRuleOnSelectQuery($query);
130
131
        // Assert
132
        $this->assertSame(1, $query->count());
133
    }
134
135
    /**
136
     * @group AclEntityCreate
137
     *
138
     * @return void
139
     */
140
    public function testInspectCreateWithCreatePermissionInEntityLevel(): void
141
    {
142
        // Arrange
143
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
144
145
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
146
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
147
            ->addAclEntityMetadata(
148
                SpyProduct::class,
149
                (new AclEntityMetadataTransfer())
150
                    ->setEntityName(SpyProduct::class)
151
                    ->setDefaultGlobalOperationMask(
152
                        AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_CREATE,
153
                    ),
154
            );
155
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
156
157
        // Act, Assert
158
        $aclModelDirector->inspectCreate(new SpyProduct());
159
    }
160
161
    /**
162
     * @group AclEntityUpdate
163
     *
164
     * @return void
165
     */
166
    public function testInspectUpdateWithUpdatePermissionInEntityLevel(): void
167
    {
168
        // Arrange
169
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
170
        $productTransfer = $this->tester->haveProduct();
171
172
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
173
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
174
            ->addAclEntityMetadata(
175
                SpyProduct::class,
176
                (new AclEntityMetadataTransfer())
177
                    ->setEntityName(SpyProduct::class)
178
                    ->setDefaultGlobalOperationMask(AclEntityConstants::OPERATION_MASK_UPDATE),
179
            );
180
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
181
182
        // Act, Assert
183
        $aclModelDirector->inspectUpdate(
184
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectUpdate() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

184
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
185
        );
186
    }
187
188
    /**
189
     * @group AclEntityDelete
190
     *
191
     * @return void
192
     */
193
    public function testInspectDeleteWithDeletePermissionInEntityLevel(): void
194
    {
195
        // Arrange
196
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
197
        $productTransfer = $this->tester->haveProduct();
198
199
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
200
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
201
            ->addAclEntityMetadata(
202
                SpyProduct::class,
203
                (new AclEntityMetadataTransfer())
204
                    ->setEntityName(SpyProduct::class)
205
                    ->setDefaultGlobalOperationMask(
206
                        AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_DELETE,
207
                    ),
208
            );
209
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
210
211
        // Act, Assert
212
        $aclModelDirector->inspectDelete(
213
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectDelete() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

213
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
214
        );
215
    }
216
217
    /**
218
     * @group AclEntityApplyAclRules
219
     *
220
     * @return void
221
     */
222
    public function testApplyAclRulesWithReadPermissionInGlobalLevel(): void
223
    {
224
        // Arrange
225
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
226
        $productTransfer = $this->tester->haveProduct();
227
228
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
229
        $aclEntityConfig = $this->tester->mockConfigMethod(
230
            'getDefaultGlobalOperationMask',
231
            AclEntityConstants::OPERATION_MASK_READ,
232
        );
233
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
234
        $aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer, null, $aclEntityConfig);
235
236
        $query = SpyProductQuery::create()->filterByIdProduct($productTransfer->getIdProductConcrete());
237
238
        // Act
239
        $aclQueryDirector->applyAclRuleOnSelectQuery($query);
240
241
        // Assert
242
        $this->assertSame(1, $query->count());
243
    }
244
245
    /**
246
     * @group AclEntityCreate
247
     *
248
     * @return void
249
     */
250
    public function testInspectCreateWithCreatePermissionInGlobalLevel(): void
251
    {
252
        // Arrange
253
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
254
255
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
256
        $aclEntityConfig = $this->tester->mockConfigMethod(
257
            'getDefaultGlobalOperationMask',
258
            AclEntityConstants::OPERATION_MASK_CREATE,
259
        );
260
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
261
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, null, $aclEntityConfig);
262
263
        // Act, Assert
264
        $aclModelDirector->inspectCreate(new SpyProduct());
265
    }
266
267
    /**
268
     * @group AclEntityUpdate
269
     *
270
     * @return void
271
     */
272
    public function testInspectUpdateWithUpdatePermissionInGlobalLevel(): void
273
    {
274
        // Arrange
275
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
276
        $productTransfer = $this->tester->haveProduct();
277
278
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
279
        $aclEntityConfig = $this->tester->mockConfigMethod(
280
            'getDefaultGlobalOperationMask',
281
            AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_UPDATE,
282
        );
283
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
284
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, null, $aclEntityConfig);
285
286
        // Act, Assert
287
        $aclModelDirector->inspectUpdate(
288
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectUpdate() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

288
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
289
        );
290
    }
291
292
    /**
293
     * @group AclEntityDelete
294
     *
295
     * @return void
296
     */
297
    public function testInspectDeleteWithDeletePermissionInGlobalLevel(): void
298
    {
299
        // Arrange
300
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
301
        $productTransfer = $this->tester->haveProduct();
302
303
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
304
        $aclEntityConfig = $this->tester->mockConfigMethod(
305
            'getDefaultGlobalOperationMask',
306
            AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_DELETE,
307
        );
308
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
309
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, null, $aclEntityConfig);
310
311
        // Act, Assert
312
        $aclModelDirector->inspectDelete(
313
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectDelete() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

313
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
314
        );
315
    }
316
317
    /**
318
     * @group AclEntityApplyAclRules
319
     *
320
     * @return void
321
     */
322
    public function testApplyAclRulesWithNoReadPermissionInEntityLevel(): void
323
    {
324
        // Arrange
325
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
326
        $productTransfer = $this->tester->haveProduct();
327
328
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
329
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
330
            ->addAclEntityMetadata(
331
                SpyProduct::class,
332
                (new AclEntityMetadataTransfer())
333
                    ->setEntityName(SpyProduct::class)
334
                    ->setDefaultGlobalOperationMask(
335
                        AclEntityConstants::OPERATION_MASK_CREATE | AclEntityConstants::OPERATION_MASK_DELETE,
336
                    ),
337
            );
338
        $aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
339
        $query = SpyProductQuery::create()->filterByIdProduct($productTransfer->getIdProductConcrete());
340
341
        // Act
342
        $aclQueryDirector->applyAclRuleOnSelectQuery($query);
343
344
        // Assert
345
        $this->assertSame(0, $query->count());
346
        $this->assertStringContainsString(
347
            'id_product is null',
348
            $this->tester->purify($query->toString()),
349
        );
350
    }
351
352
    /**
353
     * @group AclEntityCreate
354
     *
355
     * @return void
356
     */
357
    public function testInspectCreateWithNoCreatePermissionInEntityLevel(): void
358
    {
359
        // Assert
360
        $this->expectException(OperationNotAuthorizedException::class);
361
        $this->expectExceptionMessage('Operation "create" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
362
363
        // Arrange
364
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
365
366
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
367
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
368
            ->addAclEntityMetadata(
369
                SpyProduct::class,
370
                (new AclEntityMetadataTransfer())
371
                    ->setEntityName(SpyProduct::class)
372
                    ->setDefaultGlobalOperationMask(
373
                        AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_DELETE,
374
                    ),
375
            );
376
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
377
378
        // Act
379
        $aclModelDirector->inspectCreate(new SpyProduct());
380
    }
381
382
    /**
383
     * @group AclEntityUpdate
384
     *
385
     * @return void
386
     */
387
    public function testInspectUpdateWithNoUpdatePermissionInEntityLevel(): void
388
    {
389
        // Assert
390
        $this->expectException(OperationNotAuthorizedException::class);
391
        $this->expectExceptionMessage('Operation "update" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
392
393
        // Arrange
394
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
395
        $productTransfer = $this->tester->haveProduct();
396
397
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
398
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
399
            ->addAclEntityMetadata(
400
                SpyProduct::class,
401
                (new AclEntityMetadataTransfer())
402
                    ->setEntityName(SpyProduct::class)
403
                    ->setDefaultGlobalOperationMask(AclEntityConstants::OPERATION_MASK_READ),
404
            );
405
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
406
407
        // Act
408
        $aclModelDirector->inspectUpdate(
409
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectUpdate() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

409
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
410
        );
411
    }
412
413
    /**
414
     * @group AclEntityDelete
415
     *
416
     * @return void
417
     */
418
    public function testInspectDeleteWithNoDeletePermissionInEntityLevel(): void
419
    {
420
        // Assert
421
        $this->expectException(OperationNotAuthorizedException::class);
422
        $this->expectExceptionMessage('Operation "delete" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
423
424
        // Arrange
425
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
426
        $productTransfer = $this->tester->haveProduct();
427
428
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
429
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
430
            ->addAclEntityMetadata(
431
                SpyProduct::class,
432
                (new AclEntityMetadataTransfer())
433
                    ->setEntityName(SpyProduct::class)
434
                    ->setDefaultGlobalOperationMask(
435
                        AclEntityConstants::OPERATION_MASK_CREATE | AclEntityConstants::OPERATION_MASK_READ,
436
                    ),
437
            );
438
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
439
440
        // Act
441
        $aclModelDirector->inspectDelete(
442
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectDelete() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

442
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
443
        );
444
    }
445
446
    /**
447
     * @group AclEntityApplyAclRules
448
     *
449
     * @return void
450
     */
451
    public function testApplyAclRulesWithNoReadPermissionInGlobalLevel(): void
452
    {
453
        // Arrange
454
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
455
        $productTransfer = $this->tester->haveProduct();
456
457
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
458
        $aclEntityConfig = $this->tester->mockConfigMethod(
459
            'getDefaultGlobalOperationMask',
460
            AclEntityConstants::OPERATION_MASK_CREATE | AclEntityConstants::OPERATION_MASK_DELETE,
461
        );
462
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
463
        $aclQueryDirector = $this->tester->createAclQueryDirector($rolesTransfer, null, $aclEntityConfig);
464
465
        $query = SpyProductQuery::create()->filterByIdProduct($productTransfer->getIdProductConcrete());
466
467
        // Act
468
        $aclQueryDirector->applyAclRuleOnSelectQuery($query);
469
470
        // Assert
471
        $this->assertSame(0, $query->count());
472
        $this->assertStringContainsString(
473
            'id_product is null',
474
            $this->tester->purify($query->toString()),
475
        );
476
    }
477
478
    /**
479
     * @group AclEntityCreate
480
     *
481
     * @return void
482
     */
483
    public function testInspectCreateWithNoCreatePermissionInGlobalLevel(): void
484
    {
485
        // Assert
486
        $this->expectException(OperationNotAuthorizedException::class);
487
        $this->expectExceptionMessage('Operation "create" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
488
489
        // Arrange
490
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
491
492
        $this->tester->mockConfigMethod(
493
            'getDefaultGlobalOperationMask',
494
            AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_DELETE,
495
        );
496
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
497
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer);
498
499
        // Act
500
        $aclModelDirector->inspectCreate(new SpyProduct());
501
    }
502
503
    /**
504
     * @group AclEntityUpdate
505
     *
506
     * @return void
507
     */
508
    public function testInspectUpdateWithNoUpdatePermissionInGlobalLevel(): void
509
    {
510
        // Assert
511
        $this->expectException(OperationNotAuthorizedException::class);
512
        $this->expectExceptionMessage('Operation "update" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
513
514
        // Arrange
515
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
516
        $productTransfer = $this->tester->haveProduct();
517
518
        /** @var \Spryker\Zed\AclEntity\AclEntityConfig $aclEntityConfig */
519
        $aclEntityConfig = $this->tester->mockConfigMethod(
520
            'getDefaultGlobalOperationMask',
521
            AclEntityConstants::OPERATION_MASK_READ,
522
        );
523
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
524
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, null, $aclEntityConfig);
525
526
        // Act
527
        $aclModelDirector->inspectUpdate(
528
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectUpdate() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

528
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
529
        );
530
    }
531
532
    /**
533
     * @group AclEntityDelete
534
     *
535
     * @return void
536
     */
537
    public function testInspectDeleteWithNoDeletePermissionInGlobalLevel(): void
538
    {
539
        // Assert
540
        $this->expectException(OperationNotAuthorizedException::class);
541
        $this->expectExceptionMessage('Operation "delete" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
542
543
        // Arrange
544
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
545
        $productTransfer = $this->tester->haveProduct();
546
547
        $this->tester->mockConfigMethod(
548
            'getDefaultGlobalOperationMask',
549
            AclEntityConstants::OPERATION_MASK_CREATE | AclEntityConstants::OPERATION_MASK_READ,
550
        );
551
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
552
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer);
553
554
        // Act
555
        $aclModelDirector->inspectDelete(
556
            $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
0 ignored issues
show
Bug introduced by
It seems like $this->tester->findProdu...roductConcreteOrFail()) can also be of type null; however, parameter $entity of Spryker\Zed\AclEntity\Pe...rector::inspectDelete() does only seem to accept Propel\Runtime\ActiveRecord\ActiveRecordInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

556
            /** @scrutinizer ignore-type */ $this->tester->findProductConcreteByIdProduct($productTransfer->getIdProductConcreteOrFail()),
Loading history...
557
        );
558
    }
559
560
    /**
561
     * @group AclEntityCreate
562
     *
563
     * @return void
564
     */
565
    public function testOtherEntityGlobalScopeDefinitionDoesntInfluenceCurrentEntity(): void
566
    {
567
        // Assert
568
        $this->expectException(OperationNotAuthorizedException::class);
569
        $this->expectExceptionMessage('Operation "create" is restricted for Orm\Zed\Product\Persistence\SpyProduct');
570
571
        // Arrange
572
        $roleTransfer = $this->tester->haveRole([RoleTransfer::NAME => AclQueryDirectorTester::ACL_ROLE_1_NAME]);
573
        $this->tester->haveAclEntityRule(
574
            [
575
                AclEntityRuleTransfer::SCOPE => AclEntityConstants::SCOPE_GLOBAL,
576
                AclEntityRuleTransfer::ENTITY => SpyStore::class,
577
                AclEntityRuleTransfer::ID_ACL_ROLE => $roleTransfer->getIdAclRole(),
578
                AclEntityRuleTransfer::PERMISSION_MASK => AclEntityConstants::OPERATION_MASK_CREATE,
579
            ],
580
        );
581
582
        $rolesTransfer = (new RolesTransfer())->addRole($roleTransfer);
583
        $aclEntityMetadataCollectionTransfer = (new AclEntityMetadataCollectionTransfer())
584
            ->addAclEntityMetadata(
585
                SpyProduct::class,
586
                (new AclEntityMetadataTransfer())
587
                    ->setEntityName(SpyProduct::class)
588
                    ->setDefaultGlobalOperationMask(
589
                        AclEntityConstants::OPERATION_MASK_READ | AclEntityConstants::OPERATION_MASK_DELETE,
590
                    ),
591
            );
592
        $aclModelDirector = $this->tester->createAclModelDirector($rolesTransfer, $aclEntityMetadataCollectionTransfer);
593
594
        // Act, Assert
595
        $aclModelDirector->inspectCreate(new SpyProduct());
596
    }
597
}
598