Issues (3877)

SprykerTest/Zed/Cms/Business/CmsFacadePageTest.php (3 issues)

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 SprykerTest\Zed\Cms\Business;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\CmsPageAttributesTransfer;
12
use Generated\Shared\Transfer\CmsPageMetaAttributesTransfer;
13
use Generated\Shared\Transfer\CmsPageTransfer;
14
use Generated\Shared\Transfer\StoreRelationTransfer;
15
use Spryker\Zed\Cms\Business\CmsFacade;
16
use Spryker\Zed\Store\Business\StoreFacade;
17
use Spryker\Zed\Store\StoreDependencyProvider;
18
19
/**
20
 * Auto-generated group annotations
21
 *
22
 * @group SprykerTest
23
 * @group Zed
24
 * @group Cms
25
 * @group Business
26
 * @group Facade
27
 * @group CmsFacadePageTest
28
 * Add your own group annotations below this line
29
 */
30
class CmsFacadePageTest extends Unit
31
{
32
    /**
33
     * @var string
34
     */
35
    public const CMS_PAGE_NEW_TITLE = 'new title';
36
37
    /**
38
     * @var string
39
     */
40
    public const CMS_PAGE_NEW_KEY_WORDS = 'new key words';
41
42
    /**
43
     * @var string
44
     */
45
    public const CMS_PAGE_NEW_DESCRIPTION = 'new description';
46
47
    /**
48
     * @var \Spryker\Zed\Cms\Business\CmsFacade
49
     */
50
    protected $cmsFacade;
51
52
    /**
53
     * @var \SprykerTest\Zed\Cms\CmsBusinessTester
54
     */
55
    protected $tester;
56
57
    /**
58
     * @return void
59
     */
60
    protected function setUp(): void
61
    {
62
        parent::setUp();
63
64
        $this->cmsFacade = new CmsFacade();
65
    }
66
67
    /**
68
     * @return void
69
     */
70
    public function testSaveCmsGlossaryShouldPersistUpdatedTranslations(): void
71
    {
72
        $fixtures = $this->createCmsPageTransferFixtures();
73
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
74
75
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
76
77
        $cmsGlossaryTransfer = $this->cmsFacade->findPageGlossaryAttributes($idCmsPage);
78
79
        $cmsGlossaryAttributesTransfer = $cmsGlossaryTransfer->getGlossaryAttributes()[0];
80
81
        $translationFixtures = $this->getTranslationFixtures();
82
83
        $translations = $cmsGlossaryAttributesTransfer->getTranslations();
84
        foreach ($translations as $cmsPlaceholderTranslationTransfer) {
85
            $cmsPlaceholderTranslationTransfer->setTranslation(
86
                $translationFixtures[$cmsPlaceholderTranslationTransfer->getLocaleName()],
87
            );
88
        }
89
90
        $updatedCmsGlossaryTransfer = $this->cmsFacade->saveCmsGlossary($cmsGlossaryTransfer);
91
92
        $cmsGlossaryAttributesTransfer = $updatedCmsGlossaryTransfer->getGlossaryAttributes()[0];
93
94
        $translations = $cmsGlossaryAttributesTransfer->getTranslations();
95
        foreach ($translations as $cmsPlaceholderTranslationTransfer) {
96
            $this->assertSame(
97
                $translationFixtures[$cmsPlaceholderTranslationTransfer->getLocaleName()],
98
                $cmsPlaceholderTranslationTransfer->getTranslation(),
99
            );
100
        }
101
    }
102
103
    /**
104
     * @return void
105
     */
106
    public function testCreatePageShouldPersistGivenCmsPage(): void
107
    {
108
        $fixtures = $this->createCmsPageTransferFixtures();
109
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
110
111
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
112
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
113
114
        $this->assertSame($persistedCmsPageTransfer->getFkTemplate(), $cmsPageTransfer->getFkTemplate());
115
        $this->assertSame($persistedCmsPageTransfer->getIsActive(), $cmsPageTransfer->getIsActive());
116
        $this->assertSame($persistedCmsPageTransfer->getIsSearchable(), $cmsPageTransfer->getIsSearchable());
117
        $this->assertNotEmpty($persistedCmsPageTransfer->getFkPage());
118
119
        $this->assertPageAttributes($cmsPageTransfer, $persistedCmsPageTransfer);
120
        $this->assertPageMetaAttributes($cmsPageTransfer, $persistedCmsPageTransfer);
121
    }
122
123
    /**
124
     * @return void
125
     */
126
    public function testUpdatePageShouldUpdatePageWithNewData(): void
127
    {
128
        $fixtures = $this->createCmsPageTransferFixtures();
129
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
130
131
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
132
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
133
134
        $persistedCmsPageMetaAttributes = $persistedCmsPageTransfer->getMetaAttributes()[0];
135
        $persistedCmsPageMetaAttributes->setMetaTitle(static::CMS_PAGE_NEW_TITLE);
136
        $persistedCmsPageMetaAttributes->setMetaKeywords(static::CMS_PAGE_NEW_KEY_WORDS);
137
        $persistedCmsPageMetaAttributes->setMetaDescription(static::CMS_PAGE_NEW_DESCRIPTION);
138
139
        $persistedCmsPageAttributes = $persistedCmsPageTransfer->getPageAttributes()[0];
140
        $persistedCmsPageAttributes->setName('new page name');
141
        $persistedCmsPageAttributes->setUrl('updated-url');
142
143
        $updatedCmsPageTransfer = $this->cmsFacade->updatePage($persistedCmsPageTransfer);
144
145
        $updatedCmsPageMetaAttributes = $updatedCmsPageTransfer->getMetaAttributes()[0];
146
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaDescription(), $persistedCmsPageMetaAttributes->getMetaDescription());
147
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaKeywords(), $persistedCmsPageMetaAttributes->getMetaKeywords());
148
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaTitle(), $persistedCmsPageMetaAttributes->getMetaTitle());
149
150
        $updatedCmsPageAttributes = $persistedCmsPageTransfer->getPageAttributes()[0];
