Passed
Push — master ( cacbf1...74b6c9 )
by
unknown
34:14
created

testUpdateSspAssetCollection()   B

Complexity

Conditions 10
Paths 40

Size

Total Lines 58
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 34
nc 40
nop 3
dl 0
loc 58
rs 7.6666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerFeatureTest\Zed\SelfServicePortal\Business\Facade;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\CompanyBusinessUnitTransfer;
12
use Generated\Shared\Transfer\DashboardRequestTransfer;
13
use Generated\Shared\Transfer\DashboardResponseTransfer;
14
use Generated\Shared\Transfer\PaginationTransfer;
15
use Generated\Shared\Transfer\PermissionCollectionTransfer;
16
use Generated\Shared\Transfer\SortTransfer;
17
use Generated\Shared\Transfer\SspAssetBusinessUnitAssignmentTransfer;
18
use Generated\Shared\Transfer\SspAssetCollectionRequestTransfer;
19
use Generated\Shared\Transfer\SspAssetCollectionResponseTransfer;
20
use Generated\Shared\Transfer\SspAssetConditionsTransfer;
21
use Generated\Shared\Transfer\SspAssetCriteriaTransfer;
22
use Generated\Shared\Transfer\SspAssetIncludeTransfer;
23
use Generated\Shared\Transfer\SspAssetTransfer;
24
use Orm\Zed\CompanyBusinessUnit\Persistence\SpyCompanyBusinessUnitQuery;
25
use Orm\Zed\SelfServicePortal\Persistence\SpySspAssetQuery;
26
use Spryker\Zed\CompanyRole\Communication\Plugin\PermissionStoragePlugin;
27
use Spryker\Zed\FileManager\Dependency\Service\FileManagerToFileSystemServiceInterface;
28
use Spryker\Zed\FileManager\FileManagerDependencyProvider;
29
use SprykerFeature\Shared\SelfServicePortal\Plugin\Permission\ViewBusinessUnitSspAssetPermissionPlugin;
30
use SprykerFeature\Shared\SelfServicePortal\Plugin\Permission\ViewCompanySspAssetPermissionPlugin;
31
use SprykerFeature\Zed\SelfServicePortal\Business\SelfServicePortalFacade;
32
use SprykerFeature\Zed\SelfServicePortal\Communication\Plugin\SspDashboardManagement\SspAssetDashboardDataExpanderPlugin;
33
34
/**
35
 * @group SprykerFeatureTest
36
 * @group Zed
37
 * @group SelfServicePortal
38
 * @group Business
39
 * @group SspAssetManagementFacadeTest
40
 */
