Completed
Push — ezp_30981_content_info_proxy ( 6fc040...a78a98 )
by
unknown
15:33
created

testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\UrlAliasHandlerTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
12
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
13
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler;
14
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
15
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper;
16
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway\DoctrineDatabase;
17
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
18
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway;
19
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase as ContentGateway;
20
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase as DoctrineDatabaseLocation;
21
use eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler as LanguageHandler;
22
use eZ\Publish\Core\Persistence\Legacy\Content\Language\Gateway\DoctrineDatabase as LanguageGateway;
23
use eZ\Publish\Core\Persistence\Legacy\Content\Language\Mapper as LanguageMapper;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator;
25
use eZ\Publish\Core\Persistence\TransformationProcessor\DefinitionBased;
26
use eZ\Publish\Core\Persistence\TransformationProcessor\DefinitionBased\Parser;
27
use eZ\Publish\Core\Persistence\TransformationProcessor\PcreCompiler;
28
use eZ\Publish\Core\Persistence\Utf8Converter;
29
use eZ\Publish\SPI\Persistence\Content\UrlAlias;
30
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
31
use eZ\Publish\SPI\Persistence\TransactionHandler;
32
33
/**
34
 * Test case for UrlAliasHandler.
35
 *
36
 * @group urlalias-handler
37
 */
38
class UrlAliasHandlerTest extends TestCase
39
{
40
    /**
41
     * Test for the lookup() method.
42
     *
43
     * Simple lookup case.
44
     *
45
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
46
     * @group location
47
     * @group virtual
48
     * @group resource
49
     * @group case-correction
50
     * @group multiple-languages
51
     */
52 View Code Duplication
    public function testLookup()
53
    {
54
        $handler = $this->getHandler();
55
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
56
57
        $urlAlias = $handler->lookup('jedan');
58
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
59
    }
60
61
    /**
62
     * Test for the lookup() method.
63
     *
64
     * Trying to lookup non existent URL alias throws NotFoundException.
65
     *
66
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
67
     * @group location
68
     * @group virtual
69
     * @group resource
70
     */
71
    public function testLookupThrowsNotFoundException()
72
    {
73
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);
74
75
        $handler = $this->getHandler();
76
        $handler->lookup('wooden/iron');
77
    }
78
79
    /**
80
     * Test for the lookup() method.
81
     *
82
     * Trying to lookup URL alias with exceeded path segments limit
83
     *
84
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
85
     * @group location
86
     * @group case-correction
87
     */
88
    public function testLookupThrowsInvalidArgumentException()
89
    {
90
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
91
92
        $handler = $this->getHandler();
93
        $handler->lookup(str_repeat('/1', 99));
94
    }
95
96
    public function providerForTestLookupLocationUrlAlias()
97
    {
98
        return [
99
            [
100
                'jedan',
101
                [
102
                    [
103
                        'always-available' => true,
104
                        'translations' => [
105
                            'cro-HR' => 'jedan',
106
                        ],
107
                    ],
108
                ],
109
                ['cro-HR'],
110
                true,
111
                314,
112
                '0-6896260129051a949051c3847c34466f',
113
            ],
114
            [
115
                'jedan/dva',
116
                [
117
                    [
118
                        'always-available' => true,
119
                        'translations' => [
120
                            'cro-HR' => 'jedan',
121
                        ],
122
                    ],
123
                    [
124
                        'always-available' => false,
125
                        'translations' => [
126
                            'cro-HR' => 'dva',
127
                            'eng-GB' => 'two',
128
                        ],
129
                    ],
130
                ],
131
                ['cro-HR'],
132
                false,
133
                315,
134
                '2-c67ed9a09ab136fae610b6a087d82e21',
135
            ],
136
            [
137
                'jedan/two',
138
                [
139
                    [
140
                        'always-available' => true,
141
                        'translations' => [
142
                            'cro-HR' => 'jedan',
143
                        ],
144
                    ],
145
                    [
146
                        'always-available' => false,
147
                        'translations' => [
148
                            'cro-HR' => 'dva',
149
                            'eng-GB' => 'two',
150
                        ],
151
                    ],
152
                ],
153
                ['eng-GB'],
154
                false,
155
                315,
156
                '2-b8a9f715dbb64fd5c56e7783c6820a61',
157
            ],
158
            [
159
                'jedan/dva/tri',
160
                [
161
                    [
162
                        'always-available' => true,
163
                        'translations' => [
164
                            'cro-HR' => 'jedan',
165
                        ],
166
                    ],
167
                    [
168
                        'always-available' => false,
169
                        'translations' => [
170
                            'cro-HR' => 'dva',
171
                            'eng-GB' => 'two',
172
                        ],
173
                    ],
174
                    [
175
                        'always-available' => false,
176
                        'translations' => [
177
                            'cro-HR' => 'tri',
178
                            'eng-GB' => 'three',
179
                            'ger-DE' => 'drei',
180
                        ],
181
                    ],
182
                ],
183
                ['cro-HR'],
184
                false,
185
                316,
186
                '3-d2cfe69af2d64330670e08efb2c86df7',
187
            ],
188
            [
189
                'jedan/two/three',
190
                [
191
                    [
192
                        'always-available' => true,
193
                        'translations' => [
194
                            'cro-HR' => 'jedan',
195
                        ],
196
                    ],
197
                    [
198
                        'always-available' => false,
199
                        'translations' => [
200
                            'cro-HR' => 'dva',
201
                            'eng-GB' => 'two',
202
                        ],
203
                    ],
204
                    [
205
                        'always-available' => false,
206
                        'translations' => [
207
                            'cro-HR' => 'tri',
208
                            'eng-GB' => 'three',
209
                            'ger-DE' => 'drei',
210
                        ],
211
                    ],
212
                ],
213
                ['eng-GB'],
214
                false,
215
                316,
216
                '3-35d6d33467aae9a2e3dccb4b6b027878',
217
            ],
218
            [
219
                'jedan/dva/three',
220
                [
221
                    [
222
                        'always-available' => true,
223
                        'translations' => [
224
                            'cro-HR' => 'jedan',
225
                        ],
226
                    ],
227
                    [
228
                        'always-available' => false,
229
                        'translations' => [
230
                            'cro-HR' => 'dva',
231
                            'eng-GB' => 'two',
232
                        ],
233
                    ],
234
                    [
235
                        'always-available' => false,
236
                        'translations' => [
237
                            'cro-HR' => 'tri',
238
                            'eng-GB' => 'three',
239
                            'ger-DE' => 'drei',
240
                        ],
241
                    ],
242
                ],
243
                ['eng-GB'],
244
                false,
245
                316,
246
                '3-35d6d33467aae9a2e3dccb4b6b027878',
247
            ],
248
            [
249
                'jedan/two/tri',
250
                [
251
                    [
252
                        'always-available' => true,
253
                        'translations' => [
254
                            'cro-HR' => 'jedan',
255
                        ],
256
                    ],
257
                    [
258
                        'always-available' => false,
259
                        'translations' => [
260
                            'cro-HR' => 'dva',
261
                            'eng-GB' => 'two',
262
                        ],
263
                    ],
264
                    [
265
                        'always-available' => false,
266
                        'translations' => [
267
                            'cro-HR' => 'tri',
268
                            'eng-GB' => 'three',
269
                            'ger-DE' => 'drei',
270
                        ],
271
                    ],
272
                ],
273
                ['cro-HR'],
274
                false,
275
                316,
276
                '3-d2cfe69af2d64330670e08efb2c86df7',
277
            ],
278
            [
279
                'jedan/dva/drei',
280
                [
281
                    [
282
                        'always-available' => true,
283
                        'translations' => [
284
                            'cro-HR' => 'jedan',
285
                        ],
286
                    ],
287
                    [
288
                        'always-available' => false,
289
                        'translations' => [
290
                            'cro-HR' => 'dva',
291
                            'eng-GB' => 'two',
292
                        ],
293
                    ],
294
                    [
295
                        'always-available' => false,
296
                        'translations' => [
297
                            'cro-HR' => 'tri',
298
                            'eng-GB' => 'three',
299
                            'ger-DE' => 'drei',
300
                        ],
301
                    ],
302
                ],
303
                ['ger-DE'],
304
                false,
305
                316,
306
                '3-1d8d2fd0a99802b89eb356a86e029d25',
307
            ],
308
            [
309
                'jedan/two/drei',
310
                [
311
                    [
312
                        'always-available' => true,
313
                        'translations' => [
314
                            'cro-HR' => 'jedan',
315
                        ],
316
                    ],
317
                    [
318
                        'always-available' => false,
319
                        'translations' => [
320
                            'cro-HR' => 'dva',
321
                            'eng-GB' => 'two',
322
                        ],
323
                    ],
324
                    [
325
                        'always-available' => false,
326
                        'translations' => [
327
                            'cro-HR' => 'tri',
328
                            'eng-GB' => 'three',
329
                            'ger-DE' => 'drei',
330
                        ],
331
                    ],
332
                ],
333
                ['ger-DE'],
334
                false,
335
                316,
336
                '3-1d8d2fd0a99802b89eb356a86e029d25',
337
            ],
338
        ];
339
    }
340
341
    /**
342
     * Test for the lookup() method.
343
     *
344
     * Testing that UrlAlias is found and has expected state.
345
     *
346
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
347
     * @dataProvider providerForTestLookupLocationUrlAlias
348
     * @depends testLookup
349
     * @group location
350
     */
351 View Code Duplication
    public function testLookupLocationUrlAlias(
352
        $url,
353
        array $pathData,
354
        array $languageCodes,
355
        $alwaysAvailable,
356
        $locationId,
357
        $id
358
    ) {
359
        $handler = $this->getHandler();
360
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
361
362
        $urlAlias = $handler->lookup($url);
363
364
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
365
        self::assertEquals(
366
            new UrlAlias(
367
                [
368
                    'id' => $id,
369
                    'type' => UrlAlias::LOCATION,
370
                    'destination' => $locationId,
371
                    'languageCodes' => $languageCodes,
372
                    'pathData' => $pathData,
373
                    'alwaysAvailable' => $alwaysAvailable,
374
                    'isHistory' => false,
375
                    'isCustom' => false,
376
                    'forward' => false,
377
                ]
378
            ),
379
            $urlAlias
380
        );
381
    }
382
383
    /**
384
     * Testing that looking up case incorrect URL results in redirection to case correct path.
385
     *
386
     * Note that case corrected path is not always equal to case corrected case incorrect path, eg. "JEDAN/TWO/THREE"
387
     * will not always redirect to "jedan/two/three".
388
     * In some cases, depending on list of prioritized languages and if Content available in the different language
389
     * higher in the list of prioritized languages, path showing to that Content will be used.
390
     * Example: "JEDAN/TWO/DREI" with "eng-GB" and "ger-DE" as prioritized languages will produce redirection
391
     * to the "jedan/two/three", as "eng-GB" is the most prioritized language and Content that URL alias is pointing
392
     * to is available in it.
393
     *
394
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
395
     * @dataProvider providerForTestLookupLocationUrlAlias
396
     * @depends testLookup
397
     * @group case-correction
398
     * @group location
399
     *
400
     * @todo refactor, only forward pertinent
401
     */
402 View Code Duplication
    public function testLookupLocationCaseCorrection(
403
        $url,
404
        array $pathData,
405
        array $languageCodes,
406
        $alwaysAvailable,
407
        $locationId,
408
        $id
409
    ) {
410
        $handler = $this->getHandler();
411
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
412
413
        $urlAlias = $handler->lookup(strtoupper($url));
414
415
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
416
        self::assertEquals(
417
            new UrlAlias(
418
                [
419
                    'id' => $id,
420
                    'type' => UrlAlias::LOCATION,
421
                    'destination' => $locationId,
422
                    'languageCodes' => $languageCodes,
423
                    'pathData' => $pathData,
424
                    'alwaysAvailable' => $alwaysAvailable,
425
                    'isHistory' => false,
426
                    'isCustom' => false,
427
                    'forward' => false,
428
                ]
429
            ),
430
            $urlAlias
431
        );
432
    }
433
434
    public function providerForTestLookupLocationMultipleLanguages()
435
    {
436
        return [
437
            [
438
                'jedan/dva',
439
                [
440
                    [
441
                        'always-available' => true,
442
                        'translations' => [
443
                            'cro-HR' => 'jedan',
444
                        ],
445
                    ],
446
                    [
447
                        'always-available' => false,
448
                        'translations' => [
449
                            'cro-HR' => 'dva',
450
                            'eng-GB' => 'dva',
451
                        ],
452
                    ],
453
                ],
454
                ['cro-HR', 'eng-GB'],
455
                false,
456
                315,
457
                '2-c67ed9a09ab136fae610b6a087d82e21',
458
            ],
459
            [
460
                'jedan/dva/tri',
461
                [
462
                    [
463
                        'always-available' => true,
464
                        'translations' => [
465
                            'cro-HR' => 'jedan',
466
                        ],
467
                    ],
468
                    [
469
                        'always-available' => false,
470
                        'translations' => [
471
                            'cro-HR' => 'dva',
472
                            'eng-GB' => 'dva',
473
                        ],
474
                    ],
475
                    [
476
                        'always-available' => false,
477
                        'translations' => [
478
                            'cro-HR' => 'tri',
479
                            'eng-GB' => 'three',
480
                        ],
481
                    ],
482
                ],
483
                ['cro-HR'],
484
                false,
485
                316,
486
                '3-d2cfe69af2d64330670e08efb2c86df7',
487
            ],
488
            [
489
                'jedan/dva/three',
490
                [
491
                    [
492
                        'always-available' => true,
493
                        'translations' => [
494
                            'cro-HR' => 'jedan',
495
                        ],
496
                    ],
497
                    [
498
                        'always-available' => false,
499
                        'translations' => [
500
                            'cro-HR' => 'dva',
501
                            'eng-GB' => 'dva',
502
                        ],
503
                    ],
504
                    [
505
                        'always-available' => false,
506
                        'translations' => [
507
                            'cro-HR' => 'tri',
508
                            'eng-GB' => 'three',
509
                        ],
510
                    ],
511
                ],
512
                ['eng-GB'],
513
                false,
514
                316,
515
                '3-35d6d33467aae9a2e3dccb4b6b027878',
516
            ],
517
        ];
518
    }
519
520
    /**
521
     * Test for the lookup() method.
522
     *
523
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
524
     * @dataProvider providerForTestLookupLocationMultipleLanguages
525
     * @depends testLookup
526
     * @group multiple-languages
527
     * @group location
528
     */
529 View Code Duplication
    public function testLookupLocationMultipleLanguages(
530
        $url,
531
        array $pathData,
532
        array $languageCodes,
533
        $alwaysAvailable,
534
        $locationId,
535
        $id
536
    ) {
537
        $handler = $this->getHandler();
538
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
539
540
        $urlAlias = $handler->lookup($url);
541
542
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
543
        self::assertEquals(
544
            new UrlAlias(
545
                [
546
                    'id' => $id,
547
                    'type' => UrlAlias::LOCATION,
548
                    'destination' => $locationId,
549
                    'languageCodes' => $languageCodes,
550
                    'pathData' => $pathData,
551
                    'alwaysAvailable' => $alwaysAvailable,
552
                    'isHistory' => false,
553
                    'isCustom' => false,
554
                    'forward' => false,
555
                ]
556
            ),
557
            $urlAlias
558
        );
559
    }
560
561
    /**
562
     * Test for the lookup() method.
563
     *
564
     * @todo document
565
     *
566
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
567
     * @depends testLookup
568
     * @group history
569
     * @group location
570
     */
571
    public function testLookupLocationHistoryUrlAlias()
572
    {
573
        $handler = $this->getHandler();
574
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
575
576
        $urlAlias = $handler->lookup('jedan/dva/tri-history');
577
578
        self::assertEquals(
579
            $this->getHistoryAlias(),
580
            $urlAlias
581
        );
582
    }
583
584
    public function providerForTestLookupCustomLocationUrlAlias()
585
    {
586
        return [
587
            [
588
                'autogenerated-hello/everybody',
589
                [
590
                    [
591
                        'always-available' => true,
592
                        'translations' => [
593
                            'eng-GB' => 'autogenerated-hello',
594
                        ],
595
                    ],
596
                    [
597
                        'always-available' => true,
598
                        'translations' => [
599
                            'eng-GB' => 'everybody',
600
                        ],
601
                    ],
602
                ],
603
                ['eng-GB'],
604
                false,
605
                true,
606
                315,
607
                '2-88150d7d17390010ba6222de68bfafb5',
608
            ],
609
            [
610
                'hello',
611
                [
612
                    [
613
                        'always-available' => false,
614
                        'translations' => [
615
                            'eng-GB' => 'hello',
616
                        ],
617
                    ],
618
                ],
619
                ['eng-GB'],
620
                true,
621
                false,
622
                314,
623
                '0-5d41402abc4b2a76b9719d911017c592',
624
            ],
625
            [
626
                'hello/and/goodbye',
627
                [
628
                    [
629
                        'always-available' => false,
630
                        'translations' => [
631
                            'eng-GB' => 'hello',
632
                        ],
633
                    ],
634
                    [
635
                        'always-available' => true,
636
                        'translations' => [
637
                            'always-available' => 'and',
638
                        ],
639
                    ],
640
                    [
641
                        'always-available' => false,
642
                        'translations' => [
643
                            'eng-GB' => 'goodbye',
644
                        ],
645
                    ],
646
                ],
647
                ['eng-GB'],
648
                true,
649
                false,
650
                316,
651
                '8-69faab6268350295550de7d587bc323d',
652
            ],
653
            [
654
                'hello/everyone',
655
                [
656
                    [
657
                        'always-available' => false,
658
                        'translations' => [
659
                            'eng-GB' => 'hello',
660
                        ],
661
                    ],
662
                    [
663
                        'always-available' => false,
664
                        'translations' => [
665
                            'eng-GB' => 'everyone',
666
                        ],
667
                    ],
668
                ],
669
                ['eng-GB'],
670
                true,
671
                false,
672
                315,
673
                '6-ed881bac6397ede33c0a285c9f50bb83',
674
            ],
675
            [
676
                'well/ha-ha-ha',
677
                [
678
                    [
679
                        'always-available' => true,
680
                        'translations' => [
681
                            'always-available' => 'well',
682
                        ],
683
                    ],
684
                    [
685
                        'always-available' => false,
686
                        'translations' => [
687
                            'eng-GB' => 'ha-ha-ha',
688
                        ],
689
                    ],
690
                ],
691
                ['eng-GB'],
692
                false,
693
                false,
694
                317,
695
                '10-17a197f4bbe127c368b889a67effd1b3',
696
            ],
697
        ];
698
    }
699
700
    /**
701
     * Test for the lookup() method.
702
     *
703
     * Testing that UrlAlias is found and has expected state.
704
     *
705
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
706
     * @dataProvider providerForTestLookupCustomLocationUrlAlias
707
     * @depends testLookup
708
     * @group location
709
     * @group custom
710
     */
711 View Code Duplication
    public function testLookupCustomLocationUrlAlias(
712
        $url,
713
        array $pathData,
714
        array $languageCodes,
715
        $forward,
716
        $alwaysAvailable,
717
        $destination,
718
        $id
719
    ) {
720
        $handler = $this->getHandler();
721
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
722
723
        $urlAlias = $handler->lookup($url);
724
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
725
        self::assertEquals(
726
            new UrlAlias(
727
                [
728
                    'id' => $id,
729
                    'type' => UrlAlias::LOCATION,
730
                    'destination' => $destination,
731
                    'languageCodes' => $languageCodes,
732
                    'pathData' => $pathData,
733
                    'alwaysAvailable' => $alwaysAvailable,
734
                    'isHistory' => false,
735
                    'isCustom' => true,
736
                    'forward' => $forward,
737
                ]
738
            ),
739
            $urlAlias
740
        );
741
    }
742
743
    /**
744
     * Test for the lookup() method.
745
     *
746
     * Testing that UrlAlias is found and has expected state.
747
     *
748
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
749
     * @dataProvider providerForTestLookupCustomLocationUrlAlias
750
     * @depends testLookup
751
     * @group location
752
     * @group custom
753
     */
754 View Code Duplication
    public function testLookupCustomLocationUrlAliasCaseCorrection(
755
        $url,
756
        array $pathData,
757
        array $languageCodes,
758
        $forward,
759
        $alwaysAvailable,
760
        $destination,
761
        $id
762
    ) {
763
        $handler = $this->getHandler();
764
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
765
766
        $urlAlias = $handler->lookup(strtoupper($url));
767
768
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
769
        self::assertEquals(
770
            new UrlAlias(
771
                [
772
                    'id' => $id,
773
                    'type' => UrlAlias::LOCATION,
774
                    'destination' => $destination,
775
                    'languageCodes' => $languageCodes,
776
                    'pathData' => $pathData,
777
                    'alwaysAvailable' => $alwaysAvailable,
778
                    'isHistory' => false,
779
                    'isCustom' => true,
780
                    'forward' => $forward,
781
                ]
782
            ),
783
            $urlAlias
784
        );
785
    }