151
        $this->assertSame($updatedCmsPageAttributes->getName(), $persistedCmsPageAttributes->getName());
152
        $this->assertSame($updatedCmsPageAttributes->getUrl(), $persistedCmsPageAttributes->getUrl());
153
    }
154
155
    /**
156
     * @return void
157
     */
158
    public function testActivatePageShouldActivateInactivePage(): void
159
    {
160
        $fixtures = $this->createCmsPageTransferFixtures();
161
        $fixtures[CmsPageTransfer::IS_ACTIVE] = false;
162
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
163
164
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
165
166
        $cmsGlossaryTransfer = $this->cmsFacade->findPageGlossaryAttributes($idCmsPage);
167
168
        $cmsGlossaryAttributesTransfer = $cmsGlossaryTransfer->getGlossaryAttributes()[0];
169
170
        $translationFixtures = $this->getTranslationFixtures();
171
172
        $translations = $cmsGlossaryAttributesTransfer->getTranslations();
173
        foreach ($translations as $cmsPlaceholderTranslationTransfer) {
174
            $cmsPlaceholderTranslationTransfer->setTranslation(
175
                $translationFixtures[$cmsPlaceholderTranslationTransfer->getLocaleName()],
176
            );
177
        }
178
        $this->cmsFacade->saveCmsGlossary($cmsGlossaryTransfer);
179
180
        $this->cmsFacade->activatePage($idCmsPage);
181
182
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
183
184
        $this->assertTrue($persistedCmsPageTransfer->getIsActive());
185
    }
186
187
    /**
188
     * @return void
189
     */
190
    public function testDeActivatePageShouldActivateInactivePage(): void
191
    {
192
        $fixtures = $this->createCmsPageTransferFixtures();
193
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
194
195
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
196
197
        $this->cmsFacade->deactivatePage($idCmsPage);
198
199
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
200
201
        $this->assertFalse($persistedCmsPageTransfer->getIsActive());
202
    }
203
204
    /**
205
     * @return void
206
     */
207
    public function testGetPageUrlPrefixShouldBuildUrlPrefixFromGivenLocalName(): void
208
    {
209
        $cmsPageAttributeTransfer = new CmsPageAttributesTransfer();
210
        $cmsPageAttributeTransfer->setLocaleName('en_US');
211
212
        $urlPrefix = $this->cmsFacade->getPageUrlPrefix($cmsPageAttributeTransfer);
213
214
        $this->assertSame('', $urlPrefix);
215
    }