41
class SspAssetManagementFacadeTest extends Unit
42
{
43
    /**
44
     * @var string
45
     */
46
    protected const LOCALE_CURRENT = 'LOCALE_CURRENT';
47
48
    /**
49
     * @var string
50
     */
51
    public const PLUGINS_PERMISSION = 'PLUGINS_PERMISSION';
52
53
    /**
54
     * @var \SprykerFeatureTest\Zed\SelfServicePortal\SelfServicePortalBusinessTester
55
     */
56
    protected $tester;
57
58
    /**
59
     * @var \SprykerFeature\Zed\SelfServicePortal\Business\SelfServicePortalFacade
60
     */
61
    protected $selfServicePortalFacade;
62
63
    /**
64
     * @var \Generated\Shared\Transfer\CompanyBusinessUnitTransfer
65
     */
66
    protected CompanyBusinessUnitTransfer $companyBusinessUnit;
67
68
    protected function _before(): void
69
    {
70
        $this->selfServicePortalFacade = new SelfServicePortalFacade();
71
72
        $this->companyBusinessUnit = $this->tester->haveCompanyBusinessUnit([
73
            CompanyBusinessUnitTransfer::KEY => 'Test Company Business Unit',
74
            CompanyBusinessUnitTransfer::FK_COMPANY => $this->tester->haveCompany()->getIdCompany(),
75
        ]);
76
77
        $serviceFileSystemMock = $this->createMock(FileManagerToFileSystemServiceInterface::class);
78
        $serviceFileSystemMock->method('write')->willReturnCallback(function (): void {
79
        });
80
        $this->tester->setDependency(FileManagerDependencyProvider::SERVICE_FILE_SYSTEM, $serviceFileSystemMock);
81
        $this->tester->setDependency(static::LOCALE_CURRENT, 'en_US');
82
        $this->tester->preparePermissionStorageDependency(new PermissionStoragePlugin());
83
        $this->tester->setDependency(static::PLUGINS_PERMISSION, [
84
            new ViewCompanySspAssetPermissionPlugin(),
85
            new ViewBusinessUnitSspAssetPermissionPlugin(),
86
        ]);
87
    }
88
89
    /**
90
     * @dataProvider assetSuccessfulCollectionDataProvider
91
     *
92
     * @param array<mixed> $sspAssetData
93
     * @param int $expectedAssetCount
94
     * @param string $expectedName
95
     * @param array<string> $expectedValidationErrors
96
     *
97
     * @return void
98
     */
99
    public function testCreateSspAssetCollectionIsSuccessful(
100
        array $sspAssetData,
101
        int $expectedAssetCount,
102
        string $expectedName,
103
        array $expectedValidationErrors
104
    ): void {
105
        // Arrange
106
        $sspAssetTransfer = (new SspAssetTransfer())
107
            ->setName($sspAssetData['name'])
108
            ->setSerialNumber($sspAssetData['serialNumber'])
109
            ->setNote($sspAssetData['note']);
110
111
        if (!isset($sspAssetData['companyBusinessUnitNotSet']) || !$sspAssetData['companyBusinessUnitNotSet']) {
112
            $sspAssetTransfer->setCompanyBusinessUnit($this->companyBusinessUnit);
113
        }
114
115
        // Act
116
        $sspAssetCollectionResponseTransfer = $this->selfServicePortalFacade->createSspAssetCollection(
117
            (new SspAssetCollectionRequestTransfer())
118
                ->addSspAsset($sspAssetTransfer),
119
        );
120
121
        // Assert
122
        $this->assertInstanceOf(SspAssetCollectionResponseTransfer::class, $sspAssetCollectionResponseTransfer);
123
        $this->assertCount($expectedAssetCount, $sspAssetCollectionResponseTransfer->getSspAssets());
124
125
        if ($expectedAssetCount > 0) {
126
            $createdAssetTransfer = $sspAssetCollectionResponseTransfer->getSspAssets()->getIterator()->current();
127
            $this->assertNotNull($createdAssetTransfer->getIdSspAsset());
128
            $this->assertSame($expectedName, $createdAssetTransfer->getName());
129
        }
130
131
        $this->assertSame(
132
            $expectedValidationErrors,
133
            array_map(
134
                fn ($errorTransfer) => $errorTransfer->getMessage(),
135
                $sspAssetCollectionResponseTransfer->getErrors()->getArrayCopy(),
136
            ),
137
        );
138
    }
139
140
    /**
141
     * @dataProvider assetUpdateDataProvider
142
     *
143
     * @param array<string, mixed> $originalData
144
     * @param array<string, mixed> $updateData
145
     * @param array<string, mixed> $expectedData
146
     *
147
     * @return void
148
     */
149
    public function testUpdateSspAssetCollection(
150
        array $originalData,
151
        array $updateData,
152
        array $expectedData
153
    ): void {
154
        // Arrange
155
        $originalData['generateImage'] = $updateData['generateImage'] ?? false;
156
        $sspAssetTransfer = $this->tester->haveAsset($originalData);
157
        $originalImageId = $sspAssetTransfer->getImage() ? $sspAssetTransfer->getImage()->getIdFile() : null;
158
159
        $sspAssetTransfer = (new SspAssetTransfer())
160
            ->setIdSspAsset($sspAssetTransfer->getIdSspAsset())
161
            ->setName($updateData['name'] ?? $sspAssetTransfer->getName())
162
            ->setSerialNumber($sspAssetTransfer->getSerialNumber())
163
            ->setNote($updateData['note'] ?? $sspAssetTransfer->getNote());
164
165
        if (isset($updateData['generateImage'])) {
166
            if ($updateData['generateImage']) {
167
                $imageData = $this->tester->generateSmallFile();
168
                $this->tester->attachImageToAsset($sspAssetTransfer, $imageData);
169
            } else {
170
                if ($sspAssetTransfer->getImage() && $sspAssetTransfer->getImage()->getIdFile()) {
171
                    $sspAssetTransfer->getImage()->setToDelete(true);
172
                }
173
            }
174
        }
175
176
        // Act
177
        $updateResponseTransfer = $this->selfServicePortalFacade->updateSspAssetCollection(
178
            (new SspAssetCollectionRequestTransfer())->addSspAsset($sspAssetTransfer),
179
        );
180
181
        // Assert
182
        $this->assertInstanceOf(SspAssetCollectionResponseTransfer::class, $updateResponseTransfer);
183
184
        if ($expectedData['isSuccessful']) {
185
            $this->assertEmpty($updateResponseTransfer->getErrors());
186
            $this->assertCount(1, $updateResponseTransfer->getSspAssets());
187
188
            $updatedAssetTransfer = $updateResponseTransfer->getSspAssets()->getIterator()->current();
189
            $this->assertSame($expectedData['name'], $updatedAssetTransfer->getName());
190
            $this->assertSame($expectedData['note'], $updatedAssetTransfer->getNote());
191
192
            if (isset($expectedData['hasImage']) && $expectedData['hasImage']) {
193
                $this->assertNotNull($updatedAssetTransfer->getImage());
194
                $this->assertNotNull($updatedAssetTransfer->getImage()->getIdFile());
195
            }
196
197
            if (isset($expectedData['imageUpdated'])) {
198
                $this->assertNotSame($originalImageId, $updatedAssetTransfer->getImage()->getIdFile());
199
            }
200
        } else {
201
            $this->assertNotEmpty($updateResponseTransfer->getErrors());
202
203
            $sspAssetEntity = SpySspAssetQuery::create()->findOneByIdSspAsset($sspAssetTransfer->getIdSspAsset());
204
205
            $this->assertSame($expectedData['name'], $sspAssetEntity->getName());
206
            $this->assertSame($expectedData['note'], $sspAssetEntity->getNote());
207
        }
208
    }
209
210
    /**
211
     * @dataProvider getAssetCollectionDataProvider
212
     *
213
     * @param array<mixed> $sspAssets
214
     * @param string $assignedBusinessUnitsCondition
215
     * @param array<mixed> $sorting
216
     * @param bool $fetchSspAssetsPerAssignment
217
     * @param array<mixed> $expectedAssets
218
     *
219
     * @return void
220
     */
221
    public function testGetSspAssetCollectionReturnsCorrectAssets(
222
        array $sspAssets,
223
        string $assignedBusinessUnitsCondition,
224
        array $sorting,
225
        bool $fetchSspAssetsPerAssignment,
226
        array $expectedAssets
227
    ): void {
228
        $permissionTransfer = $this->tester->havePermission(new ViewCompanySspAssetPermissionPlugin());
229
        $permissionCollectionTransfer = (new PermissionCollectionTransfer())->addPermission($permissionTransfer);
230
        $companyTransfer = $this->tester->haveCompany();
231
232
        // Arrange
233
        $businessUnitByKey = [];
234
        foreach ($sspAssets as $sspAssetData) {
235
            $businessUnitAssignments = [];
236
            foreach ($sspAssetData['assignedCompanyBusinessUnits'] as $assignedCompanyBusinessUnit) {
237
                $companyBusinessUnitEntity = SpyCompanyBusinessUnitQuery::create()->findOneByKey($assignedCompanyBusinessUnit['key']);
238
                if ($companyBusinessUnitEntity) {
239
                    $companyBusinessUnitTransfer = (new CompanyBusinessUnitTransfer())->fromArray($companyBusinessUnitEntity->toArray(), true);
240
                } else {
241
                    $companyBusinessUnitTransfer = $this->tester->haveCompanyBusinessUnit([
242
                        CompanyBusinessUnitTransfer::KEY => $assignedCompanyBusinessUnit['key'],
243
                        CompanyBusinessUnitTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
244
                    ]);
245
                }
246
                $businessUnitAssignments[] = [
247
                    SspAssetBusinessUnitAssignmentTransfer::COMPANY_BUSINESS_UNIT => $companyBusinessUnitTransfer,
248
                ];
249
                $businessUnitByKey[$companyBusinessUnitTransfer->getKey()] = $companyBusinessUnitTransfer;
250
            }
251
252
            $companyUserTransfer = $this->tester->haveCompanyUserWithPermissions(
253
                $companyTransfer,
254
                $permissionCollectionTransfer,
255
            );
256
257
            $this->tester->haveAsset([
258
                SspAssetTransfer::NAME => $sspAssetData['name'],
259
                SspAssetTransfer::SERIAL_NUMBER => $sspAssetData['serialNumber'],
260
                SspAssetTransfer::NOTE => $sspAssetData['note'],
261
                SspAssetTransfer::COMPANY_BUSINESS_UNIT => $this->companyBusinessUnit,
262
                SspAssetTransfer::BUSINESS_UNIT_ASSIGNMENTS => $businessUnitAssignments,
263
            ]);
264
        }
265
266
        $sspAssetConditionsTransfer = new SspAssetConditionsTransfer();
267
        $sspAssetConditionsTransfer->setAssignedBusinessUnitId(
268
            $businessUnitByKey[$assignedBusinessUnitsCondition]->getIdCompanyBusinessUnit(),
269
        );
270
271
        $sspAssetCriteriaTransfer = (new SspAssetCriteriaTransfer())
272
            ->setSspAssetConditions($sspAssetConditionsTransfer)
273
            ->setPagination(
274
                (new PaginationTransfer())
275
                    ->setPage(1)
276
                    ->setMaxPerPage(count($expectedAssets)),
277
            )
278
            ->setInclude(
279
                (new SspAssetIncludeTransfer())
280
                    ->setWithAssignedBusinessUnits(true),
281
            )->setCompanyUser($companyUserTransfer);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $companyUserTransfer seems to be defined by a foreach iteration on line 234. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
282
283
        foreach ($sorting as $field => $direction) {
284
            $sspAssetCriteriaTransfer->addSort(
285
                (new SortTransfer())
286
                    ->setField($field)
287
                    ->setIsAscending($direction === 'ASC'),
288
            );
289
        }
290
291
        // Act
292
        $sspAssetCollectionTransfer = $this->selfServicePortalFacade->getSspAssetCollection($sspAssetCriteriaTransfer);
293
294
        // Assert
295
        $this->assertCount(count($expectedAssets), $sspAssetCollectionTransfer->getSspAssets());
296
297
        foreach ($expectedAssets as $key => $expectedAsset) {
298
            $sspAssetTransfer = $sspAssetCollectionTransfer->getSspAssets()->offsetGet($key);
299
            $this->assertSame($expectedAsset['serialNumber'], $sspAssetTransfer->getSerialNumber());
300
            $this->assertCount(count($expectedAsset['assignedCompanyBusinessUnits']), $sspAssetTransfer->getBusinessUnitAssignments()->getIterator());
301
            foreach ($expectedAsset['assignedCompanyBusinessUnits'] as $index => $expectedCompanyBusinessUnit) {
302
                $companyBusinessUnitEntity = SpyCompanyBusinessUnitQuery::create()->findOneByIdCompanyBusinessUnit($sspAssetTransfer->getBusinessUnitAssignments()->offsetGet($index)->getCompanyBusinessUnit()->getIdCompanyBusinessUnit());
303
                $this->assertSame($expectedCompanyBusinessUnit['key'], $companyBusinessUnitEntity->getKey());
304
            }
305
        }
306
    }
307
308
    public function testSspAssetDashboardDataExpanderPluginWillAddAssetToCollection(): void
309
    {
310
        // Arrange
311
        $companyTransfer = $this->tester->haveCompany();
312
        $companyBusinessUnitTransfer = $this->tester->haveCompanyBusinessUnit([
313
            CompanyBusinessUnitTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
314
        ]);
315
        $businessUnitAssignments = [
316
            [
317
                SspAssetBusinessUnitAssignmentTransfer::COMPANY_BUSINESS_UNIT => $companyBusinessUnitTransfer,
318
            ],
319
        ];
320
        $permissionTransfer = $this->tester->havePermission(new ViewCompanySspAssetPermissionPlugin());
321
        $permissionCollectionTransfer = (new PermissionCollectionTransfer())->addPermission($permissionTransfer);
322
        $companyUserTransfer = $this->tester->haveCompanyUserWithPermissions(
323
            $companyTransfer,
324
            $permissionCollectionTransfer,
325
        );
326
327
        $expectedName = 'asset name';
328
        $expectedSerialNumber = 'asset serial number';
329
        $expectedNote = 'note of the asset';
330
        $this->tester->haveAsset([
331
            SspAssetTransfer::NAME => $expectedName,
332
            SspAssetTransfer::SERIAL_NUMBER => $expectedSerialNumber,
333
            SspAssetTransfer::NOTE => $expectedNote,
334
            SspAssetTransfer::COMPANY_BUSINESS_UNIT => $this->companyBusinessUnit,
335
            SspAssetTransfer::BUSINESS_UNIT_ASSIGNMENTS => $businessUnitAssignments,
336
        ]);
337
338
        // Act
339
        $dashboardResponseTransfer = (new SspAssetDashboardDataExpanderPlugin())->provideDashboardData(
340
            (new DashboardResponseTransfer()),
341
            (new DashboardRequestTransfer())->setCompanyUser($companyUserTransfer)->setWithSspAssetCount(10),
342
        );
343
344
        // Assert
345
        $this->assertCount(1, $dashboardResponseTransfer->getDashboardComponentAssets()->getSspAssetCollection()->getSspAssets());
346
        $this->assertSame(
347
            1,
348
            $dashboardResponseTransfer->getDashboardComponentAssets()->getSspAssetCollection()->getSspAssets()->count(),
349
        );
350
        /** @var \Generated\Shared\Transfer\SspAssetTransfer $actualSspAssetTransfer */
351
        $actualSspAssetTransfer = $dashboardResponseTransfer
352
            ->getDashboardComponentAssets()
353
            ->getSspAssetCollection()
354
            ->getSspAssets()
355
            ->getIterator()
356
            ->current();
357
358
        $this->assertSame($expectedName, $actualSspAssetTransfer->getName());
359
        $this->assertSame($expectedSerialNumber, $actualSspAssetTransfer->getSerialNumber());
360
        $this->assertSame($expectedNote, $actualSspAssetTransfer->getNote());
361
    }
362
363
    /**
364
     * @return array<mixed>
365
     */
366
    protected function assetSuccessfulCollectionDataProvider(): array
367
    {
368
        return [
369
            'success with all fields' => [
370
                'sspAssetData' => [
371
                    'name' => 'Test Asset',
372
                    'serialNumber' => '123-456',
373
                    'note' => 'Test Note',
374
                ],
375
                'expectedAssetCount' => 1,
376
                'expectedName' => 'Test Asset',
377
                'expectedValidationErrors' => [],
378
            ],
379
            'success with required fields only' => [
380
                'sspAssetData' => [
381
                    'name' => 'Test Asset',
382
                    'serialNumber' => null,
383
                    'note' => null,
384
                ],
385
                'expectedAssetCount' => 1,
386
                'expectedName' => 'Test Asset',
387
                'expectedValidationErrors' => [],
388
            ],
389
            'failure with missing required fields' => [
390
                'sspAssetData' => [
391
                    'name' => null,
392
                    'serialNumber' => '123-456',
393
                    'note' => 'Test Note',
394
                ],
395
                'expectedAssetCount' => 0,
396
                'expectedName' => '',
397
                'expectedValidationErrors' => [
398
                    'self_service_portal.asset.validation.name.not_set',
399
                ],
400
            ],
401
            'failure with missing company business unit' => [
402
                'sspAssetData' => [
403
                    'name' => 'Test Asset',
404
                    'serialNumber' => '123-456',
405
                    'note' => 'Test Note',
406
                    'companyBusinessUnitNotSet' => true,
407
                ],
408
                'expectedAssetCount' => 1,
409
                'expectedName' => 'Test Asset',
410
                'expectedValidationErrors' => [],
411
            ],
412
        ];
413
    }
414
415
    /**
416
     * @return array<string, mixed>
417
     */
418
    protected function getAssetCollectionDataProvider(): array
419
    {
420
        return [
421
            'get assets sorted by id DESC with assigned business unit Test SspAsset Company Business Unit 2' => [
422
                'sspAssets' => [
423
                    [
424
                        'name' => 'Test Asset 1',
425
                        'serialNumber' => '123-456',
426
                        'note' => 'Test Note 1',
427
                        'assignedCompanyBusinessUnits' => [
428
                            [
429
                                'key' => 'Test SspAsset Company Business Unit 2',
430
                            ],
431
                        ],
432
                    ],
433
                    [
434
                        'name' => 'Test Asset 2',
435
                        'serialNumber' => '789-012',
436
                        'note' => 'Test Note 2',
437
                        'assignedCompanyBusinessUnits' => [
438
                            [
439
                                'key' => 'Test SspAsset Company Business Unit 1',
440
                            ],
441
                            [
442
                                'key' => 'Test SspAsset Company Business Unit 2',
443
                            ],
444
                        ],
445
                    ],
446
                ],
447
                'assignedBusinessUnitsCondition' => 'Test SspAsset Company Business Unit 2',
448
                'sorting' => [
449
                    'id_ssp_asset' => 'DESC',
450
                ],
451
                'fetchSspAssetsPerAssignment' => false,
452
                'expectedAssets' => [
453
                    [
454
                        'name' => 'Test Asset 2',
455
                        'serialNumber' => '789-012',
456
                        'note' => 'Test Note 2',
457
                        'assignedCompanyBusinessUnits' => [
458
                            [
459
                                'key' => 'Test SspAsset Company Business Unit 2',
460
                            ],
461
                        ],
462
                    ],
463
                    [
464
                        'name' => 'Test Asset 1',
465
                        'serialNumber' => '123-456',
466
                        'note' => 'Test Note 1',
467
                        'assignedCompanyBusinessUnits' => [
468
                            [
469
                                'key' => 'Test SspAsset Company Business Unit 2',
470
                            ],
471
                        ],
472
                    ],
473
                ],
474
            ],
475
            'get assets sorted by id ASC with assigned business unit Test SspAsset Company Business Unit 3' => [
476
                'sspAssets' => [
477
                    [
478
                        'name' => 'Test Asset 3',
479
                        'serialNumber' => '123-456',
480
                        'note' => 'Test Note 3',
481
                        'assignedCompanyBusinessUnits' => [
482
                            [
483
                                'key' => 'Test SspAsset Company Business Unit 3',
484
                            ],
485
                            [
486
                                'key' => 'Test SspAsset Company Business Unit 4',
487
                            ],
488
                        ],
489
                    ],
490
                    [
491
                        'name' => 'Test Asset 4',
492
                        'serialNumber' => '789-012',
493
                        'note' => 'Test Note 4',
494
                        'assignedCompanyBusinessUnits' => [
495
                            [
496
                                'key' => 'Test SspAsset Company Business Unit 4',
497
                            ],
498
                        ],
499
                    ],
500
                ],
501
                'assignedBusinessUnitsCondition' => 'Test SspAsset Company Business Unit 3',
502
                'sorting' => [
503
                    'id_ssp_asset' => 'ASC',
504
                ],
505
                'fetchSspAssetsPerAssignment' => false,
506
                'expectedAssets' => [
507
                    [
508
                        'name' => 'Test Asset 3',
509
                        'serialNumber' => '123-456',
510
                        'note' => 'Test Note 3',
511
                        'assignedCompanyBusinessUnits' => [
512
                            [
513
                                'key' => 'Test SspAsset Company Business Unit 3',
514
                            ],
515
                        ],
516
                    ],
517
                ],
518
            ],
519
        ];
520
    }
521
522
    /**
523
     * @return array<string, array<mixed>>
524
     */
525
    public function assetUpdateDataProvider(): array
526
    {
527
        return [
528
            'update asset name and note' => [
529
                'originalData' => [
530
                    'name' => 'Original Asset Name',
531
                    'serialNumber' => 'SN123',
532
                    'note' => 'Original note',
533
                ],
534
                'updateData' => [
535
                    'name' => 'Updated Asset Name',
536
                    'note' => 'Updated note',
537
                ],
538
                'expectedData' => [
539
                    'isSuccessful' => true,
540
                    'name' => 'Updated Asset Name',
541
                    'note' => 'Updated note',
542
                ],
543
            ],
544
            'update with invalid data' => [
545
                'originalData' => [
546
                    'name' => 'Original Asset Name',
547
                    'serialNumber' => 'SN123',
548
                    'note' => 'Original note',
549
                ],
550
                'updateData' => [
551
                    'name' => '',
552
                ],
553
                'expectedData' => [
554
                    'isSuccessful' => false,
555
                    'name' => 'Original Asset Name',
556
                    'note' => 'Original note',
557
                ],
558
            ],
559
            'update with image' => [
560
                'originalData' => [
561
                    'name' => 'Asset with Image',
562
                    'serialNumber' => 'SN456',
563
                    'note' => 'Asset with image note',
564
                    'generateImage' => true,
565
                ],
566
                'updateData' => [
567
                    'generateImage' => true,
568
                ],
569
                'expectedData' => [
570
                    'isSuccessful' => true,
571
                    'name' => 'Asset with Image',
572
                    'note' => 'Asset with image note',
573
                    'hasImage' => true,
574
                ],
575
            ],
576
            'update with image replace' => [
577
                'originalData' => [
578
                    'name' => 'Asset with Image',
579
                    'serialNumber' => 'SN456',
580
                    'note' => 'Asset with image note',
581
                    'generateImage' => true,
582
                ],
583
                'updateData' => [
584
                    'generateImage' => true,
585
                ],
586
                'expectedData' => [
587
                    'isSuccessful' => true,
588
                    'name' => 'Asset with Image',
589
                    'note' => 'Asset with image note',
590
                    'hasImage' => true,
591
                ],
592
            ],
593
            'update with image delete' => [
594
                'originalData' => [
595
                    'name' => 'Asset with Image',
596
                    'serialNumber' => 'SN456',
597
                    'note' => 'Asset with image note',
598
                    'generateImage' => true,
599
                ],
600
                'updateData' => [
601
                    'generateImage' => false,
602
                ],
603
                'expectedData' => [
604
                    'isSuccessful' => true,
605
                    'name' => 'Asset with Image',
606
                    'note' => 'Asset with image note',
607
                    'hasImage' => false,
608
                ],
609
            ],
610
        ];
611
    }
612
}
613