786
787
    public function providerForTestLookupVirtualUrlAlias()
788
    {
789
        return [
790
            [
791
                'hello/and',
792
                '6-be5d5d37542d75f93a87094459f76678',
793
            ],
794
            [
795
                'HELLO/AND',
796
                '6-be5d5d37542d75f93a87094459f76678',
797
            ],
798
        ];
799
    }
800
801
    /**
802
     * Test for the lookup() method.
803
     *
804
     * Testing that NOP action redirects to site root.
805
     *
806
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
807
     * @dataProvider providerForTestLookupVirtualUrlAlias
808
     * @depends testLookup
809
     * @group virtual
810
     */
811 View Code Duplication
    public function testLookupVirtualUrlAlias($url, $id)
812
    {
813
        $handler = $this->getHandler();
814
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
815
816
        $urlAlias = $handler->lookup($url);
817
818
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
819
    }
820
821
    public function providerForTestLookupResourceUrlAlias()
822
    {
823
        return [
824
            [
825
                'is-alive',
826
                [
827
                    [
828
                        'always-available' => true,
829
                        'translations' => [
830
                            'eng-GB' => 'is-alive',
831
                        ],
832
                    ],
833
                ],
834
                ['eng-GB'],
835
                true,
836
                true,
837
                'ezinfo/isalive',
838
                '0-d003895fa282a14c8ec3eddf23ca4ca2',
839
            ],
840
            [
841
                'is-alive/then/search',
842
                [
843
                    [
844
                        'always-available' => true,
845
                        'translations' => [
846
                            'eng-GB' => 'is-alive',
847
                        ],
848
                    ],
849
                    [
850
                        'always-available' => true,
851
                        'translations' => [
852
                            'always-available' => 'then',
853
                        ],
854
                    ],
855
                    [
856
                        'always-available' => false,
857
                        'translations' => [
858
                            'cro-HR' => 'search',
859
                        ],
860
                    ],
861
                ],
862
                ['cro-HR'],
863
                false,
864
                false,
865
                'content/search',
866
                '3-06a943c59f33a34bb5924aaf72cd2995',
867
            ],
868
        ];
869
    }
870
871
    /**
872
     * Test for the lookup() method.
873
     *
874
     * Testing that UrlAlias is found and has expected state.
875
     *
876
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
877
     * @dataProvider providerForTestLookupResourceUrlAlias
878
     * @depends testLookup
879
     * @group resource
880
     */
881 View Code Duplication
    public function testLookupResourceUrlAlias(
882
        $url,
883
        $pathData,
884
        array $languageCodes,
885
        $forward,
886
        $alwaysAvailable,
887
        $destination,
888
        $id
889
    ) {
890
        $handler = $this->getHandler();
891
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
892
893
        $urlAlias = $handler->lookup($url);
894
895
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
896
        self::assertEquals(
897
            new UrlAlias(
898
                [
899
                    'id' => $id,
900
                    'type' => UrlAlias::RESOURCE,
901
                    'destination' => $destination,
902
                    'languageCodes' => $languageCodes,
903
                    'pathData' => $pathData,
904
                    'alwaysAvailable' => $alwaysAvailable,
905
                    'isHistory' => false,
906
                    'isCustom' => true,
907
                    'forward' => $forward,
908
                ]
909
            ),
910
            $urlAlias
911
        );
912
    }
913
914
    /**
915
     * Test for the lookup() method.
916
     *
917
     * Testing that UrlAlias is found and has expected state.
918
     *
919
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
920
     * @dataProvider providerForTestLookupResourceUrlAlias
921
     * @depends testLookup
922
     * @group resource
923
     */
924 View Code Duplication
    public function testLookupResourceUrlAliasCaseInsensitive(
925
        $url,
926
        $pathData,
927
        array $languageCodes,
928
        $forward,
929
        $alwaysAvailable,
930
        $destination,
931
        $id
932
    ) {
933
        $handler = $this->getHandler();
934
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
935
936
        $urlAlias = $handler->lookup(strtoupper($url));
937
938
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
939
        self::assertEquals(
940
            new UrlAlias(
941
                [
942
                    'id' => $id,
943
                    'type' => UrlAlias::RESOURCE,
944
                    'destination' => $destination,
945
                    'languageCodes' => $languageCodes,
946
                    'pathData' => $pathData,
947
                    'alwaysAvailable' => $alwaysAvailable,
948
                    'isHistory' => false,
949
                    'isCustom' => true,
950
                    'forward' => $forward,
951
                ]
952
            ),
953
            $urlAlias
954
        );
955
    }
956
957
    /**
958
     * Test for the lookup() method with uppercase utf8 characters.
959
     *
960
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
961
     * @depends testLookup
962
     */
963 View Code Duplication
    public function testLookupUppercaseIri()
964
    {
965
        $handler = $this->getHandler();
966
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_iri.php');
967
968
        $urlAlias = $handler->lookup('΀');
969
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
970
    }
971
972
    protected function assertVirtualUrlAliasValid(UrlAlias $urlAlias, $id)
973
    {
974
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
975
        self::assertEquals($id, $urlAlias->id);
976
        self::assertEquals(UrlAlias::VIRTUAL, $urlAlias->type);
977
        /*self::assertEquals(
978
            new UrlAlias(
979
                array(
980
                    "id" => $id,
981
                    "type" => UrlAlias::VIRTUAL,
982
                    "destination" => null,
983
                    "languageCodes" => array(),
984
                    "pathData" => null,
985
                    "alwaysAvailable" => true,
986
                    "isHistory" => true,
987
                    "isCustom" => false,
988
                    "forward" => false
989
                )
990
            ),
991
            $urlAlias
992
        );*/
993
    }
994
995
    /**
996
     * Test for the listURLAliasesForLocation() method.
997
     *
998
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listURLAliasesForLocation
999
     */
1000
    public function testListURLAliasesForLocation()
1001
    {
1002
        $handler = $this->getHandler();
1003
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
1004
1005
        $urlAliases = $handler->listURLAliasesForLocation(315);
1006
1007
        self::assertEquals(
1008
            [
1009
                new UrlAlias(
1010
                    [
1011
                        'id' => '2-b8a9f715dbb64fd5c56e7783c6820a61',
1012
                        'type' => UrlAlias::LOCATION,
1013
                        'destination' => 315,
1014
                        'languageCodes' => ['eng-GB'],
1015
                        'pathData' => [
1016
                            [
1017
                                'always-available' => true,
1018
                                'translations' => ['cro-HR' => 'jedan'],
1019
                            ],
1020
                            [
1021
                                'always-available' => false,
1022
                                'translations' => [
1023
                                    'cro-HR' => 'dva',
1024
                                    'eng-GB' => 'two',
1025
                                ],
1026
                            ],
1027
                        ],
1028
                        'alwaysAvailable' => false,
1029
                        'isHistory' => false,
1030
                        'isCustom' => false,
1031
                        'forward' => false,
1032
                    ]
1033
                ),
1034
                new UrlAlias(
1035
                    [
1036
                        'id' => '2-c67ed9a09ab136fae610b6a087d82e21',
1037
                        'type' => UrlAlias::LOCATION,
1038
                        'destination' => 315,
1039
                        'languageCodes' => ['cro-HR'],
1040
                        'pathData' => [
1041
                            [
1042
                                'always-available' => true,
1043
                                'translations' => ['cro-HR' => 'jedan'],
1044
                            ],
1045
                            [
1046
                                'always-available' => false,
1047
                                'translations' => [
1048
                                    'cro-HR' => 'dva',
1049
                                    'eng-GB' => 'two',
1050
                                ],
1051
                            ],
1052
                        ],
1053
                        'alwaysAvailable' => false,
1054
                        'isHistory' => false,
1055
                        'isCustom' => false,
1056
                        'forward' => false,
1057
                    ]
1058
                ),
1059
            ],
1060
            $urlAliases
1061
        );
1062
    }
1063
1064
    /**
1065
     * Test for the publishUrlAliasForLocation() method.
1066
     *
1067
     * @todo document
1068
     *
1069
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1070
     * @depends testLookupLocationUrlAlias
1071
     * @group publish
1072
     */
1073 View Code Duplication
    public function testPublishUrlAliasForLocation()
1074
    {
1075
        $handler = $this->getHandler();
1076
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1077
1078
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1079
        $publishedUrlAlias = $handler->lookup('simple');
1080
1081
        self::assertEquals(4, $this->countRows());
1082
        self::assertEquals(
1083
            new UrlAlias(
1084
                [
1085
                    'id' => '0-' . md5('simple'),
1086
                    'type' => UrlAlias::LOCATION,
1087
                    'destination' => 314,
1088
                    'languageCodes' => ['eng-GB'],
1089
                    'pathData' => [
1090
                        [
1091
                            'always-available' => true,
1092
                            'translations' => [
1093
                                'eng-GB' => 'simple',
1094
                                'cro-HR' => 'path314',
1095
                            ],
1096
                        ],
1097
                    ],
1098
                    'alwaysAvailable' => true,
1099
                    'isHistory' => false,
1100
                    'isCustom' => false,
1101
                    'forward' => false,
1102
                ]
1103
            ),
1104
            $publishedUrlAlias
1105
        );
1106
    }
1107
1108
    /**
1109
     * Test for the publishUrlAliasForLocation() method.
1110
     *
1111
     * @todo document
1112
     *
1113
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1114
     * @depends testPublishUrlAliasForLocation
1115
     * @group publish
1116
     */
1117
    public function testPublishUrlAliasForLocationRepublish()
1118
    {
1119
        $handler = $this->getHandler();
1120
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1121
1122
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1123
        $publishedUrlAlias = $handler->lookup('simple');
1124
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1125
        $republishedUrlAlias = $handler->lookup('simple');
1126
1127
        self::assertEquals(4, $this->countRows());
1128
        self::assertEquals(
1129
            $publishedUrlAlias,
1130
            $republishedUrlAlias
1131
        );
1132
    }
1133
1134
    /**
1135
     * Test for the publishUrlAliasForLocation() method.
1136
     *
1137
     * @todo document
1138
     *
1139
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1140
     * @depends testPublishUrlAliasForLocation
1141
     * @group publish
1142
     */
1143 View Code Duplication
    public function testPublishUrlAliasCreatesUniqueAlias()
1144
    {
1145
        $handler = $this->getHandler();
1146
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1147
1148
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1149
        $handler->publishUrlAliasForLocation(315, 2, 'simple', 'eng-GB', true);
1150
        self::assertEquals(5, $this->countRows());
1151
1152
        $urlAlias = $handler->lookup('simple2');
1153
        self::assertEquals(
1154
            new UrlAlias(
1155
                [
1156
                    'id' => '0-' . md5('simple2'),
1157
                    'type' => UrlAlias::LOCATION,
1158
                    'destination' => 315,
1159
                    'languageCodes' => ['eng-GB'],
1160
                    'pathData' => [
1161
                        [
1162
                            'always-available' => true,
1163
                            'translations' => [
1164
                                'eng-GB' => 'simple2',
1165
                            ],
1166
                        ],
1167
                    ],
1168
                    'alwaysAvailable' => true,
1169
                    'isHistory' => false,
1170
                    'isCustom' => false,
1171
                    'forward' => false,
1172
                ]
1173
            ),
1174
            $urlAlias
1175
        );
1176
    }
1177
1178
    /**
1179
     * @return array
1180
     */
1181
    public function providerForTestPublishUrlAliasForLocationComplex()
1182
    {
1183
        return $this->providerForTestLookupLocationUrlAlias();
1184
    }
1185
1186
    /**
1187
     * Test for the publishUrlAliasForLocation() method.
1188
     *
1189
     * @todo document
1190
     *
1191
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1192
     * @dataProvider providerForTestPublishUrlAliasForLocationComplex
1193
     * @depends testPublishUrlAliasForLocation
1194
     * @group publish
1195
     */
1196
    public function testPublishUrlAliasForLocationComplex(
1197
        $url,
1198
        $pathData,
1199
        array $languageCodes,
1200
        $alwaysAvailable,
1201
        $locationId,
1202
        $id
1203
    ) {
1204
        $handler = $this->getHandler();
1205
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1206
1207
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', true);
1208
        $handler->publishUrlAliasForLocation(315, 314, 'dva', 'cro-HR', false);
1209
        $handler->publishUrlAliasForLocation(315, 314, 'two', 'eng-GB', false);
1210
        $handler->publishUrlAliasForLocation(316, 315, 'tri', 'cro-HR', false);
1211
        $handler->publishUrlAliasForLocation(316, 315, 'three', 'eng-GB', false);
1212
        $handler->publishUrlAliasForLocation(316, 315, 'drei', 'ger-DE', false);
1213
1214
        $urlAlias = $handler->lookup($url);
1215
1216
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
1217
        self::assertEquals(
1218
            new UrlAlias(
1219
                [
1220
                    'id' => $id,
1221
                    'type' => UrlAlias::LOCATION,
1222
                    'destination' => $locationId,
1223
                    'languageCodes' => $languageCodes,
1224
                    'pathData' => $pathData,
1225
                    'alwaysAvailable' => $alwaysAvailable,
1226
                    'isHistory' => false,
1227
                    'isCustom' => false,
1228
                    'forward' => false,
1229
                ]
1230
            ),
1231
            $urlAlias
1232
        );
1233
    }
1234
1235
    /**
1236
     * Test for the publishUrlAliasForLocation() method.
1237
     *
1238
     * @todo document
1239
     *
1240
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1241
     * @depends testPublishUrlAliasForLocation
1242
     * @group publish
1243
     */
1244
    public function testPublishUrlAliasForLocationSameAliasForMultipleLanguages()
1245
    {
1246
        $handler = $this->getHandler();
1247
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1248
1249
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1250
        $urlAlias1 = $handler->lookup('jedan');
1251
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB', false);
1252
        $urlAlias2 = $handler->lookup('jedan');
1253
1254
        self::assertEquals(4, $this->countRows());
1255
1256
        foreach ($urlAlias2 as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $urlAlias2 of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
1257
            if ($propertyName === 'languageCodes') {
1258
                self::assertEquals(
1259
                    ['cro-HR', 'eng-GB'],
1260
                    $urlAlias2->languageCodes
1261
                );
1262
            } elseif ($propertyName === 'pathData') {
1263
                self::assertEquals(
1264
                    [
1265
                        [
1266
                            'always-available' => false,
1267
                            'translations' => [
1268
                                'cro-HR' => 'jedan',
1269
                                'eng-GB' => 'jedan',
1270
                            ],
1271
                        ],
1272
                    ],
1273
                    $urlAlias2->pathData
1274
                );
1275
            } else {
1276
                self::assertEquals(
1277
                    $urlAlias1->$propertyName,
1278
                    $urlAlias2->$propertyName
1279
                );
1280
            }
1281
        }
1282
    }
1283
1284
    /**
1285
     * Test for the publishUrlAliasForLocation() method.
1286
     *
1287
     * @todo document
1288
     *
1289
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1290
     * @depends testPublishUrlAliasForLocation
1291
     * @group publish
1292
     */
1293
    public function testPublishUrlAliasForLocationDowngradesOldEntryToHistory()
1294
    {
1295
        $handler = $this->getHandler();
1296
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1297
1298
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1299
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', true);
1300
1301
        self::assertEquals(5, $this->countRows());
1302
1303
        $newUrlAlias = $handler->lookup('dva');
1304
1305
        self::assertEquals(
1306
            new UrlAlias(
1307
                [
1308
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1309
                    'type' => 0,
1310
                    'destination' => 314,
1311
                    'languageCodes' => ['cro-HR'],
1312
                    'pathData' => [
1313
                        [
1314
                            'always-available' => true,
1315
                            'translations' => [
1316
                                'cro-HR' => 'dva',
1317
                            ],
1318
                        ],
1319
                    ],
1320
                    'alwaysAvailable' => true,
1321
                    'isHistory' => false,
1322
                    'isCustom' => false,
1323
                    'forward' => false,
1324
                ]
1325
            ),
1326
            $newUrlAlias
1327
        );
1328
1329
        $historyUrlAlias = $handler->lookup('jedan');
1330
1331
        self::assertEquals(
1332
            new UrlAlias(
1333
                [
1334
                    'id' => '0-6896260129051a949051c3847c34466f',
1335
                    'type' => 0,
1336
                    'destination' => 314,
1337
                    'languageCodes' => ['cro-HR'],
1338
                    'pathData' => [
1339
                        [
1340
                            'always-available' => false,
1341
                            'translations' => [
1342
                                'cro-HR' => 'jedan',
1343
                            ],
1344
                        ],
1345
                    ],
1346
                    'alwaysAvailable' => false,
1347
                    'isHistory' => true,
1348
                    'isCustom' => false,
1349
                    'forward' => false,
1350
                ]
1351
            ),
1352
            $historyUrlAlias
1353
        );
1354
    }
1355
1356
    /**
1357
     * Test for the publishUrlAliasForLocation() method.
1358
     *
1359
     * @todo document
1360
     *
1361
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1362
     * @depends testPublishUrlAliasForLocation
1363
     * @depends testPublishUrlAliasForLocationSameAliasForMultipleLanguages
1364
     * @group publish
1365
     * @group downgrade
1366
     */
1367
    public function testPublishUrlAliasForLocationDowngradesOldEntryRemovesLanguage()
1368
    {
1369
        $handler = $this->getHandler();
1370
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1371
1372
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1373
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB');
1374
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'eng-GB');
1375
1376
        self::assertEquals(5, $this->countRows());
1377
1378
        $urlAlias = $handler->lookup('dva');
1379
        self::assertEquals(
1380
            new UrlAlias(
1381
                [
1382
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1383
                    'type' => UrlAlias::LOCATION,
1384
                    'destination' => 314,
1385
                    'languageCodes' => ['eng-GB'],
1386
                    'pathData' => [
1387
                        [
1388
                            'always-available' => false,
1389
                            'translations' => [
1390
                                'cro-HR' => 'jedan',
1391
                                'eng-GB' => 'dva',
1392
                            ],
1393
                        ],
1394
                    ],
1395
                    'alwaysAvailable' => false,
1396
                    'isHistory' => false,
1397
                    'isCustom' => false,
1398
                    'forward' => false,
1399
                ]
1400
            ),
1401
            $urlAlias
1402
        );
1403
1404
        $downgradedUrlAlias = $handler->lookup('jedan');
1405
        self::assertEquals(
1406
            new UrlAlias(
1407
                [
1408
                    'id' => '0-6896260129051a949051c3847c34466f',
1409
                    'type' => UrlAlias::LOCATION,
1410
                    'destination' => 314,
1411
                    'languageCodes' => ['cro-HR'],
1412
                    'pathData' => [
1413
                        [
1414
                            'always-available' => false,
1415
                            'translations' => [
1416
                                'cro-HR' => 'jedan',
1417
                                'eng-GB' => 'dva',
1418
                            ],
1419
                        ],
1420
                    ],
1421
                    'alwaysAvailable' => false,
1422
                    'isHistory' => false,
1423
                    'isCustom' => false,
1424
                    'forward' => false,
1425
                ]
1426
            ),
1427
            $downgradedUrlAlias
1428
        );
1429
    }
1430
1431
    /**
1432
     * Test for the publishUrlAliasForLocation() method.
1433
     *
1434
     * @todo document
1435
     *
1436
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1437
     * @depends testPublishUrlAliasForLocation
1438
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1439
     * @group publish
1440
     */
1441
    public function testPublishUrlAliasForLocationReusesHistory()
1442
    {
1443
        $handler = $this->getHandler();
1444
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1445
1446
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1447
        $urlAlias = $handler->lookup('jedan');
1448
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR');
1449
        $countBeforeReusing = $this->countRows();
1450
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1451
        $urlAliasReusesHistory = $handler->lookup('jedan');
1452
1453
        self::assertEquals(
1454
            $countBeforeReusing,
1455
            $this->countRows()
1456
        );
1457
1458
        self::assertEquals(
1459
            $urlAlias,
1460
            $urlAliasReusesHistory
1461
        );
1462
    }
1463
1464
    /**
1465
     * Test for the publishUrlAliasForLocation() method.
1466
     *
1467
     * @todo document
1468
     *
1469
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1470
     * @depends testPublishUrlAliasForLocation
1471
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1472
     * @group publish
1473
     */
1474
    public function testPublishUrlAliasForLocationReusesHistoryOfDifferentLanguage()