216
217
    /**
218
     * @return void
219
     */
220
    public function testBuildPageUrlWhenUrlWithoutPrefixGivenShouldBuildValidUrl(): void
221
    {
222
        $cmsPageAttributesTransfer = new CmsPageAttributesTransfer();
223
        $cmsPageAttributesTransfer->setLocaleName('en_US');
224
        $cmsPageAttributesTransfer->setUrl('test-url-functionl');
225
226
        $url = $this->cmsFacade->buildPageUrl($cmsPageAttributesTransfer);
227
228
        $this->assertSame($cmsPageAttributesTransfer->getUrl(), $url);
229
    }
230
231
    /**
232
     * @return void
233
     */
234
    public function testBuildPageUrlWhenUrlWithPrefixGivenShouldBuildValidUrl(): void
235
    {
236
        $cmsPageAttributesTransfer = new CmsPageAttributesTransfer();
237
        $cmsPageAttributesTransfer->setLocaleName('en_US');
238
        $cmsPageAttributesTransfer->setUrl('/en/test-url-functionl');
239
240
        $url = $this->cmsFacade->buildPageUrl($cmsPageAttributesTransfer);
241
242
        $this->assertSame($cmsPageAttributesTransfer->getUrl(), $url);
243
    }
244
245
    /**
246
     * @return void
247
     */
248
    public function testPublishPageShouldPersistCmsVersion(): void
249
    {
250
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
251
        $cmsVersionTransfer = $this->cmsFacade->publishWithVersion($idCmsPage);
252
253
        $this->assertNotNull($cmsVersionTransfer);
254
        $this->assertSame($cmsVersionTransfer->getFkCmsPage(), $idCmsPage);
255
        $this->assertSame($cmsVersionTransfer->getVersion(), 1);
256
        $this->assertNotEmpty($cmsVersionTransfer->getData());
257
    }
258
259
    /**
260
     * @return void
261
     */
262
    public function testPublishPageShouldGetNewVersion(): void
263
    {
264
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
265
        $cmsVersionTransferOne = $this->cmsFacade->publishWithVersion($idCmsPage);
266
        $cmsVersionTransferTwo = $this->cmsFacade->publishWithVersion($idCmsPage);
267
268
        $this->assertGreaterThan($cmsVersionTransferOne->getVersion(), $cmsVersionTransferTwo->getVersion());
269
    }
270
271
    /**
272
     * @return void
273
     */
274
    public function testRollbackPageShouldGetOldData(): void
275
    {
276
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
277
        $cmsVersionTransferOne = $this->cmsFacade->publishWithVersion($idCmsPage);
278
279
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
280
281
        foreach ($persistedCmsPageTransfer->getMetaAttributes() as $metaAttribute) {
282
            $metaAttribute->setMetaTitle(static::CMS_PAGE_NEW_TITLE);
283
            $metaAttribute->setMetaKeywords(static::CMS_PAGE_NEW_KEY_WORDS);
284
            $metaAttribute->setMetaDescription(static::CMS_PAGE_NEW_DESCRIPTION);
285
        }
286
287
        $updatedPageTransfer = $this->cmsFacade->updatePage($persistedCmsPageTransfer);
0 ignored issues
show
It seems like $persistedCmsPageTransfer can also be of type null; however, parameter $cmsPageTransfer of Spryker\Zed\Cms\Business\CmsFacade::updatePage() does only seem to accept Generated\Shared\Transfer\CmsPageTransfer, 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

287
        $updatedPageTransfer = $this->cmsFacade->updatePage(/** @scrutinizer ignore-type */ $persistedCmsPageTransfer);
Loading history...
288
        $updatedCmsPageMetaAttributes = $updatedPageTransfer->getMetaAttributes()[0];
289
290
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaDescription(), static::CMS_PAGE_NEW_DESCRIPTION);
291
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaKeywords(), static::CMS_PAGE_NEW_KEY_WORDS);
292
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaTitle(), static::CMS_PAGE_NEW_TITLE);
293
294
        $this->cmsFacade->publishWithVersion($idCmsPage);
295
        $this->cmsFacade->rollback($idCmsPage, $cmsVersionTransferOne->getVersion());