1475
    {
1476
        $handler = $this->getHandler();
1477
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1478
1479
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1480
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'eng-GB');
1481
        $handler->publishUrlAliasForLocation(314, 2, 'one-new', 'eng-GB');
1482
        $countBeforeReusing = $this->countRows();
1483
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'cro-HR');
1484
        $urlAliasReusesHistory = $handler->lookup('one-history');
1485
1486
        self::assertEquals(
1487
            $countBeforeReusing,
1488
            $this->countRows()
1489
        );
1490
1491
        self::assertEquals(
1492
            new UrlAlias(
1493
                [
1494
                    'id' => '0-' . md5('one-history'),
1495
                    'type' => UrlAlias::LOCATION,
1496
                    'destination' => 314,
1497
                    'languageCodes' => ['cro-HR'],
1498
                    'pathData' => [
1499
                        [
1500
                            'always-available' => false,
1501
                            'translations' => [
1502
                                'cro-HR' => 'one-history',
1503
                                'eng-GB' => 'one-new',
1504
                            ],
1505
                        ],
1506
                    ],
1507
                    'alwaysAvailable' => false,
1508
                    'isHistory' => false,
1509
                    'isCustom' => false,
1510
                    'forward' => false,
1511
                ]
1512
            ),
1513
            $urlAliasReusesHistory
1514
        );
1515
    }
1516
1517
    /**
1518
     * Test for the publishUrlAliasForLocation() method.
1519
     *
1520
     * @todo document
1521
     *
1522
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1523
     * @depends testPublishUrlAliasForLocation
1524
     * @group publish
1525
     */
1526 View Code Duplication
    public function testPublishUrlAliasForLocationReusesCustomAlias()
1527
    {
1528
        $handler = $this->getHandler();
1529
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1530
1531
        $countBeforeReusing = $this->countRows();
1532
        $handler->publishUrlAliasForLocation(314, 2, 'custom-hello', 'eng-GB', false);
1533
        $urlAlias = $handler->lookup('custom-hello');
1534
1535
        self::assertEquals(
1536
            $countBeforeReusing,
1537
            $this->countRows()
1538
        );
1539
        self::assertFalse($urlAlias->isCustom);
1540
    }
1541
1542
    /**
1543
     * Test for the publishUrlAliasForLocation() method.
1544
     *
1545
     * @todo document
1546
     *
1547
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1548
     * @depends testPublishUrlAliasForLocation
1549
     */
1550
    public function testPublishUrlAliasForLocationReusingNopElement()
1551
    {
1552
        $handler = $this->getHandler();
1553
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1554
1555
        $countBeforeReusing = $this->countRows();
1556
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1557
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1558
        $publishedLocationUrlAlias = $handler->lookup('nop-element');
1559
1560
        self::assertEquals(
1561
            $countBeforeReusing,
1562
            $this->countRows()
1563
        );
1564
1565
        self::assertInstanceOf(UrlAlias::class, $publishedLocationUrlAlias);
1566
        self::assertEquals(
1567
            new UrlAlias(
1568
                [
1569
                    'id' => '0-de55c2fff721217cc4cb67b58dc35f85',
1570
                    'type' => UrlAlias::LOCATION,
1571
                    'destination' => 315,
1572
                    'languageCodes' => ['eng-GB'],
1573
                    'pathData' => [
1574
                        [
1575
                            'always-available' => false,
1576
                            'translations' => ['eng-GB' => 'nop-element'],
1577
                        ],
1578
                    ],
1579
                    'alwaysAvailable' => false,
1580
                    'isHistory' => false,
1581
                    'isCustom' => false,
1582
                    'forward' => false,
1583
                ]
1584
            ),
1585
            $publishedLocationUrlAlias
1586
        );
1587
1588
        $virtualUrlAliasReloaded = $handler->lookup('nop-element/search');
1589 View Code Duplication
        foreach ($virtualUrlAliasReloaded as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $virtualUrlAliasReloaded of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1590
            if ($propertyName === 'pathData') {
1591
                self::assertEquals(
1592
                    [
1593
                        [
1594
                            'always-available' => false,
1595
                            'translations' => ['eng-GB' => 'nop-element'],
1596
                        ],
1597
                        [
1598
                            'always-available' => false,
1599
                            'translations' => ['eng-GB' => 'search'],
1600
                        ],
1601
                    ],
1602
                    $virtualUrlAliasReloaded->pathData
1603
                );
1604
            } else {
1605
                self::assertEquals(
1606
                    $virtualUrlAlias->$propertyName,
1607
                    $virtualUrlAliasReloaded->$propertyName
1608
                );
1609
            }
1610
        }
1611
    }
1612
1613
    /**
1614
     * Test for the publishUrlAliasForLocation() method.
1615
     *
1616
     * @todo document
1617
     *
1618
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1619
     * @depends testPublishUrlAliasForLocation
1620
     * @depends testPublishUrlAliasForLocationReusingNopElement
1621
     */
1622
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPath()
1623
    {
1624
        $handler = $this->getHandler();
1625
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1626
1627
        $countBeforeReusing = $this->countRows();
1628
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1629
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1630
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1631
        $virtualUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1632
1633
        self::assertEquals(
1634
            $countBeforeReusing + 1,
1635
            $this->countRows()
1636
        );
1637
1638 View Code Duplication
        foreach ($virtualUrlAliasChanged as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $virtualUrlAliasChanged of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1639
            if ($propertyName === 'pathData') {
1640
                self::assertEquals(
1641
                    [
1642
                        [
1643
                            'always-available' => false,
1644
                            'translations' => ['eng-GB' => 'nop-element-renamed'],
1645
                        ],
1646
                        [
1647
                            'always-available' => false,
1648
                            'translations' => ['eng-GB' => 'search'],
1649
                        ],
1650
                    ],
1651
                    $virtualUrlAliasChanged->pathData
1652
                );
1653
            } else {
1654
                self::assertEquals(
1655
                    $virtualUrlAlias->$propertyName,
1656
                    $virtualUrlAliasChanged->$propertyName
1657
                );
1658
            }
1659
        }
1660
    }
1661
1662
    /**
1663
     * Test for the publishUrlAliasForLocation() method.
1664
     *
1665
     * @todo document
1666
     *
1667
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1668
     * @depends testPublishUrlAliasForLocation
1669
     * @depends testPublishUrlAliasForLocationReusingNopElementChangesCustomPath
1670
     */
1671
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPathAndCreatesHistory()
1672
    {
1673
        $handler = $this->getHandler();
1674
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1675
1676
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1677
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1678
1679
        $customUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1680
        $customUrlAliasHistory = $handler->lookup('nop-element/search');
1681
1682
        self::assertTrue($customUrlAliasHistory->isHistory);
1683
        $customUrlAliasHistory->isHistory = false;
1684
        self::assertEquals(
1685
            $customUrlAliasChanged,
1686
            $customUrlAliasHistory
1687
        );
1688
    }
1689
1690
    /**
1691
     * Test for the publishUrlAliasForLocation() method.
1692
     *
1693
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1694
     */
1695
    public function testPublishUrlAliasForLocationUpdatesLocationPathIdentificationString()
1696
    {
1697
        $handler = $this->getHandler();
1698
        $locationGateway = $this->getLocationGateway();
1699
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1700
1701
        // Publishes the alias indicating that language is main, triggering updating of path_identification_string
1702
        $handler->publishUrlAliasForLocation(316, 315, 'TEST TEST TEST', 'eng-GB', false, true);
1703
1704
        $locationData = $locationGateway->getBasicNodeData(316);
1705
1706
        self::assertEquals('path314/path315/test_test_test', $locationData['path_identification_string']);
1707
    }
1708
1709
    /**
1710
     * Test for the publishUrlAliasForLocation() method.
1711
     *
1712
     * @group cleanup
1713
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1714
     */
1715
    public function testPublishUrlAliasReuseNopCleanupCustomAliasIsDestroyed()
1716
    {
1717
        $handler = $this->getHandler();
1718
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_nop.php');
1719
1720
        $handler->lookup('nop-element/search');
1721
        $handler->publishUrlAliasForLocation(314, 2, 'nop-element', 'cro-HR', false);
1722
1723
        $urlAlias = $handler->lookup('jedan');
1724
        $this->assertEquals(
1725
            new UrlAlias(
1726
                [
1727
                    'id' => '0-' . md5('jedan'),
1728
                    'type' => UrlAlias::LOCATION,
1729
                    'destination' => 314,
1730
                    'pathData' => [
1731
                        [
1732
                            'always-available' => false,
1733
                            'translations' => ['cro-HR' => 'jedan'],
1734
                        ],
1735
                    ],
1736
                    'languageCodes' => ['cro-HR'],
1737
                    'alwaysAvailable' => false,
1738
                    'isHistory' => true,
1739
                    'isCustom' => false,
1740
                    'forward' => false,
1741
                ]
1742
            ),
1743
            $urlAlias
1744
        );
1745
1746
        $urlAlias = $handler->lookup('nop-element');
1747
        $this->assertEquals(
1748
            new UrlAlias(
1749
                [
1750
                    'id' => '0-' . md5('nop-element'),
1751
                    'type' => UrlAlias::LOCATION,
1752
                    'destination' => 314,
1753
                    'pathData' => [
1754
                        [
1755
                            'always-available' => false,
1756
                            'translations' => [
1757
                                'cro-HR' => 'nop-element',
1758
                                'eng-GB' => 'dva',
1759
                            ],
1760
                        ],
1761
                    ],
1762
                    'languageCodes' => [
1763
                        'cro-HR',
1764
                    ],
1765
                    'alwaysAvailable' => false,
1766
                    'isHistory' => false,
1767
                    'isCustom' => false,
1768
                    'forward' => false,
1769
                ]
1770
            ),
1771
            $urlAlias
1772
        );
1773
1774
        try {
1775
            $handler->lookup('nop-element/search');
1776
            $this->fail('Custom alias is not destroyed');
1777
        } catch (NotFoundException $e) {
1778
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
1779
            // on the same level (that means link and ID are updated to the existing alias ID,
1780
            // so custom alias children entries are no longer properly linked (parent-link))
1781
        }
1782
    }
1783
1784
    /**
1785
     * Test for the publishUrlAliasForLocation() method.
1786
     *
1787
     * @group cleanup
1788
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1789
     */
1790 View Code Duplication
    public function testPublishUrlAliasReuseHistoryCleanup()
1791
    {
1792
        $handler = $this->getHandler();
1793
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_history.php');
1794
1795
        $handler->publishUrlAliasForLocation(314, 2, 'tri', 'cro-HR', false);
1796
1797
        $urlAlias = $handler->lookup('jedan');
1798
        $this->assertEquals(
1799
            new UrlAlias(
1800
                [
1801
                    'id' => '0-' . md5('jedan'),
1802
                    'type' => UrlAlias::LOCATION,
1803
                    'destination' => 314,
1804
                    'pathData' => [
1805
                        [
1806
                            'always-available' => false,
1807
                            'translations' => ['cro-HR' => 'jedan'],
1808
                        ],
1809
                    ],
1810
                    'languageCodes' => ['cro-HR'],
1811
                    'alwaysAvailable' => false,
1812
                    'isHistory' => true,
1813
                    'isCustom' => false,
1814
                    'forward' => false,
1815
                ]
1816
            ),
1817
            $urlAlias
1818
        );
1819
1820
        $urlAlias = $handler->lookup('tri');
1821
        $this->assertEquals(
1822
            new UrlAlias(
1823
                [
1824
                    'id' => '0-' . md5('tri'),
1825
                    'type' => UrlAlias::LOCATION,
1826
                    'destination' => 314,
1827
                    'pathData' => [
1828
                        [
1829
                            'always-available' => false,
1830
                            'translations' => [
1831
                                'cro-HR' => 'tri',
1832
                                'eng-GB' => 'dva',
1833
                            ],
1834
                        ],
1835
                    ],
1836
                    'languageCodes' => [
1837
                        'cro-HR',
1838
                    ],
1839
                    'alwaysAvailable' => false,
1840
                    'isHistory' => false,
1841
                    'isCustom' => false,
1842
                    'forward' => false,
1843
                ]
1844
            ),
1845
            $urlAlias
1846
        );
1847
    }
1848
1849
    /**
1850
     * Test for the publishUrlAliasForLocation() method.
1851
     *
1852
     * @group cleanup
1853
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1854
     */
1855 View Code Duplication
    public function testPublishUrlAliasReuseAutogeneratedCleanup()
1856
    {
1857
        $handler = $this->getHandler();
1858
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_reusing.php');
1859
1860
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', false);
1861
1862
        $urlAlias = $handler->lookup('jedan');
1863
        $this->assertEquals(
1864
            new UrlAlias(
1865
                [
1866
                    'id' => '0-' . md5('jedan'),
1867
                    'type' => UrlAlias::LOCATION,
1868
                    'destination' => 314,
1869
                    'pathData' => [
1870
                        [
1871
                            'always-available' => false,
1872
                            'translations' => ['cro-HR' => 'jedan'],
1873
                        ],
1874
                    ],
1875
                    'languageCodes' => ['cro-HR'],
1876
                    'alwaysAvailable' => false,
1877
                    'isHistory' => true,
1878
                    'isCustom' => false,
1879
                    'forward' => false,
1880
                ]
1881
            ),
1882
            $urlAlias
1883
        );
1884
1885
        $urlAlias = $handler->lookup('dva');
1886
        $this->assertEquals(
1887
            new UrlAlias(
1888
                [
1889
                    'id' => '0-' . md5('dva'),
1890
                    'type' => UrlAlias::LOCATION,
1891
                    'destination' => 314,
1892
                    'pathData' => [
1893
                        [
1894
                            'always-available' => false,
1895
                            'translations' => [
1896
                                'cro-HR' => 'dva',
1897
                                'eng-GB' => 'dva',
1898
                            ],
1899
                        ],
1900
                    ],
1901
                    'languageCodes' => [
1902
                        'cro-HR',
1903
                        'eng-GB',
1904
                    ],
1905
                    'alwaysAvailable' => false,
1906
                    'isHistory' => false,
1907
                    'isCustom' => false,
1908
                    'forward' => false,
1909
                ]
1910
            ),
1911
            $urlAlias
1912
        );
1913
    }
1914
1915
    /**
1916
     * Test for the createCustomUrlAlias() method.
1917
     *
1918
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createCustomUrlAlias
1919
     * @group create
1920
     * @group custom
1921
     */
1922 View Code Duplication
    public function testCreateCustomUrlAliasBehaviour()
1923
    {
1924
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1925
1926
        $handlerMock->expects(
1927
            $this->once()
1928
        )->method(
1929
            'createUrlAlias'
1930
        )->with(
1931
            $this->equalTo('eznode:1'),
1932
            $this->equalTo('path'),
1933
            $this->equalTo(false),
1934
            $this->equalTo(null),
1935
            $this->equalTo(false)
1936
        )->will(
1937
            $this->returnValue(
1938
                new UrlAlias()
1939
            )
1940
        );
1941
1942
        $this->assertInstanceOf(
1943
            UrlAlias::class,
1944
            $handlerMock->createCustomUrlAlias(1, 'path')
1945
        );
1946
    }
1947
1948
    /**
1949
     * Test for the createGlobalUrlAlias() method.
1950
     *
1951
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createGlobalUrlAlias
1952
     * @group create
1953
     * @group global
1954
     */
1955 View Code Duplication
    public function testCreateGlobalUrlAliasBehaviour()
1956
    {
1957
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1958
1959
        $handlerMock->expects(
1960
            $this->once()
1961
        )->method(
1962
            'createUrlAlias'
1963
        )->with(
1964
            $this->equalTo('module/module'),
1965
            $this->equalTo('path'),
1966
            $this->equalTo(false),
1967
            $this->equalTo(null),
1968
            $this->equalTo(false)
1969
        )->will(
1970
            $this->returnValue(
1971
                new UrlAlias()
1972
            )
1973
        );
1974
1975
        $this->assertInstanceOf(
1976
            UrlAlias::class,
1977
            $handlerMock->createGlobalUrlAlias('module/module', 'path')
1978
        );
1979
    }
1980
1981
    /**
1982
     * Test for the createUrlAlias() method.
1983
     *
1984
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
1985
     * @group create
1986
     * @group custom
1987
     */
1988
    public function testCreateCustomUrlAlias()
1989
    {
1990
        $handler = $this->getHandler();
1991
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1992
1993
        $path = 'custom-location-alias';
1994
        $customUrlAlias = $handler->createCustomUrlAlias(
1995
            314,
1996
            $path,
1997
            false,
1998
            'cro-HR',
1999
            false
2000
        );
2001
2002
        self::assertEquals(4, $this->countRows());
2003
        self::assertEquals(
2004
            new UrlAlias(
2005
                [
2006
                    'id' => '0-' . md5($path),
2007
                    'type' => UrlAlias::LOCATION,
2008
                    'destination' => 314,
2009
                    'pathData' => [
2010
                        [
2011
                            'always-available' => false,
2012
                            'translations' => [
2013
                                'cro-HR' => 'custom-location-alias',
2014
                            ],
2015
                        ],
2016
                    ],
2017
                    'languageCodes' => ['cro-HR'],
2018
                    'alwaysAvailable' => false,
2019
                    'isHistory' => false,
2020
                    'isCustom' => true,
2021
                    'forward' => false,
2022
                ]
2023
            ),
2024
            $customUrlAlias
2025
        );
2026
    }
2027
2028
    /**
2029
     * Test for the createUrlAlias() method.
2030
     *
2031
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2032
     * @group create
2033
     * @group custom
2034
     */
2035
    public function testCreateCustomUrlAliasWithNonameParts()
2036
    {
2037
        $handler = $this->getHandler();
2038
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2039
2040
        $path = 'there-is-a//custom-location-alias//here';
2041
        $customUrlAlias = $handler->createCustomUrlAlias(
2042
            314,
2043
            $path,
2044
            false,
2045
            'cro-HR',
2046
            false
2047
        );
2048
2049
        self::assertEquals(8, $this->countRows());
2050
2051
        self::assertEquals(
2052
            new UrlAlias(
2053
                [
2054
                    'id' => '7-' . md5('here'),
2055
                    'type' => UrlAlias::LOCATION,
2056
                    'destination' => 314,
2057
                    'pathData' => [
2058
                        [
2059
                            'always-available' => true,
2060
                            'translations' => [
2061
                                'always-available' => 'there-is-a',
2062
                            ],
2063
                        ],
2064
                        [
2065
                            'always-available' => true,
2066
                            'translations' => [
2067
                                'always-available' => 'noname2',
2068
                            ],
2069
                        ],
2070
                        [
2071
                            'always-available' => true,
2072
                            'translations' => [
2073
                                'always-available' => 'custom-location-alias',
2074
                            ],
2075
                        ],
2076
                        [
2077
                            'always-available' => true,
2078
                            'translations' => [
2079
                                'always-available' => 'noname4',
2080
                            ],
2081
                        ],
2082
                        [
2083
                            'always-available' => false,
2084
                            'translations' => [
2085
                                'cro-HR' => 'here',
2086
                            ],
2087
                        ],
2088
                    ],
2089
                    'languageCodes' => ['cro-HR'],
2090
                    'alwaysAvailable' => false,
2091
                    'isHistory' => false,
2092
                    'isCustom' => true,
2093
                    'forward' => false,
2094
                ]
2095
            ),
2096
            $customUrlAlias
2097
        );
2098
    }
2099
2100
    /**
2101
     * Test for the createUrlAlias() method.
2102
     *
2103
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2104
     * @group create
2105
     * @group custom
2106
     *
2107
     * @todo pathData
2108
     */
2109
    public function testCreatedCustomUrlAliasIsLoadable()
2110
    {
2111
        $handler = $this->getHandler();
2112
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2113
2114
        $path = 'custom-location-alias';
2115
        $customUrlAlias = $handler->createCustomUrlAlias(
2116
            314,
2117
            $path,
2118
            false,
2119
            'cro-HR',
2120
            false
2121
        );
2122
        $loadedCustomUrlAlias = $handler->lookup($path);
2123
2124
        self::assertEquals(4, $this->countRows());
2125
2126
        foreach ($loadedCustomUrlAlias as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $loadedCustomUrlAlias of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
2127
            if ($propertyName === 'pathData') {
2128
                self::assertEquals(
2129
                    [
2130
                        [
2131
                            'always-available' => false,
2132
                            'translations' => ['cro-HR' => $path],
2133
                        ],
2134
                    ],
2135
                    $loadedCustomUrlAlias->$propertyName
2136
                );
2137
            } else {
2138
                self::assertEquals(
2139
                    $customUrlAlias->$propertyName,
2140
                    $loadedCustomUrlAlias->$propertyName
2141
                );
2142
            }
2143
        }
2144
    }
2145
2146
    /**
2147
     * Test for the createUrlAlias() method.
2148
     *
2149
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2150
     * @group create
2151
     * @group custom
2152
     */
2153
    public function testCreateCustomUrlAliasWithNopElement(): void
2154
    {
2155
        $handler = $this->getHandler();
2156
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2157
2158
        $path = 'ribar/palunko';
2159
        $customUrlAlias = $handler->createCustomUrlAlias(
2160
            314,
2161
            $path,
2162
            false,
2163
            'cro-HR',
2164
            true
2165
        );
2166
2167
        self::assertEquals(5, $this->countRows());
2168
        self::assertEquals(
2169
            new UrlAlias(
2170
                [
2171
                    'id' => '4-' . md5('palunko'),
2172
                    'type' => UrlAlias::LOCATION,
2173
                    'destination' => 314,
2174
                    'pathData' => [
2175
                        [
2176
                            'always-available' => true,
2177
                            'translations' => [
2178
                                'always-available' => 'ribar',
2179
                            ],
2180
                        ],
2181
                        [
2182
                            'always-available' => true,
2183
                            'translations' => [
2184
                                'cro-HR' => 'palunko',
2185
                            ],
2186
                        ],
2187
                    ],
2188
                    'languageCodes' => ['cro-HR'],
2189
                    'alwaysAvailable' => true,
2190
                    'isHistory' => false,
2191
                    'isCustom' => true,
2192
                    'forward' => false,
2193
                ]
2194
            ),
2195
            $customUrlAlias
2196
        );
2197
2198
        // test that valid NOP element has been created
2199
        $url = 'ribar';
2200
        $urlAlias = $handler->lookup($url);
2201
2202
        $this->assertVirtualUrlAliasValid(
2203
            $urlAlias,
2204
            '0-' . md5($url)
2205
        );
2206
    }
2207
2208
    /**
2209
     * Test for the createUrlAlias() method.
2210
     *
2211
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2212
     * @group create
2213
     * @group custom
2214
     */
2215 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistory()
2216
    {
2217
        $handler = $this->getHandler();
2218
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2219
2220
        $countBeforeReusing = $this->countRows();
2221
        $handler->createCustomUrlAlias(
2222
            314,
2223
            'history-hello',
2224
            true,
2225
            'eng-GB',
2226
            true
2227
        );
2228
2229
        self::assertEquals(
2230
            $countBeforeReusing,
2231
            $this->countRows()
2232
        );
2233
        self::assertEquals(
2234
            new UrlAlias(
2235
                [
2236
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2237
                    'type' => UrlAlias::LOCATION,
2238
                    'destination' => 314,
2239
                    'languageCodes' => ['eng-GB'],
2240
                    'pathData' => [
2241
                        [
2242
                            'always-available' => true,
2243
                            'translations' => ['eng-GB' => 'history-hello'],
2244
                        ],
2245
                    ],
2246
                    'alwaysAvailable' => true,
2247
                    'isHistory' => false,
2248
                    'isCustom' => true,
2249
                    'forward' => true,
2250
                ]
2251
            ),
2252
            $handler->lookup('history-hello')
2253
        );
2254
    }
2255
2256
    /**
2257
     * Test for the createUrlAlias() method.
2258
     *
2259
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2260
     * @group create
2261
     * @group custom
2262
     */
2263
    public function testCreateCustomUrlAliasAddLanguage()
2264
    {
2265
        $handler = $this->getHandler();
2266
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2267
2268
        $countBeforeReusing = $this->countRows();
2269
        $handler->createCustomUrlAlias(
2270
            314,
2271
            'path314',
2272
            false,
2273
            'eng-GB',
2274
            true
2275
        );
2276
2277
        self::assertEquals(
2278
            $countBeforeReusing,
2279
            $this->countRows()
2280
        );
2281
        self::assertEquals(
2282
            new UrlAlias(
2283
                [
2284
                    'id' => '0-fdbbfa1e24e78ef56cb16ba4482c7771',
2285
                    'type' => UrlAlias::LOCATION,
2286
                    'destination' => '314',
2287
                    'languageCodes' => ['cro-HR', 'eng-GB'],
2288
                    'pathData' => [
2289
                        [
2290
                            'always-available' => true,
2291
                            'translations' => [
2292
                                'cro-HR' => 'path314',
2293
                                'eng-GB' => 'path314',
2294
                            ],
2295
                        ],
2296
                    ],
2297
                    'alwaysAvailable' => true,
2298
                    'isHistory' => false,
2299
                    'isCustom' => true,
2300
                    'forward' => false,
2301
                ]
2302
            ),
2303
            $handler->lookup('path314')
2304
        );
2305
    }
2306
2307
    /**
2308
     * Test for the createUrlAlias() method.
2309
     *
2310
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2311
     * @group create
2312
     * @group custom
2313
     */
2314 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistoryOfDifferentLanguage()
2315
    {
2316
        $handler = $this->getHandler();
2317
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2318
2319
        $countBeforeReusing = $this->countRows();
2320
        $handler->createCustomUrlAlias(
2321
            314,
2322
            'history-hello',
2323
            true,
2324
            'cro-HR',
2325
            true
2326
        );
2327
2328
        self::assertEquals(
2329
            $countBeforeReusing,
2330
            $this->countRows()
2331
        );
2332
        self::assertEquals(
2333
            new UrlAlias(
2334
                [
2335
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2336
                    'type' => UrlAlias::LOCATION,
2337
                    'destination' => 314,
2338
                    'languageCodes' => ['cro-HR'],
2339
                    'pathData' => [
2340
                        [
2341
                            'always-available' => true,
2342
                            'translations' => ['cro-HR' => 'history-hello'],
2343
                        ],
2344
                    ],
2345
                    'alwaysAvailable' => true,
2346
                    'isHistory' => false,
2347
                    'isCustom' => true,
2348
                    'forward' => true,
2349
                ]
2350
            ),
2351
            $handler->lookup('history-hello')
2352
        );
2353
    }
2354
2355
    /**
2356
     * Test for the createUrlAlias() method.
2357
     *
2358
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2359
     * @group create
2360
     * @group custom
2361
     */
2362
    public function testCreateCustomUrlAliasReusesNopElement()
2363
    {
2364
        $handler = $this->getHandler();
2365
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2366
2367
        $countBeforeReusing = $this->countRows();
2368
        $handler->createCustomUrlAlias(
2369
            314,
2370
            'nop-element',
2371
            true,
2372
            'cro-HR',
2373
            true
2374
        );
2375
2376
        self::assertEquals(
2377
            $countBeforeReusing,
2378
            $this->countRows()
2379
        );
2380
2381
        // Check that custom alias whose nop element was reused still works as expected
2382
        self::assertEquals(
2383
            new UrlAlias(
2384
                [
2385
                    'id' => '2-06a943c59f33a34bb5924aaf72cd2995',
2386
                    'type' => UrlAlias::RESOURCE,
2387
                    'destination' => 'content/search',
2388
                    'languageCodes' => ['eng-GB'],
2389
                    'pathData' => [
2390
                        [
2391
                            'always-available' => true,
2392
                            'translations' => ['cro-HR' => 'nop-element'],
2393
                        ],
2394
                        [
2395
                            'always-available' => false,
2396
                            'translations' => ['eng-GB' => 'search'],
2397
                        ],
2398
                    ],
2399
                    'alwaysAvailable' => false,
2400
                    'isHistory' => false,
2401
                    'isCustom' => true,
2402
                    'forward' => false,
2403
                ]
2404
            ),
2405
            $handler->lookup('nop-element/search')
2406
        );
2407
    }
2408
2409
    /**
2410
     * Test for the createUrlAlias() method.
2411
     *
2412
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2413
     * @group create
2414
     * @group custom
2415
     */
2416 View Code Duplication
    public function testCreateCustomUrlAliasReusesLocationElement()
2417
    {
2418
        $handler = $this->getHandler();
2419
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2420
2421
        $countBeforeReusing = $this->countRows();
2422
        $locationUrlAlias = $handler->lookup('autogenerated-hello');
2423
        $handler->createCustomUrlAlias(
2424
            315,
2425
            'autogenerated-hello/custom-location-alias-for-315',
2426
            true,
2427
            'cro-HR',
2428
            true
2429
        );
2430
2431
        self::assertEquals(
2432
            $countBeforeReusing + 1,
2433
            $this->countRows()
2434
        );
2435
2436
        // Check that location alias still works as expected
2437
        self::assertEquals(
2438
            $locationUrlAlias,
2439
            $handler->lookup('autogenerated-hello')
2440
        );
2441
    }
2442
2443
    /**
2444
     * Test for the listGlobalURLAliases() method.
2445
     *
2446
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2447
     * @depends testLookupResourceUrlAlias
2448
     */
2449
    public function testListGlobalURLAliases()
2450
    {
2451
        $handler = $this->getHandler();
2452
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2453
2454
        $globalAliasList = $handler->listGlobalURLAliases();
2455
2456
        self::assertEquals(
2457
            [
2458
                $handler->lookup('is-alive'),
2459
                $handler->lookup('is-alive/then/search'),
2460
                $handler->lookup('nop-element/search'),
2461
            ],
2462
            $globalAliasList
2463
        );
2464
    }
2465
2466
    /**
2467
     * Test for the listGlobalURLAliases() method.
2468
     *
2469
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2470
     * @depends testLookupResourceUrlAlias
2471
     */
2472 View Code Duplication
    public function testListGlobalURLAliasesWithLanguageCode()
2473
    {
2474
        $handler = $this->getHandler();
2475
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2476
2477
        $globalAliasList = $handler->listGlobalURLAliases('eng-GB');
2478
2479
        self::assertEquals(
2480
            [
2481
                $handler->lookup('is-alive'),
2482
                $handler->lookup('nop-element/search'),
2483
            ],
2484
            $globalAliasList
2485
        );
2486
    }
2487
2488
    /**
2489
     * Test for the listGlobalURLAliases() method.
2490
     *
2491
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2492
     * @depends testLookupResourceUrlAlias
2493
     */
2494
    public function testListGlobalURLAliasesWithOffset()
2495
    {
2496
        $handler = $this->getHandler();
2497
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2498
2499
        $globalAliasList = $handler->listGlobalURLAliases(null, 2);
2500
2501
        self::assertEquals(
2502
            [
2503
                $handler->lookup('nop-element/search'),
2504
            ],
2505
            $globalAliasList
2506
        );
2507
    }
2508
2509
    /**
2510
     * Test for the listGlobalURLAliases() method.
2511
     *
2512
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2513
     * @depends testLookupResourceUrlAlias
2514
     */
2515
    public function testListGlobalURLAliasesWithOffsetAndLimit()
2516
    {
2517
        $handler = $this->getHandler();
2518
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2519
2520
        $globalAliasList = $handler->listGlobalURLAliases(null, 1, 1);
2521
2522
        self::assertEquals(
2523
            [
2524
                $handler->lookup('is-alive/then/search'),
2525
            ],
2526
            $globalAliasList
2527
        );
2528
    }
2529
2530
    /**
2531
     * Test for the locationDeleted() method.
2532
     *
2533
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationDeleted
2534
     */
2535
    public function testLocationDeleted()
2536
    {
2537
        $handler = $this->getHandler();
2538
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_delete.php');
2539
2540
        $countBeforeDeleting = $this->countRows();
2541
2542
        $handler->locationDeleted(5);
2543
2544
        self::assertEquals(
2545
            $countBeforeDeleting - 5,
2546
            $this->countRows()
2547
        );
2548
2549
        self::assertEmpty(
2550
            $handler->listURLAliasesForLocation(5)
2551
        );
2552
2553
        $removedAliases = [
2554
            'moved-original-parent/moved-history',
2555
            'moved-original-parent/sub',
2556
            'moved-original-parent',
2557
            'moved-original-parent-history',
2558
            'custom-below/moved-original-parent-custom',
2559
        ];
2560
        foreach ($removedAliases as $path) {
2561
            try {
2562
                $handler->lookup($path);
2563
                $this->fail("Alias '$path' not removed!");
2564
            } catch (NotFoundException $e) {
2565
                // Do nothing
2566
            }
2567
        }
2568
    }
2569
2570
    /**
2571
     * Test for the locationMoved() method.
2572
     *
2573
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2574
     */
2575 View Code Duplication
    public function testLocationMovedHistorize()
2576
    {
2577
        $handler = $this->getHandler();
2578
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2579
2580
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2581
        $handler->locationMoved(4, 2, 3);
2582
2583
        $urlAlias = $handler->lookup('move-this');
2584
        self::assertEquals(
2585
            new UrlAlias(
2586
                [
2587
                    'id' => '0-' . md5('move-this'),
2588
                    'type' => UrlAlias::LOCATION,
2589
                    'destination' => '4',
2590
                    'languageCodes' => ['eng-GB'],
2591
                    'pathData' => [
2592
                        [
2593
                            'always-available' => false,
2594
                            'translations' => ['eng-GB' => 'move-this'],
2595
                        ],
2596
                    ],
2597
                    'alwaysAvailable' => false,
2598
                    'isHistory' => true,
2599
                    'isCustom' => false,
2600
                    'forward' => false,
2601
                ]
2602
            ),
2603
            $urlAlias
2604
        );
2605
    }
2606
2607
    /**
2608
     * Test for the locationMoved() method.
2609
     *
2610
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2611
     */
2612 View Code Duplication
    public function testLocationMovedHistory()
2613
    {
2614
        $handler = $this->getHandler();
2615
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2616
2617
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2618
        $handler->locationMoved(4, 2, 3);
2619
2620
        $urlAlias = $handler->lookup('move-this-history');
2621
        self::assertEquals(
2622
            new UrlAlias(
2623
                [
2624
                    'id' => '0-' . md5('move-this-history'),
2625
                    'type' => UrlAlias::LOCATION,
2626
                    'destination' => '4',
2627
                    'languageCodes' => ['eng-GB'],
2628
                    'pathData' => [
2629
                        [
2630
                            'always-available' => false,
2631
                            'translations' => ['eng-GB' => 'move-this-history'],
2632
                        ],
2633
                    ],
2634
                    'alwaysAvailable' => false,
2635
                    'isHistory' => true,
2636
                    'isCustom' => false,
2637
                    'forward' => false,
2638
                ]
2639
            ),
2640
            $urlAlias
2641
        );
2642
    }
2643
2644
    /**
2645
     * Test for the locationMoved() method.
2646
     *
2647
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2648
     */
2649 View Code Duplication
    public function testLocationMovedHistorySubtree()
2650
    {
2651
        $handler = $this->getHandler();
2652
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2653
2654
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2655
        $handler->locationMoved(4, 2, 3);
2656
2657
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2658
        self::assertEquals(
2659
            new UrlAlias(
2660
                [
2661
                    'id' => '5-' . md5('sub2'),
2662
                    'type' => UrlAlias::LOCATION,
2663
                    'destination' => '6',
2664
                    'languageCodes' => ['eng-GB'],
2665
                    'pathData' => [
2666
                        [
2667
                            'always-available' => false,
2668
                            'translations' => ['eng-GB' => 'move-this'],
2669
                        ],
2670
                        [
2671
                            'always-available' => false,
2672
                            'translations' => ['eng-GB' => 'sub1'],
2673
                        ],
2674
                        [
2675
                            'always-available' => false,
2676
                            'translations' => ['eng-GB' => 'sub2'],
2677
                        ],
2678
                    ],
2679
                    'alwaysAvailable' => false,
2680
                    'isHistory' => true,
2681
                    'isCustom' => false,
2682
                    'forward' => false,
2683
                ]
2684
            ),
2685
            $urlAlias
2686
        );
2687
    }
2688
2689
    /**
2690
     * Test for the locationMoved() method.
2691
     *
2692
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2693
     */
2694 View Code Duplication
    public function testLocationMovedReparent()
2695
    {
2696
        $handler = $this->getHandler();
2697
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2698
2699
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2700
        $handler->locationMoved(4, 2, 3);
2701
2702
        $urlAlias = $handler->lookup('move-here/move-this/sub1');
2703
        self::assertEquals(
2704
            new UrlAlias(
2705
                [
2706
                    'id' => '9-' . md5('sub1'),
2707
                    'type' => UrlAlias::LOCATION,
2708
                    'destination' => '5',
2709
                    'languageCodes' => ['eng-GB'],
2710
                    'pathData' => [
2711
                        [
2712
                            'always-available' => false,
2713
                            'translations' => ['eng-GB' => 'move-here'],
2714
                        ],
2715
                        [
2716
                            'always-available' => false,
2717
                            'translations' => ['eng-GB' => 'move-this'],
2718
                        ],
2719
                        [
2720
                            'always-available' => false,
2721
                            'translations' => ['eng-GB' => 'sub1'],
2722
                        ],
2723
                    ],
2724
                    'alwaysAvailable' => false,
2725
                    'isHistory' => false,
2726
                    'isCustom' => false,
2727
                    'forward' => false,
2728
                ]
2729
            ),
2730
            $urlAlias
2731
        );
2732
    }
2733
2734
    /**
2735
     * Test for the locationMoved() method.
2736
     *
2737
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2738
     */
2739
    public function testLocationMovedReparentHistory()
2740
    {
2741
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);
2742
2743
        $handler = $this->getHandler();
2744
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2745
2746
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2747
        $handler->locationMoved(4, 2, 3);
2748
2749
        $handler->lookup('move-here/move-this-history');
2750
    }
2751
2752
    /**
2753
     * Test for the locationMoved() method.
2754
     *
2755
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2756
     */
2757 View Code Duplication
    public function testLocationMovedReparentSubtree()
2758
    {
2759
        $handler = $this->getHandler();
2760
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2761
2762
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2763
        $handler->locationMoved(4, 2, 3);
2764
2765
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2766
        self::assertEquals(
2767
            new UrlAlias(
2768
                [
2769
                    'id' => '5-' . md5('sub2'),
2770
                    'type' => UrlAlias::LOCATION,
2771
                    'destination' => '6',
2772
                    'languageCodes' => ['eng-GB'],
2773
                    'pathData' => [
2774
                        [
2775
                            'always-available' => false,
2776
                            'translations' => ['eng-GB' => 'move-here'],
2777
                        ],
2778
                        [
2779
                            'always-available' => false,
2780
                            'translations' => ['eng-GB' => 'move-this'],
2781
                        ],
2782
                        [
2783
                            'always-available' => false,
2784
                            'translations' => ['eng-GB' => 'sub1'],
2785
                        ],
2786
                        [
2787
                            'always-available' => false,
2788
                            'translations' => ['eng-GB' => 'sub2'],
2789
                        ],
2790
                    ],
2791
                    'alwaysAvailable' => false,
2792
                    'isHistory' => false,
2793
                    'isCustom' => false,
2794
                    'forward' => false,
2795
                ]
2796
            ),
2797
            $urlAlias
2798
        );
2799
    }
2800
2801
    /**
2802
     * Test for the locationMoved() method.
2803
     *
2804
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2805
     */
2806 View Code Duplication
    public function testLocationMovedReparentSubtreeHistory()
2807
    {
2808
        $handler = $this->getHandler();
2809
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2810
2811
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2812
        $handler->locationMoved(4, 2, 3);
2813
2814
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2-history');
2815
        self::assertEquals(
2816
            new UrlAlias(
2817
                [
2818
                    'id' => '5-' . md5('sub2-history'),
2819
                    'type' => UrlAlias::LOCATION,
2820
                    'destination' => '6',
2821
                    'languageCodes' => ['eng-GB'],
2822
                    'pathData' => [
2823
                        [
2824
                            'always-available' => false,
2825
                            'translations' => ['eng-GB' => 'move-here'],
2826
                        ],
2827
                        [
2828
                            'always-available' => false,
2829
                            'translations' => ['eng-GB' => 'move-this'],
2830
                        ],
2831
                        [
2832
                            'always-available' => false,
2833
                            'translations' => ['eng-GB' => 'sub1'],
2834
                        ],
2835
                        [
2836
                            'always-available' => false,
2837
                            'translations' => ['eng-GB' => 'sub2-history'],
2838
                        ],
2839
                    ],
2840
                    'alwaysAvailable' => false,
2841
                    'isHistory' => true,
2842
                    'isCustom' => false,
2843
                    'forward' => false,
2844
                ]
2845
            ),
2846
            $urlAlias
2847
        );
2848
    }
2849
2850
    /**
2851
     * Test for the locationCopied() method.
2852
     *
2853
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2854
     */
2855 View Code Duplication
    public function testLocationCopiedCopiedLocationAliasIsValid()
2856
    {
2857
        $handler = $this->getHandler();
2858
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2859
2860
        $urlAlias = $handler->lookup('move-this');
2861
2862
        $handler->locationCopied(4, 400, 3);
2863
2864
        self::assertEquals(
2865
            $urlAlias,
2866
            $handler->lookup('move-this')
2867
        );
2868
    }