296
297
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
298
        $persistedCmsPageMetaAttributes = $persistedCmsPageTransfer->getMetaAttributes()[0];
299
300
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaDescription(), static::CMS_PAGE_NEW_DESCRIPTION);
301
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaKeywords(), static::CMS_PAGE_NEW_KEY_WORDS);
302
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaTitle(), static::CMS_PAGE_NEW_TITLE);
303
    }
304
305
    /**
306
     * @return void
307
     */
308
    public function testRevertPageShouldGetOldData(): void
309
    {
310
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
311
        $this->cmsFacade->publishWithVersion($idCmsPage);
312
313
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
314
315
        foreach ($persistedCmsPageTransfer->getMetaAttributes() as $metaAttribute) {
316
            $metaAttribute->setMetaTitle(static::CMS_PAGE_NEW_TITLE);
317
            $metaAttribute->setMetaKeywords(static::CMS_PAGE_NEW_KEY_WORDS);
318
            $metaAttribute->setMetaDescription(static::CMS_PAGE_NEW_DESCRIPTION);
319
        }
320
321
        $updatedPageTransfer = $this->cmsFacade->updatePage($persistedCmsPageTransfer);
0 ignored issues
show
It seems like $persistedCmsPageTransfer can also be of type null; however, parameter $cmsPageTransfer of Spryker\Zed\Cms\Business\CmsFacade::updatePage() does only seem to accept Generated\Shared\Transfer\CmsPageTransfer, 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

321
        $updatedPageTransfer = $this->cmsFacade->updatePage(/** @scrutinizer ignore-type */ $persistedCmsPageTransfer);
Loading history...
322
        $updatedCmsPageMetaAttributes = $updatedPageTransfer->getMetaAttributes()[0];
323
324
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaDescription(), static::CMS_PAGE_NEW_DESCRIPTION);
325
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaKeywords(), static::CMS_PAGE_NEW_KEY_WORDS);
326
        $this->assertSame($updatedCmsPageMetaAttributes->getMetaTitle(), static::CMS_PAGE_NEW_TITLE);
327
328
        $this->cmsFacade->revert($idCmsPage);
329
330
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
331
        $persistedCmsPageMetaAttributes = $persistedCmsPageTransfer->getMetaAttributes()[0];
332
333
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaDescription(), static::CMS_PAGE_NEW_DESCRIPTION);
334
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaKeywords(), static::CMS_PAGE_NEW_KEY_WORDS);
335
        $this->assertNotEquals($persistedCmsPageMetaAttributes->getMetaTitle(), static::CMS_PAGE_NEW_TITLE);
336
    }
337
338
    /**
339
     * @return void
340
     */
341
    public function testFindLatestCmsVersionReturnsLatestVersion(): void
342
    {
343
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
344
        $cmsVersionTransferOne = $this->cmsFacade->publishWithVersion($idCmsPage);
345
        $this->cmsFacade->publishWithVersion($idCmsPage);
346
347
        $cmsVersionTransferTwo = $this->cmsFacade->findLatestCmsVersionByIdCmsPage($idCmsPage);
348
349
        $this->assertGreaterThan($cmsVersionTransferOne->getVersion(), $cmsVersionTransferTwo->getVersion());
350
    }
351
352
    /**
353
     * @return void
354
     */
355
    public function testFindAllCmsVersionByReturnsAllVersions(): void
356
    {
357
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
358
        $this->cmsFacade->publishWithVersion($idCmsPage);
359
        $this->cmsFacade->publishWithVersion($idCmsPage);
360
361
        $versions = $this->cmsFacade->findAllCmsVersionByIdCmsPage($idCmsPage);
362
363
        $this->assertSame(count($versions), 2);
364
    }
365
366
    /**
367
     * @return void
368
     */
369
    public function testFindCmsVersionByVersionNumberReturnsSameVersion(): void
370
    {
371
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
372
        $this->cmsFacade->publishWithVersion($idCmsPage);
373
        $this->cmsFacade->publishWithVersion($idCmsPage);
374
375
        $cmsVersion = $this->cmsFacade->findCmsVersionByIdCmsPageAndVersion($idCmsPage, 1);
376
377
        $this->assertSame($cmsVersion->getVersion(), 1);
378
    }
379
380
    /**
381
     * @return void
382
     */