2869
2870
    /**
2871
     * Test for the locationCopied() method.
2872
     *
2873
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2874
     */
2875 View Code Duplication
    public function testLocationCopiedCopiedSubtreeIsValid()
2876
    {
2877
        $handler = $this->getHandler();
2878
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2879
2880
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2881
2882
        $handler->locationCopied(4, 400, 3);
2883
2884
        self::assertEquals(
2885
            $urlAlias,
2886
            $handler->lookup('move-this/sub1/sub2')
2887
        );
2888
    }
2889
2890
    /**
2891
     * Test for the locationCopied() method.
2892
     *
2893
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2894
     */
2895 View Code Duplication
    public function testLocationCopiedHistoryNotCopied()
2896
    {
2897
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);
2898
2899
        $handler = $this->getHandler();
2900
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2901
2902
        $handler->locationCopied(4, 400, 3);
2903
2904
        $handler->lookup('move-here/move-this-history');
2905
    }
2906
2907
    /**
2908
     * Test for the locationCopied() method.
2909
     *
2910
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2911
     */
2912 View Code Duplication
    public function testLocationCopiedSubtreeHistoryNotCopied()
2913
    {
2914
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);
2915
2916
        $handler = $this->getHandler();
2917
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2918
2919
        $handler->locationCopied(4, 400, 3);
2920
2921
        $handler->lookup('move-here/move-this/sub1/sub2-history');
2922
    }
2923
2924
    /**
2925
     * Test for the locationCopied() method.
2926
     *
2927
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2928
     */
2929
    public function testLocationCopiedSubtree()
2930
    {
2931
        $handler = $this->getHandler();
2932
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2933
2934
        $countBeforeCopying = $this->countRows();
2935
2936
        $handler->locationCopied(4, 400, 3);
2937
2938
        self::assertEquals(
2939
            $countBeforeCopying + 2,
2940
            $this->countRows()
2941
        );
2942
2943
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2944
        self::assertEquals(
2945
            new UrlAlias(
2946
                [
2947
                    'id' => '10-' . md5('sub2'),
2948
                    'type' => UrlAlias::LOCATION,
2949
                    'destination' => 600,
2950
                    'languageCodes' => ['eng-GB'],
2951
                    'pathData' => [
2952
                        [
2953
                            'always-available' => false,
2954
                            'translations' => ['eng-GB' => 'move-here'],
2955
                        ],
2956
                        [
2957
                            'always-available' => false,
2958
                            'translations' => ['eng-GB' => 'move-this'],
2959
                        ],
2960
                        [
2961
                            'always-available' => false,
2962
                            'translations' => ['eng-GB' => 'sub1'],
2963
                        ],
2964
                        [
2965
                            'always-available' => false,
2966
                            'translations' => ['eng-GB' => 'sub2'],
2967
                        ],
2968
                    ],
2969
                    'alwaysAvailable' => false,
2970
                    'isHistory' => false,
2971
                    'isCustom' => false,
2972
                    'forward' => false,
2973
                ]
2974
            ),
2975
            $urlAlias
2976
        );
2977
    }
2978
2979
    /**
2980
     * Test for the loadUrlAlias() method.
2981
     *
2982
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2983
     * @dataProvider providerForTestLookupLocationMultipleLanguages
2984
     */
2985 View Code Duplication
    public function testLoadAutogeneratedUrlAlias(
2986
        $url,
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2987
        array $pathData,
2988
        array $languageCodes,
2989
        $alwaysAvailable,
2990
        $locationId,
2991
        $id
2992
    ) {
2993
        $handler = $this->getHandler();
2994
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
2995
2996
        $urlAlias = $handler->loadUrlAlias($id);
2997
2998
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
2999
        self::assertEquals(
3000
            new UrlAlias(
3001
                [
3002
                    'id' => $id,
3003
                    'type' => UrlAlias::LOCATION,
3004
                    'destination' => $locationId,
3005
                    'languageCodes' => $languageCodes,
3006
                    'pathData' => $pathData,
3007
                    'alwaysAvailable' => $alwaysAvailable,
3008
                    'isHistory' => false,
3009
                    'isCustom' => false,
3010
                    'forward' => false,
3011
                ]
3012
            ),
3013
            $urlAlias
3014
        );
3015
    }
3016
3017
    /**
3018
     * Test for the loadUrlAlias() method.
3019
     *
3020
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3021
     * @dataProvider providerForTestLookupResourceUrlAlias
3022
     */
3023 View Code Duplication
    public function testLoadResourceUrlAlias(
3024
        $url,
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3025
        $pathData,
3026
        array $languageCodes,
3027
        $forward,
3028
        $alwaysAvailable,
3029
        $destination,
3030
        $id
3031
    ) {
3032
        $handler = $this->getHandler();
3033
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
3034
3035
        $urlAlias = $handler->loadUrlAlias($id);
3036
3037
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
3038
        self::assertEquals(
3039
            new UrlAlias(
3040
                [
3041
                    'id' => $id,
3042
                    'type' => UrlAlias::RESOURCE,
3043
                    'destination' => $destination,
3044
                    'languageCodes' => $languageCodes,
3045
                    'pathData' => $pathData,
3046
                    'alwaysAvailable' => $alwaysAvailable,
3047
                    'isHistory' => false,
3048
                    'isCustom' => true,
3049
                    'forward' => $forward,
3050
                ]
3051
            ),
3052
            $urlAlias
3053
        );
3054
    }
3055
3056
    /**
3057
     * Test for the loadUrlAlias() method.
3058
     *
3059
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3060
     * @dataProvider providerForTestLookupVirtualUrlAlias
3061
     */
3062 View Code Duplication
    public function testLoadVirtualUrlAlias($url, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3063
    {
3064
        $handler = $this->getHandler();
3065
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
3066
3067
        $urlAlias = $handler->loadUrlAlias($id);
3068
3069
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
3070
    }
3071
3072
    protected function getHistoryAlias()
3073
    {
3074
        return new UrlAlias(
3075
            [
3076
                'id' => '3-5f46413bb0ba5998caef84ab1ea590e1',
3077
                'type' => UrlAlias::LOCATION,
3078
                'destination' => '316',
3079
                'pathData' => [
3080
                    [
3081
                        'always-available' => true,
3082
                        'translations' => ['cro-HR' => 'jedan'],
3083
                    ],
3084
                    [
3085
                        'always-available' => false,
3086
                        'translations' => [
3087
                            'cro-HR' => 'dva',
3088
                            'eng-GB' => 'two',
3089
                        ],
3090
                    ],
3091
                    [
3092
                        'always-available' => false,
3093
                        'translations' => [
3094
                            'cro-HR' => 'tri-history',
3095
                        ],
3096
                    ],
3097
                ],
3098
                'languageCodes' => ['cro-HR'],
3099
                'alwaysAvailable' => false,
3100
                'isHistory' => true,
3101
                'isCustom' => false,
3102
                'forward' => false,
3103
            ]
3104
        );
3105
    }
3106
3107
    /**
3108
     * Test for the loadUrlAlias() method.
3109
     *
3110
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3111
     */
3112
    public function testLoadHistoryUrlAlias()
3113
    {
3114
        $handler = $this->getHandler();
3115
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
3116
3117
        $historyAlias = $this->getHistoryAlias();
3118
        $urlAlias = $handler->loadUrlAlias($historyAlias->id);
3119
3120
        self::assertEquals(
3121
            $historyAlias,
3122
            $urlAlias
3123
        );
3124
    }
3125
3126
    /**
3127
     * Test for the loadUrlAlias() method.
3128
     *
3129
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3130
     */
3131
    public function testLoadUrlAliasThrowsNotFoundException()
3132
    {
3133
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);
3134
3135
        $handler = $this->getHandler();
3136
3137
        $handler->loadUrlAlias('non-existent');
3138
    }
3139
3140
    public function providerForTestPublishUrlAliasForLocationSkipsReservedWord()
3141
    {
3142
        return [
3143
            [
3144
                'section',
3145
                'section2',
3146
            ],
3147
            [
3148
                'claß',
3149
                'class2',
3150
            ],
3151
        ];
3152
    }
3153
3154
    /**
3155
     * Test for the publishUrlAliasForLocation() method.
3156
     *
3157
     * @dataProvider providerForTestPublishUrlAliasForLocationSkipsReservedWord
3158
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
3159
     * @group publish
3160
     */
3161
    public function testPublishUrlAliasForLocationSkipsReservedWord($text, $alias)
3162
    {
3163
        $handler = $this->getHandler();
3164
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
3165
3166
        $handler->publishUrlAliasForLocation(314, 2, $text, 'kli-KR');
3167
3168
        $urlAlias = $handler->lookup($alias);
3169
3170
        $this->assertEquals(314, $urlAlias->destination);
3171
        $this->assertEquals(['kli-KR'], $urlAlias->languageCodes);
3172
    }
3173
3174
    /**
3175
     * Test for the locationSwapped() method.
3176
     *
3177
     * @group swap
3178
     */
3179
    public function testLocationSwappedSimple()
3180
    {
3181
        $handler = $this->getHandler();
3182
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple.php');
3183
3184
        $countBeforeReusing = $this->countRows();
3185
3186
        $handler->locationSwapped(316, 314, 317, 315);
3187
3188
        $this->assertEquals(
3189
            $countBeforeReusing,
3190
            $this->countRows()
3191
        );
3192
3193
        $urlAlias = $handler->lookup('jedan/swap');
3194
        $this->assertEquals(
3195
            new UrlAlias(
3196
                [
3197
                    'id' => '2-' . md5('swap'),
3198
                    'type' => UrlAlias::LOCATION,
3199
                    'destination' => 316,
3200
                    'languageCodes' => [
3201
                        'cro-HR',
3202
                    ],
3203
                    'pathData' => [
3204
                        [
3205
                            'always-available' => false,
3206
                            'translations' => [
3207
                                'cro-HR' => 'jedan',
3208
                            ],
3209
                        ],
3210
                        [
3211
                            'always-available' => false,
3212
                            'translations' => [
3213
                                'cro-HR' => 'swap',
3214
                            ],
3215
                        ],
3216
                    ],
3217
                    'alwaysAvailable' => false,
3218
                    'isHistory' => false,
3219
                    'isCustom' => false,
3220
                    'forward' => false,
3221
                ]
3222
            ),
3223
            $urlAlias
3224
        );
3225
3226
        $urlAlias = $handler->lookup('dva/swap');
3227
        $this->assertEquals(
3228
            new UrlAlias(
3229
                [
3230
                    'id' => '3-' . md5('swap'),
3231
                    'type' => UrlAlias::LOCATION,
3232
                    'destination' => 317,
3233
                    'languageCodes' => [
3234
                        'cro-HR',
3235
                    ],
3236
                    'pathData' => [
3237
                        [
3238
                            'always-available' => false,
3239
                            'translations' => [
3240
                                'cro-HR' => 'dva',
3241
                            ],
3242
                        ],
3243
                        [
3244
                            'always-available' => false,
3245
                            'translations' => [
3246
                                'cro-HR' => 'swap',
3247
                            ],
3248
                        ],
3249
                    ],
3250
                    'alwaysAvailable' => false,
3251
                    'isHistory' => false,
3252
                    'isCustom' => false,
3253
                    'forward' => false,
3254
                ]
3255
            ),
3256
            $urlAlias
3257
        );
3258
    }
3259
3260
    /**
3261
     * Test for the locationSwapped() method.
3262
     *
3263
     * @group swap
3264
     */
3265 View Code Duplication
    public function testLocationSwappedSimpleWithHistory()
3266
    {
3267
        $handler = $this->getHandler();
3268
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_history.php');
3269
3270
        $countBeforeReusing = $this->countRows();
3271
3272
        $handler->locationSwapped(316, 314, 317, 315);
3273
3274
        $this->assertEquals(
3275
            $countBeforeReusing,
3276
            $this->countRows()
3277
        );
3278
3279
        $urlAlias = $handler->lookup('jedan/swap');
3280
        $this->assertEquals(
3281
            new UrlAlias(
3282
                [
3283
                    'id' => '2-' . md5('swap'),
3284
                    'type' => UrlAlias::LOCATION,
3285
                    'destination' => 316,
3286
                    'languageCodes' => [
3287
                        'cro-HR',
3288
                    ],
3289
                    'pathData' => [
3290
                        [
3291
                            'always-available' => false,
3292
                            'translations' => [
3293
                                'cro-HR' => 'jedan',
3294
                            ],
3295
                        ],
3296
                        [
3297
                            'always-available' => false,
3298
                            'translations' => [
3299
                                'cro-HR' => 'swap',
3300
                            ],
3301
                        ],
3302
                    ],
3303
                    'alwaysAvailable' => false,
3304
                    'isHistory' => true,
3305
                    'isCustom' => false,
3306
                    'forward' => false,
3307
                ]
3308
            ),
3309
            $urlAlias
3310
        );
3311
3312
        $urlAlias = $handler->lookup('dva/swap');
3313
        $this->assertEquals(
3314
            new UrlAlias(
3315
                [
3316
                    'id' => '3-' . md5('swap'),
3317
                    'type' => UrlAlias::LOCATION,
3318
                    'destination' => 317,
3319
                    'languageCodes' => [
3320
                        'cro-HR',
3321
                    ],
3322
                    'pathData' => [
3323
                        [
3324
                            'always-available' => false,
3325
                            'translations' => [
3326
                                'cro-HR' => 'dva',
3327
                            ],
3328
                        ],
3329
                        [
3330
                            'always-available' => false,
3331
                            'translations' => [
3332
                                'cro-HR' => 'swap',
3333
                            ],
3334
                        ],
3335
                    ],
3336
                    'alwaysAvailable' => false,
3337
                    'isHistory' => true,
3338
                    'isCustom' => false,
3339
                    'forward' => false,
3340
                ]
3341
            ),
3342
            $urlAlias
3343
        );
3344
3345
        $urlAlias = $handler->lookup('jedan/swap-new');
3346
        $this->assertEquals(
3347
            new UrlAlias(
3348
                [
3349
                    'id' => '2-' . md5('swap-new'),
3350
                    'type' => UrlAlias::LOCATION,
3351
                    'destination' => 316,
3352
                    'languageCodes' => [
3353
                        'cro-HR',
3354
                    ],
3355
                    'pathData' => [
3356
                        [
3357
                            'always-available' => false,
3358
                            'translations' => [
3359
                                'cro-HR' => 'jedan',
3360
                            ],
3361
                        ],
3362
                        [
3363
                            'always-available' => false,
3364
                            'translations' => [
3365
                                'cro-HR' => 'swap-new',
3366
                            ],
3367
                        ],
3368
                    ],
3369
                    'alwaysAvailable' => false,
3370
                    'isHistory' => false,
3371
                    'isCustom' => false,
3372
                    'forward' => false,
3373
                ]
3374
            ),
3375
            $urlAlias
3376
        );
3377
3378
        $urlAlias = $handler->lookup('dva/swap-new');
3379
        $this->assertEquals(
3380
            new UrlAlias(
3381
                [
3382
                    'id' => '3-' . md5('swap-new'),
3383
                    'type' => UrlAlias::LOCATION,
3384
                    'destination' => 317,
3385
                    'languageCodes' => [
3386
                        'cro-HR',
3387
                    ],
3388
                    'pathData' => [
3389
                        [
3390
                            'always-available' => false,
3391
                            'translations' => [
3392
                                'cro-HR' => 'dva',
3393
                            ],
3394
                        ],
3395
                        [
3396
                            'always-available' => false,
3397
                            'translations' => [
3398
                                'cro-HR' => 'swap-new',
3399
                            ],
3400
                        ],
3401
                    ],
3402
                    'alwaysAvailable' => false,
3403
                    'isHistory' => false,
3404
                    'isCustom' => false,
3405
                    'forward' => false,
3406
                ]
3407
            ),
3408
            $urlAlias
3409
        );
3410
    }
3411
3412
    /**
3413
     * Test for the locationSwapped() method.
3414
     *
3415
     * @group swap
3416
     */
3417
    public function testLocationSwappedSimpleWithConflict()
3418
    {
3419
        $handler = $this->getHandler();
3420
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_conflict.php');
3421
3422
        $urlAlias1TakenExpected = $handler->lookup('jedan/swap-new-2');
3423
        $urlAlias2TakenExpected = $handler->lookup('dva/swap-new-1');
3424
3425
        $urlAlias1HistorizedExpected = $handler->lookup('jedan/swap-new-1');
3426
        $urlAlias1HistorizedExpected->isHistory = true;
3427
        $urlAlias2HistorizedExpected = $handler->lookup('dva/swap-new-2');
3428
        $urlAlias2HistorizedExpected->isHistory = true;
3429
3430
        $countBeforeReusing = $this->countRows();
3431
3432
        $handler->locationSwapped(316, 314, 317, 315);
3433
3434
        $this->assertEquals(
3435
            $countBeforeReusing + 2,
3436
            $this->countRows()
3437
        );
3438
3439
        $urlAlias1Taken = $handler->lookup('jedan/swap-new-2');
3440
        $urlAlias2Taken = $handler->lookup('dva/swap-new-1');
3441
3442
        $urlAlias1Historized = $handler->lookup('jedan/swap-new-1');
3443
        $urlAlias2Historized = $handler->lookup('dva/swap-new-2');
3444
3445
        $this->assertEquals($urlAlias1TakenExpected, $urlAlias1Taken);
3446
        $this->assertEquals($urlAlias2TakenExpected, $urlAlias2Taken);
3447
3448
        $this->assertEquals($urlAlias1HistorizedExpected, $urlAlias1Historized);
3449
        $this->assertEquals($urlAlias2HistorizedExpected, $urlAlias2Historized);
3450
3451
        $urlAlias1New = $handler->lookup('jedan/swap-new-22');
3452
        $this->assertEquals(
3453
            new UrlAlias(
3454
                [
3455
                    'id' => '2-' . md5('swap-new-22'),
3456
                    'type' => UrlAlias::LOCATION,
3457
                    'destination' => 316,
3458
                    'languageCodes' => [
3459
                        'cro-HR',
3460
                    ],
3461
                    'pathData' => [
3462
                        [
3463
                            'always-available' => false,
3464
                            'translations' => [
3465
                                'cro-HR' => 'jedan',
3466
                            ],
3467
                        ],
3468
                        [
3469
                            'always-available' => false,
3470
                            'translations' => [
3471
                                'cro-HR' => 'swap-new-22',
3472
                            ],
3473
                        ],
3474
                    ],
3475
                    'alwaysAvailable' => false,
3476
                    'isHistory' => false,
3477
                    'isCustom' => false,
3478
                    'forward' => false,
3479
                ]
3480
            ),
3481
            $urlAlias1New
3482
        );
3483
3484
        $urlAlias2New = $handler->lookup('dva/swap-new-12');
3485
        $this->assertEquals(
3486
            new UrlAlias(
3487
                [
3488
                    'id' => '3-' . md5('swap-new-12'),
3489
                    'type' => UrlAlias::LOCATION,
3490
                    'destination' => 317,
3491
                    'languageCodes' => [
3492
                        'cro-HR',
3493
                    ],
3494
                    'pathData' => [
3495
                        [
3496
                            'always-available' => false,
3497
                            'translations' => [
3498
                                'cro-HR' => 'dva',
3499
                            ],
3500
                        ],
3501
                        [
3502
                            'always-available' => false,
3503
                            'translations' => [
3504
                                'cro-HR' => 'swap-new-12',
3505
                            ],
3506
                        ],
3507
                    ],
3508
                    'alwaysAvailable' => false,
3509
                    'isHistory' => false,
3510
                    'isCustom' => false,
3511
                    'forward' => false,
3512
                ]
3513
            ),
3514
            $urlAlias2New
3515
        );
3516
    }
3517
3518
    /**
3519
     * Test for the locationSwapped() method.
3520
     *
3521
     * @group swap
3522
     */
3523 View Code Duplication
    public function testLocationSwappedSiblingsSimple()
3524
    {
3525
        $handler = $this->getHandler();
3526
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3527
3528
        $countBeforeReusing = $this->countRows();
3529
3530
        $handler->locationSwapped(314, 2, 315, 2);
3531
3532
        $this->assertEquals(
3533
            $countBeforeReusing,
3534
            $this->countRows()
3535
        );
3536
3537
        $urlAlias = $handler->lookup('jedan');
3538
        $this->assertEquals(
3539
            new UrlAlias(
3540
                [
3541
                    'id' => '0-' . md5('jedan'),
3542
                    'type' => UrlAlias::LOCATION,
3543
                    'destination' => 315,
3544
                    'languageCodes' => [
3545
                        'cro-HR',
3546
                    ],
3547
                    'pathData' => [
3548
                        [
3549
                            'always-available' => false,
3550
                            'translations' => [
3551
                                'cro-HR' => 'jedan',
3552
                            ],
3553
                        ],
3554
                    ],
3555
                    'alwaysAvailable' => false,
3556
                    'isHistory' => false,
3557
                    'isCustom' => false,
3558
                    'forward' => false,
3559
                ]
3560
            ),
3561
            $urlAlias
3562
        );
3563
3564
        $urlAlias = $handler->lookup('dva');
3565
        $this->assertEquals(
3566
            new UrlAlias(
3567
                [
3568
                    'id' => '0-' . md5('dva'),
3569
                    'type' => UrlAlias::LOCATION,
3570
                    'destination' => 314,
3571
                    'languageCodes' => [
3572
                        'cro-HR',
3573
                    ],
3574
                    'pathData' => [
3575
                        [
3576
                            'always-available' => false,
3577
                            'translations' => [
3578
                                'cro-HR' => 'dva',
3579
                            ],
3580
                        ],
3581
                    ],
3582
                    'alwaysAvailable' => false,
3583
                    'isHistory' => false,
3584
                    'isCustom' => false,
3585
                    'forward' => false,
3586
                ]
3587
            ),
3588
            $urlAlias
3589
        );
3590
    }
3591
3592
    /**
3593
     * Test for the locationSwapped() method.
3594
     *
3595
     * @group swap
3596
     */
3597 View Code Duplication
    public function testLocationSwappedSiblingsSimpleReverse()
3598
    {
3599
        $handler = $this->getHandler();
3600
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3601
3602
        $countBeforeReusing = $this->countRows();
3603
3604
        $handler->locationSwapped(315, 2, 314, 2);
3605
3606
        $this->assertEquals(
3607
            $countBeforeReusing,
3608
            $this->countRows()
3609
        );
3610
3611
        $urlAlias = $handler->lookup('jedan');
3612
        $this->assertEquals(
3613
            new UrlAlias(
3614
                [
3615
                    'id' => '0-' . md5('jedan'),
3616
                    'type' => UrlAlias::LOCATION,
3617
                    'destination' => 315,
3618
                    'languageCodes' => [
3619
                        'cro-HR',
3620
                    ],
3621
                    'pathData' => [
3622
                        [
3623
                            'always-available' => false,
3624
                            'translations' => [
3625
                                'cro-HR' => 'jedan',
3626
                            ],
3627
                        ],
3628
                    ],
3629
                    'alwaysAvailable' => false,
3630
                    'isHistory' => false,
3631
                    'isCustom' => false,
3632
                    'forward' => false,
3633
                ]
3634
            ),
3635
            $urlAlias
3636
        );
3637
3638
        $urlAlias = $handler->lookup('dva');
3639
        $this->assertEquals(
3640
            new UrlAlias(
3641
                [
3642
                    'id' => '0-' . md5('dva'),
3643
                    'type' => UrlAlias::LOCATION,
3644
                    'destination' => 314,
3645
                    'languageCodes' => [
3646
                        'cro-HR',
3647
                    ],
3648
                    'pathData' => [
3649
                        [
3650
                            'always-available' => false,
3651
                            'translations' => [
3652
                                'cro-HR' => 'dva',
3653
                            ],
3654
                        ],
3655
                    ],
3656
                    'alwaysAvailable' => false,
3657
                    'isHistory' => false,
3658
                    'isCustom' => false,
3659
                    'forward' => false,
3660
                ]
3661
            ),
3662
            $urlAlias
3663
        );
3664
    }
3665
3666
    /**
3667
     * Test for the locationSwapped() method.
3668
     *
3669
     * @group swap
3670
     */
3671 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistory()
3672
    {
3673
        $handler = $this->getHandler();
3674
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3675
3676
        $countBeforeReusing = $this->countRows();
3677
3678
        $handler->locationSwapped(314, 2, 315, 2);
3679
3680
        $this->assertEquals(
3681
            $countBeforeReusing,
3682
            $this->countRows()
3683
        );
3684
3685
        $urlAlias = $handler->lookup('jedan');
3686
        $this->assertEquals(
3687
            new UrlAlias(
3688
                [
3689
                    'id' => '0-' . md5('jedan'),
3690
                    'type' => UrlAlias::LOCATION,
3691
                    'destination' => 314,
3692
                    'languageCodes' => [
3693
                        'cro-HR',
3694
                    ],
3695
                    'pathData' => [
3696
                        [
3697
                            'always-available' => false,
3698
                            'translations' => [
3699
                                'cro-HR' => 'jedan',
3700
                            ],
3701
                        ],
3702
                    ],
3703
                    'alwaysAvailable' => false,
3704
                    'isHistory' => true,
3705
                    'isCustom' => false,
3706
                    'forward' => false,
3707
                ]
3708
            ),
3709
            $urlAlias
3710
        );
3711
3712
        $urlAlias = $handler->lookup('dva');
3713
        $this->assertEquals(
3714
            new UrlAlias(
3715
                [
3716
                    'id' => '0-' . md5('dva'),
3717
                    'type' => UrlAlias::LOCATION,
3718
                    'destination' => 315,
3719
                    'languageCodes' => [
3720
                        'cro-HR',
3721
                    ],
3722
                    'pathData' => [
3723
                        [
3724
                            'always-available' => false,
3725
                            'translations' => [
3726
                                'cro-HR' => 'dva',
3727
                            ],
3728
                        ],
3729
                    ],
3730
                    'alwaysAvailable' => false,
3731
                    'isHistory' => true,
3732
                    'isCustom' => false,
3733
                    'forward' => false,
3734
                ]
3735
            ),
3736
            $urlAlias
3737
        );
3738
3739
        $urlAlias = $handler->lookup('jedan-new');
3740
        $this->assertEquals(
3741
            new UrlAlias(
3742
                [
3743
                    'id' => '0-' . md5('jedan-new'),
3744
                    'type' => UrlAlias::LOCATION,
3745
                    'destination' => 315,
3746
                    'languageCodes' => [
3747
                        'cro-HR',
3748
                    ],
3749
                    'pathData' => [
3750
                        [
3751
                            'always-available' => false,
3752
                            'translations' => [
3753
                                'cro-HR' => 'jedan-new',
3754
                            ],
3755
                        ],
3756
                    ],
3757
                    'alwaysAvailable' => false,
3758
                    'isHistory' => false,
3759
                    'isCustom' => false,
3760
                    'forward' => false,
3761
                ]
3762
            ),
3763
            $urlAlias
3764
        );
3765
3766
        $urlAlias = $handler->lookup('dva-new');
3767
        $this->assertEquals(
3768
            new UrlAlias(
3769
                [
3770
                    'id' => '0-' . md5('dva-new'),
3771
                    'type' => UrlAlias::LOCATION,
3772
                    'destination' => 314,
3773
                    'languageCodes' => [
3774
                        'cro-HR',
3775
                    ],
3776
                    'pathData' => [
3777
                        [
3778
                            'always-available' => false,
3779
                            'translations' => [
3780
                                'cro-HR' => 'dva-new',
3781
                            ],
3782
                        ],
3783
                    ],
3784
                    'alwaysAvailable' => false,
3785
                    'isHistory' => false,
3786
                    'isCustom' => false,
3787
                    'forward' => false,
3788
                ]
3789
            ),
3790
            $urlAlias
3791
        );
3792
    }
3793
3794
    /**
3795
     * Test for the locationSwapped() method.
3796
     *
3797
     * @group swap
3798
     */
3799 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistoryReverse()
3800
    {
3801
        $handler = $this->getHandler();
3802
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3803
3804
        $countBeforeReusing = $this->countRows();
3805
3806
        $handler->locationSwapped(315, 2, 314, 2);
3807
3808
        $this->assertEquals(
3809
            $countBeforeReusing,
3810
            $this->countRows()
3811
        );
3812
3813
        $urlAlias = $handler->lookup('jedan');
3814
        $this->assertEquals(
3815
            new UrlAlias(
3816
                [
3817
                    'id' => '0-' . md5('jedan'),
3818
                    'type' => UrlAlias::LOCATION,
3819
                    'destination' => 314,
3820
                    'languageCodes' => [
3821
                        'cro-HR',
3822
                    ],
3823
                    'pathData' => [
3824
                        [
3825
                            'always-available' => false,
3826
                            'translations' => [
3827
                                'cro-HR' => 'jedan',
3828
                            ],
3829
                        ],
3830
                    ],
3831
                    'alwaysAvailable' => false,
3832
                    'isHistory' => true,
3833
                    'isCustom' => false,
3834
                    'forward' => false,
3835
                ]
3836
            ),
3837
            $urlAlias
3838
        );
3839
3840
        $urlAlias = $handler->lookup('dva');
3841
        $this->assertEquals(
3842
            new UrlAlias(
3843
                [
3844
                    'id' => '0-' . md5('dva'),
3845
                    'type' => UrlAlias::LOCATION,
3846
                    'destination' => 315,
3847
                    'languageCodes' => [
3848
                        'cro-HR',
3849
                    ],
3850
                    'pathData' => [
3851
                        [
3852
                            'always-available' => false,
3853
                            'translations' => [
3854
                                'cro-HR' => 'dva',
3855
                            ],
3856
                        ],
3857
                    ],
3858
                    'alwaysAvailable' => false,
3859
                    'isHistory' => true,
3860
                    'isCustom' => false,
3861
                    'forward' => false,
3862
                ]
3863
            ),
3864
            $urlAlias
3865
        );
3866
3867
        $urlAlias = $handler->lookup('jedan-new');
3868
        $this->assertEquals(
3869
            new UrlAlias(
3870
                [
3871
                    'id' => '0-' . md5('jedan-new'),
3872
                    'type' => UrlAlias::LOCATION,
3873
                    'destination' => 315,
3874
                    'languageCodes' => [
3875
                        'cro-HR',
3876
                    ],
3877
                    'pathData' => [
3878
                        [
3879
                            'always-available' => false,
3880
                            'translations' => [
3881
                                'cro-HR' => 'jedan-new',
3882
                            ],
3883
                        ],
3884
                    ],
3885
                    'alwaysAvailable' => false,
3886
                    'isHistory' => false,
3887
                    'isCustom' => false,
3888
                    'forward' => false,
3889
                ]
3890
            ),
3891
            $urlAlias
3892
        );
3893
3894
        $urlAlias = $handler->lookup('dva-new');
3895
        $this->assertEquals(
3896
            new UrlAlias(
3897
                [
3898
                    'id' => '0-' . md5('dva-new'),
3899
                    'type' => UrlAlias::LOCATION,
3900
                    'destination' => 314,
3901
                    'languageCodes' => [
3902
                        'cro-HR',
3903
                    ],
3904
                    'pathData' => [
3905
                        [
3906
                            'always-available' => false,
3907
                            'translations' => [
3908
                                'cro-HR' => 'dva-new',
3909
                            ],
3910
                        ],
3911
                    ],
3912
                    'alwaysAvailable' => false,
3913
                    'isHistory' => false,
3914
                    'isCustom' => false,
3915
                    'forward' => false,
3916
                ]
3917
            ),
3918
            $urlAlias
3919
        );
3920
    }
3921
3922
    /**
3923
     * Test for the locationSwapped() method.
3924
     *
3925
     * @group swap
3926
     */
3927 View Code Duplication
    public function testLocationSwappedSiblingsSameName()
3928
    {
3929
        $handler = $this->getHandler();
3930
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3931
3932
        $countBeforeReusing = $this->countRows();
3933
3934
        $handler->locationSwapped(314, 2, 315, 2);
3935
3936
        $this->assertEquals(
3937
            $countBeforeReusing,
3938
            $this->countRows()
3939
        );
3940
3941
        $urlAlias = $handler->lookup('swap');
3942
        $this->assertEquals(
3943
            new UrlAlias(
3944
                [
3945
                    'id' => '0-' . md5('swap'),
3946
                    'type' => UrlAlias::LOCATION,
3947
                    'destination' => 314,
3948
                    'languageCodes' => [
3949
                        'cro-HR',
3950
                    ],
3951
                    'pathData' => [
3952
                        [
3953
                            'always-available' => false,
3954
                            'translations' => [
3955
                                'cro-HR' => 'swap',
3956
                            ],
3957
                        ],
3958
                    ],
3959
                    'alwaysAvailable' => false,
3960
                    'isHistory' => false,
3961
                    'isCustom' => false,
3962
                    'forward' => false,
3963
                ]
3964
            ),
3965
            $urlAlias
3966
        );
3967
3968
        $urlAlias = $handler->lookup('swap2');
3969
        $this->assertEquals(
3970
            new UrlAlias(
3971
                [
3972
                    'id' => '0-' . md5('swap2'),
3973
                    'type' => UrlAlias::LOCATION,
3974
                    'destination' => 315,
3975
                    'languageCodes' => [
3976
                        'cro-HR',
3977
                    ],
3978
                    'pathData' => [
3979
                        [
3980
                            'always-available' => false,
3981
                            'translations' => [
3982
                                'cro-HR' => 'swap2',
3983
                            ],
3984
                        ],
3985
                    ],
3986
                    'alwaysAvailable' => false,
3987
                    'isHistory' => false,
3988
                    'isCustom' => false,
3989
                    'forward' => false,
3990
                ]
3991
            ),
3992
            $urlAlias
3993
        );
3994
    }
3995
3996
    /**
3997
     * Test for the locationSwapped() method.
3998
     *
3999
     * @group swap
4000
     */
4001 View Code Duplication
    public function testLocationSwappedSiblingsSameNameReverse()
4002
    {
4003
        $handler = $this->getHandler();
4004
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
4005
4006
        $countBeforeReusing = $this->countRows();
4007
4008
        $handler->locationSwapped(315, 2, 314, 2);
4009
4010
        $this->assertEquals(
4011
            $countBeforeReusing,
4012
            $this->countRows()
4013
        );
4014
4015
        $urlAlias = $handler->lookup('swap');
4016
        $this->assertEquals(
4017
            new UrlAlias(
4018
                [
4019
                    'id' => '0-' . md5('swap'),
4020
                    'type' => UrlAlias::LOCATION,
4021
                    'destination' => 314,
4022
                    'languageCodes' => [
4023
                        'cro-HR',
4024
                    ],
4025
                    'pathData' => [
4026
                        [
4027
                            'always-available' => false,
4028
                            'translations' => [
4029
                                'cro-HR' => 'swap',
4030
                            ],
4031
                        ],
4032
                    ],
4033
                    'alwaysAvailable' => false,
4034
                    'isHistory' => false,
4035
                    'isCustom' => false,
4036
                    'forward' => false,
4037
                ]
4038
            ),
4039
            $urlAlias
4040
        );
4041
4042
        $urlAlias = $handler->lookup('swap2');
4043
        $this->assertEquals(
4044
            new UrlAlias(
4045
                [
4046
                    'id' => '0-' . md5('swap2'),
4047
                    'type' => UrlAlias::LOCATION,
4048
                    'destination' => 315,
4049
                    'languageCodes' => [
4050
                        'cro-HR',
4051
                    ],
4052
                    'pathData' => [
4053
                        [
4054
                            'always-available' => false,
4055
                            'translations' => [
4056
                                'cro-HR' => 'swap2',
4057
                            ],
4058
                        ],
4059
                    ],
4060
                    'alwaysAvailable' => false,
4061
                    'isHistory' => false,
4062
                    'isCustom' => false,
4063
                    'forward' => false,
4064
                ]
4065
            ),
4066
            $urlAlias
4067
        );
4068
    }
4069
4070
    /**
4071
     * Test for the locationSwapped() method.
4072
     *
4073
     * @group swap
4074
     */
4075
    public function testLocationSwappedSiblingsSameNameMultipleLanguages()
4076
    {
4077
        $handler = $this->getHandler();
4078
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name_multilang.php');
4079
4080
        $countBeforeReusing = $this->countRows();
4081
4082
        $handler->locationSwapped(314, 2, 315, 2);
4083
4084
        $this->assertEquals(
4085
            $countBeforeReusing,
4086
            $this->countRows()
4087
        );
4088
4089
        $urlAlias = $handler->lookup('swap-hr');
4090
        $this->assertEquals(
4091
            new UrlAlias(
4092
                [
4093
                    'id' => '0-' . md5('swap-hr'),
4094
                    'type' => UrlAlias::LOCATION,
4095
                    'destination' => 314,
4096
                    'languageCodes' => [
4097
                        'cro-HR',
4098
                    ],
4099
                    'pathData' => [
4100
                        [
4101
                            'always-available' => false,
4102
                            'translations' => [
4103
                                'cro-HR' => 'swap-hr',
4104
                                'eng-GB' => 'swap-en2',
4105
                            ],
4106
                        ],
4107
                    ],
4108
                    'alwaysAvailable' => false,
4109
                    'isHistory' => false,
4110
                    'isCustom' => false,
4111
                    'forward' => false,
4112
                ]
4113
            ),
4114
            $urlAlias
4115
        );
4116
4117
        $urlAlias = $handler->lookup('swap-hr2');
4118
        $this->assertEquals(
4119
            new UrlAlias(
4120
                [
4121
                    'id' => '0-' . md5('swap-hr2'),
4122
                    'type' => UrlAlias::LOCATION,
4123
                    'destination' => 315,
4124
                    'languageCodes' => [
4125
                        'cro-HR',
4126
                    ],
4127
                    'pathData' => [
4128
                        [
4129
                            'always-available' => false,
4130
                            'translations' => [
4131
                                'cro-HR' => 'swap-hr2',
4132
                                'eng-GB' => 'swap-en',
4133
                            ],
4134
                        ],
4135
                    ],
4136
                    'alwaysAvailable' => false,
4137
                    'isHistory' => false,
4138
                    'isCustom' => false,
4139
                    'forward' => false,
4140
                ]
4141
            ),
4142
            $urlAlias
4143
        );
4144
4145
        $urlAlias = $handler->lookup('swap-en');
4146
        $this->assertEquals(
4147
            new UrlAlias(
4148
                [
4149
                    'id' => '0-' . md5('swap-en'),
4150
                    'type' => UrlAlias::LOCATION,
4151
                    'destination' => 315,
4152
                    'languageCodes' => [
4153
                        'eng-GB',
4154
                    ],
4155
                    'pathData' => [
4156
                        [
4157
                            'always-available' => false,
4158
                            'translations' => [
4159
                                'cro-HR' => 'swap-hr2',
4160
                                'eng-GB' => 'swap-en',
4161
                            ],
4162
                        ],
4163
                    ],
4164
                    'alwaysAvailable' => false,
4165
                    'isHistory' => false,
4166
                    'isCustom' => false,
4167
                    'forward' => false,
4168
                ]
4169
            ),
4170
            $urlAlias
4171
        );
4172
4173
        $urlAlias = $handler->lookup('swap-en2');
4174
        $this->assertEquals(
4175
            new UrlAlias(
4176
                [
4177
                    'id' => '0-' . md5('swap-en2'),
4178
                    'type' => UrlAlias::LOCATION,
4179
                    'destination' => 314,
4180
                    'languageCodes' => [
4181
                        'eng-GB',
4182
                    ],
4183
                    'pathData' => [
4184
                        [
4185
                            'always-available' => false,
4186
                            'translations' => [
4187
                                'cro-HR' => 'swap-hr',
4188
                                'eng-GB' => 'swap-en2',
4189
                            ],
4190
                        ],
4191
                    ],
4192
                    'alwaysAvailable' => false,
4193
                    'isHistory' => false,
4194
                    'isCustom' => false,
4195
                    'forward' => false,
4196
                ]
4197
            ),
4198
            $urlAlias
4199
        );
4200
    }
4201
4202
    /**
4203
     * Test for the locationSwapped() method.
4204
     *
4205
     * @group swap
4206
     */
4207
    public function testLocationSwappedMultipleLanguagesSimple()
4208
    {
4209
        $handler = $this->getHandler();
4210
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_simple.php');
4211
4212
        $urlAlias1HRExpected = $handler->lookup('jedan/swap-hr');
4213
        $urlAlias1ENExpected = $handler->lookup('jedan/swap-en');
4214
        $urlAlias2HRExpected = $handler->lookup('dva/swap-hr');
4215
        $urlAlias2ENExpected = $handler->lookup('dva/swap-en');
4216
4217
        $countBeforeReusing = $this->countRows();
4218
4219
        $handler->locationSwapped(316, 314, 317, 315);
4220
4221
        $this->assertEquals(
4222
            $countBeforeReusing,
4223
            $this->countRows()
4224
        );
4225
4226
        $urlAlias1HR = $handler->lookup('jedan/swap-hr');
4227
        $urlAlias1EN = $handler->lookup('jedan/swap-en');
4228
        $urlAlias2HR = $handler->lookup('dva/swap-hr');
4229
        $urlAlias2EN = $handler->lookup('dva/swap-en');
4230
4231
        $this->assertEquals($urlAlias1HRExpected, $urlAlias1HR);
4232
        $this->assertEquals($urlAlias1ENExpected, $urlAlias1EN);
4233
        $this->assertEquals($urlAlias2HRExpected, $urlAlias2HR);
4234
        $this->assertEquals($urlAlias2ENExpected, $urlAlias2EN);
4235
    }