383
    public function testGetCmsVersionDataRetrievesDraftDataFromDatabase(): void
384
    {
385
        // Arrange
386
        $idCmsPage = $this->createCmsPageWithGlossaryAttributes();
387
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
388
389
        foreach ($persistedCmsPageTransfer->getMetaAttributes() as $metaAttribute) {
390
            $metaAttribute->setMetaTitle(static::CMS_PAGE_NEW_TITLE);
391
            $metaAttribute->setMetaKeywords(static::CMS_PAGE_NEW_KEY_WORDS);
392
            $metaAttribute->setMetaDescription(static::CMS_PAGE_NEW_DESCRIPTION);
393
        }
394
395
        $expectedCmsVersionData = $this->cmsFacade->updatePage($persistedCmsPageTransfer);
396
397
        // Act
398
        $actualCmsVersionData = $this->cmsFacade->getCmsVersionData($idCmsPage);
399
400
        // Assert
401
        $expectedCmsPageVersionMetaAttributes = $expectedCmsVersionData->getMetaAttributes()[0];
402
        $actualCmsPageVersionMetaAttributes = $actualCmsVersionData->getCmsPage()->getMetaAttributes()[0];
403
        $this->assertEquals($expectedCmsPageVersionMetaAttributes->getMetaDescription(), $actualCmsPageVersionMetaAttributes->getMetaDescription());
404
        $this->assertEquals($expectedCmsPageVersionMetaAttributes->getMetaKeywords(), $actualCmsPageVersionMetaAttributes->getMetaKeywords());
405
        $this->assertEquals($expectedCmsPageVersionMetaAttributes->getMetaTitle(), $actualCmsPageVersionMetaAttributes->getMetaTitle());
406
    }
407
408
    /**
409
     * @return int
410
     */
411
    protected function createCmsPageWithGlossaryAttributes(): int
412
    {
413
        $fixtures = $this->createCmsPageTransferFixtures();
414
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
415
416
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
417
        $cmsGlossaryTransfer = $this->cmsFacade->findPageGlossaryAttributes($idCmsPage);
418
419
        $cmsGlossaryAttributesTransfer = $cmsGlossaryTransfer->getGlossaryAttributes()[0];
420
421
        $translationFixtures = $this->getTranslationFixtures();
422
423
        $translations = $cmsGlossaryAttributesTransfer->getTranslations();
424
        foreach ($translations as $cmsPlaceholderTranslationTransfer) {
425
            $cmsPlaceholderTranslationTransfer->setTranslation($translationFixtures[$cmsPlaceholderTranslationTransfer->getLocaleName()]);
426
        }
427
        $this->cmsFacade->saveCmsGlossary($cmsGlossaryTransfer);
0 ignored issues
show
It seems like $cmsGlossaryTransfer can also be of type null; however, parameter $cmsGlossaryTransfer of Spryker\Zed\Cms\Business...cade::saveCmsGlossary() does only seem to accept Generated\Shared\Transfer\CmsGlossaryTransfer, 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

427
        $this->cmsFacade->saveCmsGlossary(/** @scrutinizer ignore-type */ $cmsGlossaryTransfer);
Loading history...
428
429
        return $idCmsPage;
430
    }
431
432
    /**
433
     * @return void
434
     */
435
    public function testCreateCmsPageSavesStoreRelation(): void
436
    {
437
        $storeFacade = $this->createStoreFacade();
438
439
        $stores = $storeFacade->getAllStores();
440
441
        $expectedIdStores = [];
442
443
        foreach ($stores as $storeTransfer) {
444
            $expectedIdStores[] = $storeTransfer->getIdStore();
445
        }
446
447
        $storeRelationSeed = [
448
            CmsPageTransfer::STORE_RELATION => [
449
                StoreRelationTransfer::ID_STORES => $expectedIdStores,
450
            ],
451
        ];
452
453
        $fixtures = $this->createCmsPageTransferFixtures();
454
        $fixtures += $storeRelationSeed;
455
456
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
457
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
458
459
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
460
        $resultIdStores = $persistedCmsPageTransfer->getStoreRelation()->getIdStores();
461
462
        sort($resultIdStores);
463
        $this->assertEquals($expectedIdStores, $resultIdStores);
464
    }