4236
4237
    /**
4238
     * Test for the locationSwapped() method.
4239
     *
4240
     * @group swap
4241
     */
4242
    public function testLocationSwappedMultipleLanguagesDifferentLanguagesSimple()
4243
    {
4244
        $handler = $this->getHandler();
4245
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff_simple.php');
4246
4247
        $countBeforeReusing = $this->countRows();
4248
4249
        $handler->locationSwapped(316, 314, 317, 315);
4250
4251
        $this->assertEquals(
4252
            $countBeforeReusing + 2,
4253
            $this->countRows()
4254
        );
4255
4256
        $urlAlias = $handler->lookup('jedan/swap-hr');
4257
        $this->assertEquals(
4258
            new UrlAlias(
4259
                [
4260
                    'id' => '2-' . md5('swap-hr'),
4261
                    'type' => UrlAlias::LOCATION,
4262
                    'destination' => 316,
4263
                    'languageCodes' => [
4264
                        'cro-HR',
4265
                    ],
4266
                    'pathData' => [
4267
                        [
4268
                            'always-available' => false,
4269
                            'translations' => [
4270
                                'cro-HR' => 'jedan',
4271
                            ],
4272
                        ],
4273
                        [
4274
                            'always-available' => false,
4275
                            'translations' => [
4276
                                'cro-HR' => 'swap-hr',
4277
                                'ger-DE' => 'swap-de',
4278
                            ],
4279
                        ],
4280
                    ],
4281
                    'alwaysAvailable' => false,
4282
                    'isHistory' => false,
4283
                    'isCustom' => false,
4284
                    'forward' => false,
4285
                ]
4286
            ),
4287
            $urlAlias
4288
        );
4289
4290
        $urlAlias = $handler->lookup('jedan/swap-de');
4291
        $this->assertEquals(
4292
            new UrlAlias(
4293
                [
4294
                    'id' => '2-' . md5('swap-de'),
4295
                    'type' => UrlAlias::LOCATION,
4296
                    'destination' => 316,
4297
                    'languageCodes' => [
4298
                        'ger-DE',
4299
                    ],
4300
                    'pathData' => [
4301
                        [
4302
                            'always-available' => false,
4303
                            'translations' => [
4304
                                'cro-HR' => 'jedan',
4305
                            ],
4306
                        ],
4307
                        [
4308
                            'always-available' => false,
4309
                            'translations' => [
4310
                                'cro-HR' => 'swap-hr',
4311
                                'ger-DE' => 'swap-de',
4312
                            ],
4313
                        ],
4314
                    ],
4315
                    'alwaysAvailable' => false,
4316
                    'isHistory' => false,
4317
                    'isCustom' => false,
4318
                    'forward' => false,
4319
                ]
4320
            ),
4321
            $urlAlias
4322
        );
4323
4324
        $urlAlias = $handler->lookup('jedan/swap-en');
4325
        $this->assertEquals(
4326
            new UrlAlias(
4327
                [
4328
                    'id' => '2-' . md5('swap-en'),
4329
                    'type' => UrlAlias::LOCATION,
4330
                    'destination' => 316,
4331
                    'languageCodes' => [
4332
                        'eng-GB',
4333
                    ],
4334
                    'pathData' => [
4335
                        [
4336
                            'always-available' => false,
4337
                            'translations' => [
4338
                                'cro-HR' => 'jedan',
4339
                            ],
4340
                        ],
4341
                        [
4342
                            'always-available' => false,
4343
                            'translations' => [
4344
                                'eng-GB' => 'swap-en',
4345
                            ],
4346
                        ],
4347
                    ],
4348
                    'alwaysAvailable' => false,
4349
                    'isHistory' => true,
4350
                    'isCustom' => false,
4351
                    'forward' => false,
4352
                ]
4353
            ),
4354
            $urlAlias
4355
        );
4356
4357
        $urlAlias = $handler->lookup('dva/swap-hr');
4358
        $this->assertEquals(
4359
            new UrlAlias(
4360
                [
4361
                    'id' => '3-' . md5('swap-hr'),
4362
                    'type' => UrlAlias::LOCATION,
4363
                    'destination' => 317,
4364
                    'languageCodes' => [
4365
                        'cro-HR',
4366
                    ],
4367
                    'pathData' => [
4368
                        [
4369
                            'always-available' => false,
4370
                            'translations' => [
4371
                                'cro-HR' => 'dva',
4372
                            ],
4373
                        ],
4374
                        [
4375
                            'always-available' => false,
4376
                            'translations' => [
4377
                                'eng-GB' => 'swap-en',
4378
                                'cro-HR' => 'swap-hr',
4379
                            ],
4380
                        ],
4381
                    ],
4382
                    'alwaysAvailable' => false,
4383
                    'isHistory' => false,
4384
                    'isCustom' => false,
4385
                    'forward' => false,
4386
                ]
4387
            ),
4388
            $urlAlias
4389
        );
4390
4391
        $urlAlias = $handler->lookup('dva/swap-en');
4392
        $this->assertEquals(
4393
            new UrlAlias(
4394
                [
4395
                    'id' => '3-' . md5('swap-en'),
4396
                    'type' => UrlAlias::LOCATION,
4397
                    'destination' => 317,
4398
                    'languageCodes' => [
4399
                        'eng-GB',
4400
                    ],
4401
                    'pathData' => [
4402
                        [
4403
                            'always-available' => false,
4404
                            'translations' => [
4405
                                'cro-HR' => 'dva',
4406
                            ],
4407
                        ],
4408
                        [
4409
                            'always-available' => false,
4410
                            'translations' => [
4411
                                'eng-GB' => 'swap-en',
4412
                                'cro-HR' => 'swap-hr',
4413
                            ],
4414
                        ],
4415
                    ],
4416
                    'alwaysAvailable' => false,
4417
                    'isHistory' => false,
4418
                    'isCustom' => false,
4419
                    'forward' => false,
4420
                ]
4421
            ),
4422
            $urlAlias
4423
        );
4424
4425
        $urlAlias = $handler->lookup('dva/swap-de');
4426
        $this->assertEquals(
4427
            new UrlAlias(
4428
                [
4429
                    'id' => '3-' . md5('swap-de'),
4430
                    'type' => UrlAlias::LOCATION,
4431
                    'destination' => 317,
4432
                    'languageCodes' => [
4433
                        'ger-DE',
4434
                    ],
4435
                    'pathData' => [
4436
                        [
4437
                            'always-available' => false,
4438
                            'translations' => [
4439
                                'cro-HR' => 'dva',
4440
                            ],
4441
                        ],
4442
                        [
4443
                            'always-available' => false,
4444
                            'translations' => [
4445
                                'ger-DE' => 'swap-de',
4446
                            ],
4447
                        ],
4448
                    ],
4449
                    'alwaysAvailable' => false,
4450
                    'isHistory' => true,
4451
                    'isCustom' => false,
4452
                    'forward' => false,
4453
                ]
4454
            ),
4455
            $urlAlias
4456
        );
4457
    }
4458
4459
    /**
4460
     * Test for the locationSwapped() method.
4461
     *
4462
     * @group swap
4463
     */
4464
    public function testLocationSwappedMultipleLanguagesDifferentLanguages()
4465
    {
4466
        $handler = $this->getHandler();
4467
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff.php');
4468
4469
        $countBeforeReusing = $this->countRows();
4470
4471
        $handler->locationSwapped(317, 315, 316, 314);
4472
4473
        $this->assertEquals(
4474
            $countBeforeReusing + 2,
4475
            $this->countRows()
4476
        );
4477
4478
        $urlAlias = $handler->lookup('jedan/swap-this');
4479
        $this->assertEquals(
4480
            new UrlAlias(
4481
                [
4482
                    'id' => '2-' . md5('swap-this'),
4483
                    'type' => UrlAlias::LOCATION,
4484
                    'destination' => 316,
4485
                    'languageCodes' => [
4486
                        'ger-DE',
4487
                        'nor-NO',
4488
                    ],
4489
                    'pathData' => [
4490
                        [
4491
                            'always-available' => false,
4492
                            'translations' => [
4493
                                'cro-HR' => 'jedan',
4494
                            ],
4495
                        ],
4496
                        [
4497
                            'always-available' => false,
4498
                            'translations' => [
4499
                                'cro-HR' => 'swap-hr',
4500
                                'ger-DE' => 'swap-this',
4501
                                'nor-NO' => 'swap-this',
4502
                            ],
4503
                        ],
4504
                    ],
4505
                    'alwaysAvailable' => false,
4506
                    'isHistory' => false,
4507
                    'isCustom' => false,
4508
                    'forward' => false,
4509
                ]
4510
            ),
4511
            $urlAlias
4512
        );
4513
4514
        $urlAlias = $handler->lookup('jedan/swap-en');
4515
        $this->assertEquals(
4516
            new UrlAlias(
4517
                [
4518
                    'id' => '2-' . md5('swap-en'),
4519
                    'type' => UrlAlias::LOCATION,
4520
                    'destination' => 316,
4521
                    'languageCodes' => [
4522
                        'eng-GB',
4523
                    ],
4524
                    'pathData' => [
4525
                        [
4526
                            'always-available' => false,
4527
                            'translations' => [
4528
                                'cro-HR' => 'jedan',
4529
                            ],
4530
                        ],
4531
                        [
4532
                            'always-available' => false,
4533
                            'translations' => [
4534
                                'eng-GB' => 'swap-en',
4535
                            ],
4536
                        ],
4537
                    ],
4538
                    'alwaysAvailable' => false,
4539
                    'isHistory' => true,
4540
                    'isCustom' => false,
4541
                    'forward' => false,
4542
                ]
4543
            ),
4544
            $urlAlias
4545
        );
4546
4547
        $urlAlias = $handler->lookup('dva/swap-hr');
4548
        $this->assertEquals(
4549
            new UrlAlias(
4550
                [
4551
                    'id' => '3-' . md5('swap-hr'),
4552
                    'type' => UrlAlias::LOCATION,
4553
                    'destination' => 317,
4554
                    'languageCodes' => [
4555
                        'cro-HR',
4556
                    ],
4557
                    'pathData' => [
4558
                        [
4559
                            'always-available' => false,
4560
                            'translations' => [
4561
                                'cro-HR' => 'dva',
4562
                            ],
4563
                        ],
4564
                        [
4565
                            'always-available' => false,
4566
                            'translations' => [
4567
                                'cro-HR' => 'swap-hr',
4568
                            ],
4569
                        ],
4570
                    ],
4571
                    'alwaysAvailable' => false,
4572
                    'isHistory' => true,
4573
                    'isCustom' => false,
4574
                    'forward' => false,
4575
                ]
4576
            ),
4577
            $urlAlias
4578
        );
4579
4580
        $urlAlias = $handler->lookup('dva/swap-this');
4581
        $this->assertEquals(
4582
            new UrlAlias(
4583
                [
4584
                    'id' => '3-' . md5('swap-this'),
4585
                    'type' => UrlAlias::LOCATION,
4586
                    'destination' => 317,
4587
                    'languageCodes' => [
4588
                        'cro-HR',
4589
                        'ger-DE',
4590
                    ],
4591
                    'pathData' => [
4592
                        [
4593
                            'always-available' => false,
4594
                            'translations' => [
4595
                                'cro-HR' => 'dva',
4596
                            ],
4597
                        ],
4598
                        [
4599
                            'always-available' => false,
4600
                            'translations' => [
4601
                                'cro-HR' => 'swap-this',
4602
                                'ger-DE' => 'swap-this',
4603
                                'eng-GB' => 'swap-en',
4604
                            ],
4605
                        ],
4606
                    ],
4607
                    'alwaysAvailable' => false,
4608
                    'isHistory' => false,
4609
                    'isCustom' => false,
4610
                    'forward' => false,
4611
                ]
4612
            ),
4613
            $urlAlias
4614
        );
4615
    }
4616
4617
    /**
4618
     * Test for the locationSwapped() method.
4619
     *
4620
     * @group swap
4621
     */
4622
    public function testLocationSwappedMultipleLanguagesWithCompositeHistory()
4623
    {
4624
        $handler = $this->getHandler();
4625
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_cleanup_composite.php');
4626
4627
        $countBeforeReusing = $this->countRows();
4628
4629
        $handler->locationSwapped(317, 315, 316, 314);
4630
4631
        $this->assertEquals(
4632
            $countBeforeReusing + 4,
4633
            $this->countRows()
4634
        );
4635
4636
        $urlAlias = $handler->lookup('jedan/swap-this');
4637
        $this->assertEquals(
4638
            new UrlAlias(
4639
                [
4640
                    'id' => '2-' . md5('swap-this'),
4641
                    'type' => UrlAlias::LOCATION,
4642
                    'destination' => 316,
4643
                    'languageCodes' => [
4644
                        'cro-HR',
4645
                    ],
4646
                    'pathData' => [
4647
                        [
4648
                            'always-available' => false,
4649
                            'translations' => [
4650
                                'cro-HR' => 'jedan',
4651
                            ],
4652
                        ],
4653
                        [
4654
                            'always-available' => false,
4655
                            'translations' => [
4656
                                'cro-HR' => 'swap-this',
4657
                            ],
4658
                        ],
4659
                    ],
4660
                    'alwaysAvailable' => false,
4661
                    'isHistory' => true,
4662
                    'isCustom' => false,
4663
                    'forward' => false,
4664
                ]
4665
            ),
4666
            $urlAlias
4667
        );
4668
4669
        $urlAlias = $handler->lookup('jedan/swap-en');
4670
        $this->assertEquals(
4671
            new UrlAlias(
4672
                [
4673
                    'id' => '2-' . md5('swap-en'),
4674
                    'type' => UrlAlias::LOCATION,
4675
                    'destination' => 316,
4676
                    'languageCodes' => [
4677
                        'eng-GB',
4678
                    ],
4679
                    'pathData' => [
4680
                        [
4681
                            'always-available' => false,
4682
                            'translations' => [
4683
                                'cro-HR' => 'jedan',
4684
                            ],
4685
                        ],
4686
                        [
4687
                            'always-available' => false,
4688
                            'translations' => [
4689
                                'eng-GB' => 'swap-en',
4690
                            ],
4691
                        ],
4692
                    ],
4693
                    'alwaysAvailable' => false,
4694
                    'isHistory' => true,
4695
                    'isCustom' => false,
4696
                    'forward' => false,
4697
                ]
4698
            ),
4699
            $urlAlias
4700
        );
4701
4702
        $urlAlias = $handler->lookup('jedan/swap-hr');
4703
        $this->assertEquals(
4704
            new UrlAlias(
4705
                [
4706
                    'id' => '2-' . md5('swap-hr'),
4707
                    'type' => UrlAlias::LOCATION,
4708
                    'destination' => 316,
4709
                    'languageCodes' => [
4710
                        'cro-HR',
4711
                    ],
4712
                    'pathData' => [
4713
                        [
4714
                            'always-available' => false,
4715
                            'translations' => [
4716
                                'cro-HR' => 'jedan',
4717
                            ],
4718
                        ],
4719
                        [
4720
                            'always-available' => false,
4721
                            'translations' => [
4722
                                'cro-HR' => 'swap-hr',
4723
                                'ger-DE' => 'swap-that',
4724
                                'nor-NO' => 'swap-that',
4725
                            ],
4726
                        ],
4727
                    ],
4728
                    'alwaysAvailable' => false,
4729
                    'isHistory' => false,
4730
                    'isCustom' => false,
4731
                    'forward' => false,
4732
                ]
4733
            ),
4734
            $urlAlias
4735
        );
4736
4737
        $urlAlias = $handler->lookup('jedan/swap-that');
4738
        $this->assertEquals(
4739
            new UrlAlias(
4740
                [
4741
                    'id' => '2-' . md5('swap-that'),
4742
                    'type' => UrlAlias::LOCATION,
4743
                    'destination' => 316,
4744
                    'languageCodes' => [
4745
                        'ger-DE',
4746
                        'nor-NO',
4747
                    ],
4748
                    'pathData' => [
4749
                        [
4750
                            'always-available' => false,
4751
                            'translations' => [
4752
                                'cro-HR' => 'jedan',
4753
                            ],
4754
                        ],
4755
                        [
4756
                            'always-available' => false,
4757
                            'translations' => [
4758
                                'cro-HR' => 'swap-hr',
4759
                                'ger-DE' => 'swap-that',
4760
                                'nor-NO' => 'swap-that',
4761
                            ],
4762
                        ],
4763
                    ],
4764
                    'alwaysAvailable' => false,
4765
                    'isHistory' => false,
4766
                    'isCustom' => false,
4767
                    'forward' => false,
4768
                ]
4769
            ),
4770
            $urlAlias
4771
        );
4772
4773
        $urlAlias = $handler->lookup('dva/swap-hr');
4774
        $this->assertEquals(
4775
            new UrlAlias(
4776
                [
4777
                    'id' => '3-' . md5('swap-hr'),
4778
                    'type' => UrlAlias::LOCATION,
4779
                    'destination' => 317,
4780
                    'languageCodes' => [
4781
                        'cro-HR',
4782
                    ],
4783
                    'pathData' => [
4784
                        [
4785
                            'always-available' => false,
4786
                            'translations' => [
4787
                                'cro-HR' => 'dva',
4788
                            ],
4789
                        ],
4790
                        [
4791
                            'always-available' => false,
4792
                            'translations' => [
4793
                                'cro-HR' => 'swap-hr',
4794
                            ],
4795
                        ],
4796
                    ],
4797
                    'alwaysAvailable' => false,
4798
                    'isHistory' => true,
4799
                    'isCustom' => false,
4800
                    'forward' => false,
4801
                ]
4802
            ),
4803
            $urlAlias
4804
        );
4805
4806
        $urlAlias = $handler->lookup('dva/swap-that');
4807
        $this->assertEquals(
4808
            new UrlAlias(
4809
                [
4810
                    'id' => '3-' . md5('swap-that'),
4811
                    'type' => UrlAlias::LOCATION,
4812
                    'destination' => 317,
4813
                    'languageCodes' => [
4814
                        'ger-DE',
4815
                        'nor-NO',
4816
                    ],
4817
                    'pathData' => [
4818
                        [
4819
                            'always-available' => false,
4820
                            'translations' => [
4821
                                'cro-HR' => 'dva',
4822
                            ],
4823
                        ],
4824
                        [
4825
                            'always-available' => false,
4826
                            'translations' => [
4827
                                'ger-DE' => 'swap-that',
4828
                                'nor-NO' => 'swap-that',
4829
                            ],
4830
                        ],
4831
                    ],
4832
                    'alwaysAvailable' => false,
4833
                    'isHistory' => true,
4834
                    'isCustom' => false,
4835
                    'forward' => false,
4836
                ]
4837
            ),
4838
            $urlAlias
4839
        );
4840
4841
        $urlAlias = $handler->lookup('dva/swap-this');
4842
        $this->assertEquals(
4843
            new UrlAlias(
4844
                [
4845
                    'id' => '3-' . md5('swap-this'),
4846
                    'type' => UrlAlias::LOCATION,
4847
                    'destination' => 317,
4848
                    'languageCodes' => [
4849
                        'cro-HR',
4850
                    ],
4851
                    'pathData' => [
4852
                        [
4853
                            'always-available' => false,
4854
                            'translations' => [
4855
                                'cro-HR' => 'dva',
4856
                            ],
4857
                        ],
4858
                        [
4859
                            'always-available' => false,
4860
                            'translations' => [
4861
                                'cro-HR' => 'swap-this',
4862
                                'eng-GB' => 'swap-en',
4863
                            ],
4864
                        ],
4865
                    ],
4866
                    'alwaysAvailable' => false,
4867
                    'isHistory' => false,
4868
                    'isCustom' => false,
4869
                    'forward' => false,
4870
                ]
4871
            ),
4872
            $urlAlias
4873
        );
4874
4875
        $urlAlias = $handler->lookup('dva/swap-en');
4876
        $this->assertEquals(
4877
            new UrlAlias(
4878
                [
4879
                    'id' => '3-' . md5('swap-en'),
4880
                    'type' => UrlAlias::LOCATION,
4881
                    'destination' => 317,
4882
                    'languageCodes' => [
4883
                        'eng-GB',
4884
                    ],
4885
                    'pathData' => [
4886
                        [
4887
                            'always-available' => false,
4888
                            'translations' => [
4889
                                'cro-HR' => 'dva',
4890
                            ],
4891
                        ],
4892
                        [
4893
                            'always-available' => false,
4894
                            'translations' => [
4895
                                'cro-HR' => 'swap-this',
4896
                                'eng-GB' => 'swap-en',
4897
                            ],
4898
                        ],
4899
                    ],
4900
                    'alwaysAvailable' => false,
4901
                    'isHistory' => false,
4902
                    'isCustom' => false,
4903
                    'forward' => false,
4904
                ]
4905
            ),
4906
            $urlAlias
4907
        );
4908
    }