465
466
    /**
467
     * @dataProvider relationUpdateFixtures
468
     *
469
     * @param array<int> $originalRelation
470
     * @param array<int> $modifiedRelation
471
     *
472
     * @return void
473
     */
474
    public function testUpdateCmsPageUpdatesStoreRelation(array $originalRelation, array $modifiedRelation): void
475
    {
476
        // Arrange
477
        $this->tester->setDependency(StoreDependencyProvider::PLUGINS_STORE_COLLECTION_EXPANDER, []);
478
479
        $originalRelationStoreIds = $this->tester->createStoresByNames($originalRelation);
480
        $modifiedRelationStoreIds = $this->tester->createStoresByNames($modifiedRelation);
481
        $storeRelationSeed = [
482
            CmsPageTransfer::STORE_RELATION => [
483
                StoreRelationTransfer::ID_STORES => $originalRelationStoreIds,
484
            ],
485
        ];
486
487
        $fixtures = $this->createCmsPageTransferFixtures();
488
        $fixtures += $storeRelationSeed;
489
490
        $cmsPageTransfer = $this->createCmsPageTransfer($fixtures);
491
        $idCmsPage = $this->cmsFacade->createPage($cmsPageTransfer);
492
493
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($idCmsPage);
494
        $persistedCmsPageTransfer->getStoreRelation()->setIdStores($modifiedRelationStoreIds);
495
496
        // Act
497
        $this->cmsFacade->updatePage($persistedCmsPageTransfer);
498
499
        $persistedCmsPageTransfer = $this->cmsFacade->findCmsPageById($persistedCmsPageTransfer->getFkPage());
500
        $resultIdStores = $persistedCmsPageTransfer->getStoreRelation()->getIdStores();
501
502
        // Assert
503
        sort($resultIdStores);
504
        $this->assertEquals($modifiedRelationStoreIds, $resultIdStores);
505
    }
506
507
    /**
508
     * @param array $fixtures
509
     *
510
     * @return \Generated\Shared\Transfer\CmsPageTransfer
511
     */
512
    protected function createCmsPageTransfer(array $fixtures): CmsPageTransfer
513
    {
514
        $cmsPageTransfer = new CmsPageTransfer();
515
        $cmsPageTransfer->fromArray($fixtures, true);
516
517
        return $cmsPageTransfer;
518
    }
519
520
    /**
521
     * @return array
522
     */
523
    protected function createCmsPageTransferFixtures(): array
524
    {
525
        $fixtures = [
526
            CmsPageTransfer::IS_ACTIVE => true,
527
            CmsPageTransfer::FK_TEMPLATE => 1,
528
            CmsPageTransfer::IS_SEARCHABLE => true,
529
            CmsPageTransfer::PAGE_ATTRIBUTES => [
530
                [
531
                    CmsPageAttributesTransfer::URL => '/en/function-test',
532
                    CmsPageAttributesTransfer::NAME => 'functional test',
533
                    CmsPageAttributesTransfer::LOCALE_NAME => 'en_US',
534
                    CmsPageAttributesTransfer::URL_PREFIX => '',
535
                    CmsPageAttributesTransfer::FK_LOCALE => 66,
536
                ],
537
                [
538
                    CmsPageAttributesTransfer::URL => '/de/function-test',
539
                    CmsPageAttributesTransfer::NAME => 'functional test',
540
                    CmsPageAttributesTransfer::LOCALE_NAME => 'de_DE',
541
                    CmsPageAttributesTransfer::URL_PREFIX => '',
542
                    CmsPageAttributesTransfer::FK_LOCALE => 46,
543
                ],
544
            ],
545
            CmsPageTransfer::META_ATTRIBUTES => [
546
                [
547
                    CmsPageMetaAttributesTransfer::META_TITLE => 'title english',
548
                    CmsPageMetaAttributesTransfer::META_KEYWORDS => 'key, word',
549
                    CmsPageMetaAttributesTransfer::META_DESCRIPTION => 'english description',
550
                    CmsPageMetaAttributesTransfer::LOCALE_NAME => 'en_US',
551
                    CmsPageAttributesTransfer::FK_LOCALE => 66,
552
                ],
553
                [
554
                    CmsPageMetaAttributesTransfer::META_TITLE => 'title german',
555
                    CmsPageMetaAttributesTransfer::META_KEYWORDS => 'key, word',
556
                    CmsPageMetaAttributesTransfer::META_DESCRIPTION => 'german description',
557
                    CmsPageMetaAttributesTransfer::LOCALE_NAME => 'de_DE',
558
                    CmsPageAttributesTransfer::FK_LOCALE => 46,
559
                ],
560
            ],
561
        ];
562
563
        return $fixtures;
564
    }
565
566
    /**
567
     * @param \Generated\Shared\Transfer\CmsPageTransfer $cmsPageTransfer
568
     * @param \Generated\Shared\Transfer\CmsPageTransfer $persistedCmsPageTransfer
569
     *
570
     * @return void
571
     */
572
    protected function assertPageAttributes(CmsPageTransfer $cmsPageTransfer, CmsPageTransfer $persistedCmsPageTransfer): void
573
    {
574
        foreach ($cmsPageTransfer->getPageAttributes() as $cmsPageAttributesTransfer) {
575
            foreach ($persistedCmsPageTransfer->getPageAttributes() as $persistedCmsPageAttributesTransfer) {
576
                if ($cmsPageAttributesTransfer->getLocaleName() !== $persistedCmsPageAttributesTransfer->getLocaleName()) {
577
                    continue;
578
                }
579
                $this->assertEquals($cmsPageAttributesTransfer->getName(), $persistedCmsPageAttributesTransfer->getName());
580
                $this->assertEquals($cmsPageAttributesTransfer->getUrlPrefix(), $persistedCmsPageAttributesTransfer->getUrlPrefix());
581
                $this->assertEquals($cmsPageAttributesTransfer->getUrl(), $persistedCmsPageAttributesTransfer->getUrl());
582
                $this->assertEquals($persistedCmsPageTransfer->getFkPage(), $persistedCmsPageAttributesTransfer->getIdCmsPage());
583
            }
584
        }
585
    }
586
587
    /**
588
     * @param \Generated\Shared\Transfer\CmsPageTransfer $cmsPageTransfer
589
     * @param \Generated\Shared\Transfer\CmsPageTransfer $persistedCmsPageTransfer
590
     *
591
     * @return void
592
     */
593
    protected function assertPageMetaAttributes(CmsPageTransfer $cmsPageTransfer, CmsPageTransfer $persistedCmsPageTransfer): void
594
    {
595
        foreach ($cmsPageTransfer->getMetaAttributes() as $cmsPageMetaAttributesTransfer) {
596
            foreach ($persistedCmsPageTransfer->getMetaAttributes() as $persistedCmsPageMetaAttributesTransfer) {
597
                if ($persistedCmsPageMetaAttributesTransfer->getLocaleName() !== $cmsPageMetaAttributesTransfer->getLocaleName()) {
598
                    continue;
599
                }
600
                $this->assertEquals($cmsPageMetaAttributesTransfer->getMetaDescription(), $persistedCmsPageMetaAttributesTransfer->getMetaDescription());
601
                $this->assertEquals($cmsPageMetaAttributesTransfer->getMetaTitle(), $persistedCmsPageMetaAttributesTransfer->getMetaTitle());
602
                $this->assertEquals($cmsPageMetaAttributesTransfer->getMetaKeywords(), $persistedCmsPageMetaAttributesTransfer->getMetaKeywords());
603
            }
604
        }
605
    }
606
607
    /**
608
     * @return array
609
     */
610
    protected function getTranslationFixtures(): array
611
    {
612
        $translationFixtures = [
613
            'en_US' => 'english translation',
614
            'de_DE' => 'german translation',
615
        ];
616
617
        return $translationFixtures;
618
    }
619
620
    /**
621
     * @return array
622
     */
623
    public function relationUpdateFixtures(): array
624
    {
625
        return [
626
            [
627
                ['DE', 'AT'], ['AT'],
628
            ],
629
            [
630
                ['DE'], ['DE', 'AT'],
631
            ],
632
            [
633
                ['AT'], ['DE', 'AT'],
634
            ],
635
        ];
636
    }
637
638
    /**
639
     * @return \Spryker\Zed\Store\Business\StoreFacade
640
     */
641
    protected function createStoreFacade(): StoreFacade
642
    {
643
        return new StoreFacade();
644
    }
645
}
646