4909
4910
    /**
4911
     * Test for the locationSwapped() method.
4912
     *
4913
     * @group swap
4914
     */
4915 View Code Duplication
    public function testLocationSwappedWithReusingExternalHistory()
4916
    {
4917
        $handler = $this->getHandler();
4918
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_external_history.php');
4919
4920
        $countBeforeReusing = $this->countRows();
4921
4922
        $handler->locationSwapped(318, 314, 319, 315);
4923
4924
        $this->assertEquals(
4925
            $countBeforeReusing,
4926
            $this->countRows()
4927
        );
4928
4929
        $urlAlias = $handler->lookup('jedan/swap-that');
4930
        $this->assertEquals(
4931
            new UrlAlias(
4932
                [
4933
                    'id' => '2-' . md5('swap-that'),
4934
                    'type' => UrlAlias::LOCATION,
4935
                    'destination' => 318,
4936
                    'languageCodes' => [
4937
                        'cro-HR',
4938
                    ],
4939
                    'pathData' => [
4940
                        [
4941
                            'always-available' => false,
4942
                            'translations' => [
4943
                                'cro-HR' => 'jedan',
4944
                            ],
4945
                        ],
4946
                        [
4947
                            'always-available' => false,
4948
                            'translations' => [
4949
                                'cro-HR' => 'swap-that',
4950
                            ],
4951
                        ],
4952
                    ],
4953
                    'alwaysAvailable' => false,
4954
                    'isHistory' => false,
4955
                    'isCustom' => false,
4956
                    'forward' => false,
4957
                ]
4958
            ),
4959
            $urlAlias
4960
        );
4961
4962
        $urlAlias = $handler->lookup('dva/swap-this');
4963
        $this->assertEquals(
4964
            new UrlAlias(
4965
                [
4966
                    'id' => '3-' . md5('swap-this'),
4967
                    'type' => UrlAlias::LOCATION,
4968
                    'destination' => 319,
4969
                    'languageCodes' => [
4970
                        'cro-HR',
4971
                    ],
4972
                    'pathData' => [
4973
                        [
4974
                            'always-available' => false,
4975
                            'translations' => [
4976
                                'cro-HR' => 'dva',
4977
                            ],
4978
                        ],
4979
                        [
4980
                            'always-available' => false,
4981
                            'translations' => [
4982
                                'cro-HR' => 'swap-this',
4983
                            ],
4984
                        ],
4985
                    ],
4986
                    'alwaysAvailable' => false,
4987
                    'isHistory' => false,
4988
                    'isCustom' => false,
4989
                    'forward' => false,
4990
                ]
4991
            ),
4992
            $urlAlias
4993
        );
4994
4995
        $urlAlias = $handler->lookup('dva/swap-that');
4996
        $this->assertEquals(
4997
            new UrlAlias(
4998
                [
4999
                    'id' => '3-' . md5('swap-that'),
5000
                    'type' => UrlAlias::LOCATION,
5001
                    'destination' => 319,
5002
                    'languageCodes' => [
5003
                        'cro-HR',
5004
                    ],
5005
                    'pathData' => [
5006
                        [
5007
                            'always-available' => false,
5008
                            'translations' => [
5009
                                'cro-HR' => 'dva',
5010
                            ],
5011
                        ],
5012
                        [
5013
                            'always-available' => false,
5014
                            'translations' => [
5015
                                'cro-HR' => 'swap-that',
5016
                            ],
5017
                        ],
5018
                    ],
5019
                    'alwaysAvailable' => false,
5020
                    'isHistory' => true,
5021
                    'isCustom' => false,
5022
                    'forward' => false,
5023
                ]
5024
            ),
5025
            $urlAlias
5026
        );
5027
5028
        $urlAlias = $handler->lookup('jedan/swap-this');
5029
        $this->assertEquals(
5030
            new UrlAlias(
5031
                [
5032
                    'id' => '2-' . md5('swap-this'),
5033
                    'type' => UrlAlias::LOCATION,
5034
                    'destination' => 318,
5035
                    'languageCodes' => [
5036
                        'cro-HR',
5037
                    ],
5038
                    'pathData' => [
5039
                        [
5040
                            'always-available' => false,
5041
                            'translations' => [
5042
                                'cro-HR' => 'jedan',
5043
                            ],
5044
                        ],
5045
                        [
5046
                            'always-available' => false,
5047
                            'translations' => [
5048
                                'cro-HR' => 'swap-this',
5049
                            ],
5050
                        ],
5051
                    ],
5052
                    'alwaysAvailable' => false,
5053
                    'isHistory' => true,
5054
                    'isCustom' => false,
5055
                    'forward' => false,
5056
                ]
5057
            ),
5058
            $urlAlias
5059
        );
5060
    }
5061
5062
    /**
5063
     * Test for the locationSwapped() method.
5064
     *
5065
     * @group swap
5066
     */
5067 View Code Duplication
    public function testLocationSwappedWithReusingNopEntry()
5068
    {
5069
        $handler = $this->getHandler();
5070
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5071
5072
        $countBeforeReusing = $this->countRows();
5073
5074
        $handler->locationSwapped(316, 314, 317, 315);
5075
5076
        $this->assertEquals(
5077
            $countBeforeReusing + 1,
5078
            $this->countRows()
5079
        );
5080
5081
        $urlAlias = $handler->lookup('jedan/swap-that');
5082
        $this->assertEquals(
5083
            new UrlAlias(
5084
                [
5085
                    'id' => '2-' . md5('swap-that'),
5086
                    'type' => UrlAlias::LOCATION,
5087
                    'destination' => 316,
5088
                    'languageCodes' => [
5089
                        'cro-HR',
5090
                    ],
5091
                    'pathData' => [
5092
                        [
5093
                            'always-available' => false,
5094
                            'translations' => [
5095
                                'cro-HR' => 'jedan',
5096
                            ],
5097
                        ],
5098
                        [
5099
                            'always-available' => false,
5100
                            'translations' => [
5101
                                'cro-HR' => 'swap-that',
5102
                            ],
5103
                        ],
5104
                    ],
5105
                    'alwaysAvailable' => false,
5106
                    'isHistory' => false,
5107
                    'isCustom' => false,
5108
                    'forward' => false,
5109
                ]
5110
            ),
5111
            $urlAlias
5112
        );
5113
5114
        $urlAlias = $handler->lookup('dva/swap-this');
5115
        $this->assertEquals(
5116
            new UrlAlias(
5117
                [
5118
                    'id' => '3-' . md5('swap-this'),
5119
                    'type' => UrlAlias::LOCATION,
5120
                    'destination' => 317,
5121
                    'languageCodes' => [
5122
                        'cro-HR',
5123
                    ],
5124
                    'pathData' => [
5125
                        [
5126
                            'always-available' => false,
5127
                            'translations' => [
5128
                                'cro-HR' => 'dva',
5129
                            ],
5130
                        ],
5131
                        [
5132
                            'always-available' => false,
5133
                            'translations' => [
5134
                                'cro-HR' => 'swap-this',
5135
                            ],
5136
                        ],
5137
                    ],
5138
                    'alwaysAvailable' => false,
5139
                    'isHistory' => false,
5140
                    'isCustom' => false,
5141
                    'forward' => false,
5142
                ]
5143
            ),
5144
            $urlAlias
5145
        );
5146
5147
        $urlAlias = $handler->lookup('dva/swap-that');
5148
        $this->assertEquals(
5149
            new UrlAlias(
5150
                [
5151
                    'id' => '3-' . md5('swap-that'),
5152
                    'type' => UrlAlias::LOCATION,
5153
                    'destination' => 317,
5154
                    'languageCodes' => [
5155
                        'cro-HR',
5156
                    ],
5157
                    'pathData' => [
5158
                        [
5159
                            'always-available' => false,
5160
                            'translations' => [
5161
                                'cro-HR' => 'dva',
5162
                            ],
5163
                        ],
5164
                        [
5165
                            'always-available' => false,
5166
                            'translations' => [
5167
                                'cro-HR' => 'swap-that',
5168
                            ],
5169
                        ],
5170
                    ],
5171
                    'alwaysAvailable' => false,
5172
                    'isHistory' => true,
5173
                    'isCustom' => false,
5174
                    'forward' => false,
5175
                ]
5176
            ),
5177
            $urlAlias
5178
        );
5179
5180
        $urlAlias = $handler->lookup('jedan/swap-this');
5181
        $this->assertEquals(
5182
            new UrlAlias(
5183
                [
5184
                    'id' => '2-' . md5('swap-this'),
5185
                    'type' => UrlAlias::LOCATION,
5186
                    'destination' => 316,
5187
                    'languageCodes' => [
5188
                        'cro-HR',
5189
                    ],
5190
                    'pathData' => [
5191
                        [
5192
                            'always-available' => false,
5193
                            'translations' => [
5194
                                'cro-HR' => 'jedan',
5195
                            ],
5196
                        ],
5197
                        [
5198
                            'always-available' => false,
5199
                            'translations' => [
5200
                                'cro-HR' => 'swap-this',
5201
                            ],
5202
                        ],
5203
                    ],
5204
                    'alwaysAvailable' => false,
5205
                    'isHistory' => true,
5206
                    'isCustom' => false,
5207
                    'forward' => false,
5208
                ]
5209
            ),
5210
            $urlAlias
5211
        );
5212
    }
5213
5214
    /**
5215
     * Test for the locationSwapped() method.
5216
     *
5217
     * @depends testLocationSwappedWithReusingNopEntry
5218
     * @group swap
5219
     */
5220
    public function testLocationSwappedWithReusingNopEntryCustomAliasIsDestroyed()
5221
    {
5222
        $handler = $this->getHandler();
5223
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5224
5225
        $handler->lookup('jedan/swap-that/search');
5226
        $handler->locationSwapped(316, 314, 317, 315);
5227
5228
        try {
5229
            $handler->lookup('jedan/swap-that/search');
5230
            $this->fail('Custom alias is not destroyed');
5231
        } catch (NotFoundException $e) {
5232
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
5233
            // on the same level (that means link and ID are updated to the existing alias ID,
5234
            // so custom alias children entries are no longer properly linked (parent-link))
5235
        }
5236
    }
5237
5238
    /**
5239
     * Test for the locationSwapped() method.
5240
     *
5241
     * @group swap
5242
     *
5243
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5244
     */
5245 View Code Duplication
    public function testLocationSwappedUpdatesLocationPathIdentificationString()
5246
    {
5247
        $handler = $this->getHandler();
5248
        $locationGateway = $this->getLocationGateway();
5249
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_path_identification_string.php');
5250
5251
        $countBeforeReusing = $this->countRows();
5252
5253
        $handler->locationSwapped(314, 2, 315, 2);
5254
5255
        $this->assertEquals(
5256
            $countBeforeReusing,
5257
            $this->countRows()
5258
        );
5259
5260
        $locationData = $locationGateway->getBasicNodeData(314);
5261
        self::assertEquals('dva', $locationData['path_identification_string']);
5262
5263
        $locationData = $locationGateway->getBasicNodeData(315);
5264
        self::assertEquals('jedan', $locationData['path_identification_string']);
5265
    }
5266
5267
    /**
5268
     * Test for the locationSwapped() method.
5269
     *
5270
     * @group swap
5271
     *
5272
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5273
     */
5274 View Code Duplication
    public function testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString()
5275
    {
5276
        $handler = $this->getHandler();
5277
        $locationGateway = $this->getLocationGateway();
5278
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_path_identification_string.php');
5279
5280
        $countBeforeReusing = $this->countRows();
5281
5282
        $handler->locationSwapped(314, 2, 315, 2);
5283
5284
        $this->assertEquals(
5285
            $countBeforeReusing,
5286
            $this->countRows()
5287
        );
5288
5289
        $locationData = $locationGateway->getBasicNodeData(314);
5290
        self::assertEquals('zwei', $locationData['path_identification_string']);
5291
5292
        $locationData = $locationGateway->getBasicNodeData(315);
5293
        self::assertEquals('jedan', $locationData['path_identification_string']);
5294
    }
5295
5296
    /**
5297
     * @return int
5298
     */
5299
    protected function countRows()
5300
    {
5301
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5302
        $query = $this->getDatabaseHandler()->createSelectQuery();
5303
        $query->select(
5304
            $query->expr->count('*')
5305
        )->from(
5306
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5307
        );
5308
5309
        $statement = $query->prepare();
5310
        $statement->execute();
5311
5312
        return (int)$statement->fetchColumn();
5313
    }
5314
5315
    protected function dump()
5316
    {
5317
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5318
        $query = $this->getDatabaseHandler()->createSelectQuery();
5319
        $query->select(
5320
            '*'
5321
        )->from(
5322
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5323
        );
5324
5325
        $statement = $query->prepare();
5326
        $statement->execute();
5327
5328
        var_dump($statement->fetchAll(\PDO::FETCH_ASSOC));
0 ignored issues
show
Security Debugging Code introduced by
var_dump($statement->fet...ll(\PDO::FETCH_ASSOC)); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
5329
    }
5330
5331
    /**
5332
     * @var \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler
5333
     * @deprecated Start to use DBAL $connection instead.
5334
     */
5335
    protected $dbHandler;
5336
5337
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway */
5338
    protected $locationGateway;
5339
5340
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler */
5341
    protected $languageHandler;
5342
5343
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator */
5344
    protected $languageMaskGenerator;
5345
5346
    /**
5347
     * @param array $methods
5348
     *
5349
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler|\PHPUnit\Framework\MockObject\MockObject
5350
     */
5351
    protected function getPartlyMockedHandler(array $methods)
5352
    {
5353
        return $this->getMockBuilder(Handler::class)
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/pull/3687

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5354
            ->setConstructorArgs(
5355
                [
5356
                    $this->createMock(UrlAliasGateway::class),
5357
                    $this->createMock(Mapper::class),
5358
                    $this->createMock(LocationGateway::class),
5359
                    $this->createMock(LanguageHandler::class),
5360
                    $this->createMock(SlugConverter::class),
5361
                    $this->createMock(Gateway::class),
5362
                    $this->createMock(LanguageMaskGenerator::class),
5363
                    $this->createMock(TransactionHandler::class),
5364
                ]
5365
            )
5366
            ->setMethods($methods)
5367
            ->getMock();
5368
    }
5369
5370
    /**
5371
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5372
     */
5373
    protected function getHandler()
5374
    {
5375
        $languageHandler = $this->getLanguageHandler();
5376
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5377
        $databaseHandler = $this->getDatabaseHandler();
5378
        $gateway = new DoctrineDatabase(
5379
            $databaseHandler,
5380
            $languageMaskGenerator
5381
        );
5382
        $mapper = new Mapper($languageMaskGenerator);
5383
        $slugConverter = new SlugConverter($this->getProcessor());
5384
        $contentGateway = new ContentGateway(
5385
            $this->getDatabaseHandler(),
5386
            $this->getDatabaseConnection(),
5387
            new ContentGateway\QueryBuilder($this->getDatabaseHandler()),
5388
            $languageHandler,
5389
            $languageMaskGenerator
5390
        );
5391
5392
        return new Handler(
5393
            $gateway,
5394
            $mapper,
5395
            $this->getLocationGateway(),
5396
            $languageHandler,
5397
            $slugConverter,
5398
            $contentGateway,
5399
            $languageMaskGenerator,
5400
            $this->createMock(TransactionHandler::class)
5401
        );
5402
    }
5403
5404
    /**
5405
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5406
     */
5407
    protected function getLanguageHandler()
5408
    {
5409
        if (!isset($this->languageHandler)) {
5410
            $this->languageHandler = new LanguageHandler(
5411
                new LanguageGateway(
5412
                    $this->getDatabaseHandler()
5413
                ),
5414
                new LanguageMapper()
5415
            );
5416
        }
5417
5418
        return $this->languageHandler;
5419
    }
5420
5421
    /**
5422
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5423
     */
5424
    protected function getLanguageMaskGenerator()
5425
    {
5426
        if (!isset($this->languageMaskGenerator)) {
5427
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5428
                $this->getLanguageHandler()
5429
            );
5430
        }
5431
5432
        return $this->languageMaskGenerator;
5433
    }
5434
5435
    /**
5436
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5437
     */
5438
    protected function getLocationGateway()
5439
    {
5440
        if (!isset($this->locationGateway)) {
5441
            $this->locationGateway = new DoctrineDatabaseLocation(
5442
                $this->getDatabaseHandler(),
5443
                $this->getLanguageMaskGenerator()
5444
            );
5445
        }
5446
5447
        return $this->locationGateway;
5448
    }
5449
5450
    /**
5451
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5452
     */
5453
    public function getProcessor()
5454
    {
5455
        return new DefinitionBased(
5456
            new Parser(),
5457
            new PcreCompiler(new Utf8Converter()),
5458
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5459
        );
5460
    }
5461
5462
    /**
5463
     * Data provider for tests of archiveUrlAliasesForDeletedTranslations.
5464
     *
5465
     * @see testArchiveUrlAliasesForDeletedTranslations for the description of parameters
5466
     *
5467
     * @return array
5468
     */
5469
    public function providerForArchiveUrlAliasesForDeletedTranslations()
5470
    {
5471
        return [
5472
            [2, ['eng-GB', 'pol-PL'], 'pol-PL'],
5473
            [3, ['eng-GB', 'pol-PL', 'nor-NO'], 'pol-PL'],
5474
        ];
5475
    }
5476
5477
    /**
5478
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::archiveUrlAliasesForDeletedTranslations()
5479
     *
5480
     * @dataProvider providerForArchiveUrlAliasesForDeletedTranslations
5481
     *
5482
     * @param int $locationId
5483
     * @param string[] $expectedLanguages expected language codes before deleting
5484
     * @param string $removeLanguage language code to be deleted
5485
     */
5486
    public function testArchiveUrlAliasesForDeletedTranslations(
5487
        $locationId,
5488
        array $expectedLanguages,
5489
        $removeLanguage
5490
    ) {
5491
        $handler = $this->getHandler();
5492
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_multilingual.php');
5493
5494
        // collect data persisted from fixtures
5495
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5496
        $collectedLanguages = [];
5497
        $collectedUrls = [];
5498
        foreach ($urlAliases as $urlAlias) {
5499
            // collect languages of all URL aliases
5500
            $collectedLanguages = array_merge($collectedLanguages, $urlAlias->languageCodes);
5501
            $isComposite = count($urlAlias->languageCodes) > 1;
5502
            foreach ($urlAlias->pathData as $pathData) {
5503
                // collect also actual unique URLs to be removed to check them after removal
5504
                if (!empty($pathData['translations'][$removeLanguage])) {
5505
                    $url = $pathData['translations'][$removeLanguage];
5506
                    $collectedUrls[$url] = $isComposite;
5507
                }
5508
            }
5509
        }
5510
        // sanity check
5511
        self::assertEquals($expectedLanguages, $collectedLanguages);
5512
5513
        // remove language
5514
        $publishedLanguages = array_values(array_diff($collectedLanguages, [$removeLanguage]));
5515
        $handler->archiveUrlAliasesForDeletedTranslations($locationId, 1, $publishedLanguages);
5516
5517
        // check reloaded structures
5518
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5519 View Code Duplication
        foreach ($urlAliases as $urlAlias) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5520
            self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5521
            foreach ($urlAlias->pathData as $pathData) {
5522
                self::assertNotContains($removeLanguage, $pathData['translations']);
5523
                foreach ($pathData['translations'] as $url) {
5524
                    $lookupUrlAlias = $handler->lookup($url);
5525
                    self::assertNotContains($removeLanguage, $lookupUrlAlias->languageCodes);
5526
                }
5527
            }
5528
        }
5529
5530
        // lookup removed URLs to check they're not found
5531 View Code Duplication
        foreach ($collectedUrls as $url => $isComposite) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
5532
            $urlAlias = $handler->lookup($url);
5533
            if ($isComposite) {
5534
                // check if alias no longer refers to removed Translation
5535
                self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5536
                foreach ($urlAlias->pathData as $pathData) {
5537
                    self::assertNotContains($removeLanguage, $pathData['translations']);
5538
                }
5539
            } else {
5540
                // check if non composite alias for removed translation is historized
5541
                self::assertTrue($urlAlias->isHistory);
5542
            }
5543
        }
5544
    }
5545
}
5546