Completed
Push — 7.5 ( 872380...ff94d7 )
by Łukasz
21:16
created

UrlAliasHandlerTest::getHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 30
rs 9.44
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
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
68
     * @group location
69
     * @group virtual
70
     * @group resource
71
     */
72
    public function testLookupThrowsNotFoundException()
73
    {
74
        $handler = $this->getHandler();
75
        $handler->lookup('wooden/iron');
76
    }
77
78
    /**
79
     * Test for the lookup() method.
80
     *
81
     * Trying to lookup URL alias with exceeded path segments limit
82
     *
83
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
84
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
85
     * @group location
86
     * @group case-correction
87
     */
88
    public function testLookupThrowsInvalidArgumentException()
89
    {
90
        $handler = $this->getHandler();
91
        $handler->lookup(str_repeat('/1', 99));
92
    }
93
94
    public function providerForTestLookupLocationUrlAlias()
95
    {
96
        return [
97
            [
98
                'jedan',
99
                [
100
                    [
101
                        'always-available' => true,
102
                        'translations' => [
103
                            'cro-HR' => 'jedan',
104
                        ],
105
                    ],
106
                ],
107
                ['cro-HR'],
108
                true,
109
                314,
110
                '0-6896260129051a949051c3847c34466f',
111
            ],
112
            [
113
                'jedan/dva',
114
                [
115
                    [
116
                        'always-available' => true,
117
                        'translations' => [
118
                            'cro-HR' => 'jedan',
119
                        ],
120
                    ],
121
                    [
122
                        'always-available' => false,
123
                        'translations' => [
124
                            'cro-HR' => 'dva',
125
                            'eng-GB' => 'two',
126
                        ],
127
                    ],
128
                ],
129
                ['cro-HR'],
130
                false,
131
                315,
132
                '2-c67ed9a09ab136fae610b6a087d82e21',
133
            ],
134
            [
135
                'jedan/two',
136
                [
137
                    [
138
                        'always-available' => true,
139
                        'translations' => [
140
                            'cro-HR' => 'jedan',
141
                        ],
142
                    ],
143
                    [
144
                        'always-available' => false,
145
                        'translations' => [
146
                            'cro-HR' => 'dva',
147
                            'eng-GB' => 'two',
148
                        ],
149
                    ],
150
                ],
151
                ['eng-GB'],
152
                false,
153
                315,
154
                '2-b8a9f715dbb64fd5c56e7783c6820a61',
155
            ],
156
            [
157
                'jedan/dva/tri',
158
                [
159
                    [
160
                        'always-available' => true,
161
                        'translations' => [
162
                            'cro-HR' => 'jedan',
163
                        ],
164
                    ],
165
                    [
166
                        'always-available' => false,
167
                        'translations' => [
168
                            'cro-HR' => 'dva',
169
                            'eng-GB' => 'two',
170
                        ],
171
                    ],
172
                    [
173
                        'always-available' => false,
174
                        'translations' => [
175
                            'cro-HR' => 'tri',
176
                            'eng-GB' => 'three',
177
                            'ger-DE' => 'drei',
178
                        ],
179
                    ],
180
                ],
181
                ['cro-HR'],
182
                false,
183
                316,
184
                '3-d2cfe69af2d64330670e08efb2c86df7',
185
            ],
186
            [
187
                'jedan/two/three',
188
                [
189
                    [
190
                        'always-available' => true,
191
                        'translations' => [
192
                            'cro-HR' => 'jedan',
193
                        ],
194
                    ],
195
                    [
196
                        'always-available' => false,
197
                        'translations' => [
198
                            'cro-HR' => 'dva',
199
                            'eng-GB' => 'two',
200
                        ],
201
                    ],
202
                    [
203
                        'always-available' => false,
204
                        'translations' => [
205
                            'cro-HR' => 'tri',
206
                            'eng-GB' => 'three',
207
                            'ger-DE' => 'drei',
208
                        ],
209
                    ],
210
                ],
211
                ['eng-GB'],
212
                false,
213
                316,
214
                '3-35d6d33467aae9a2e3dccb4b6b027878',
215
            ],
216
            [
217
                'jedan/dva/three',
218
                [
219
                    [
220
                        'always-available' => true,
221
                        'translations' => [
222
                            'cro-HR' => 'jedan',
223
                        ],
224
                    ],
225
                    [
226
                        'always-available' => false,
227
                        'translations' => [
228
                            'cro-HR' => 'dva',
229
                            'eng-GB' => 'two',
230
                        ],
231
                    ],
232
                    [
233
                        'always-available' => false,
234
                        'translations' => [
235
                            'cro-HR' => 'tri',
236
                            'eng-GB' => 'three',
237
                            'ger-DE' => 'drei',
238
                        ],
239
                    ],
240
                ],
241
                ['eng-GB'],
242
                false,
243
                316,
244
                '3-35d6d33467aae9a2e3dccb4b6b027878',
245
            ],
246
            [
247
                'jedan/two/tri',
248
                [
249
                    [
250
                        'always-available' => true,
251
                        'translations' => [
252
                            'cro-HR' => 'jedan',
253
                        ],
254
                    ],
255
                    [
256
                        'always-available' => false,
257
                        'translations' => [
258
                            'cro-HR' => 'dva',
259
                            'eng-GB' => 'two',
260
                        ],
261
                    ],
262
                    [
263
                        'always-available' => false,
264
                        'translations' => [
265
                            'cro-HR' => 'tri',
266
                            'eng-GB' => 'three',
267
                            'ger-DE' => 'drei',
268
                        ],
269
                    ],
270
                ],
271
                ['cro-HR'],
272
                false,
273
                316,
274
                '3-d2cfe69af2d64330670e08efb2c86df7',
275
            ],
276
            [
277
                'jedan/dva/drei',
278
                [
279
                    [
280
                        'always-available' => true,
281
                        'translations' => [
282
                            'cro-HR' => 'jedan',
283
                        ],
284
                    ],
285
                    [
286
                        'always-available' => false,
287
                        'translations' => [
288
                            'cro-HR' => 'dva',
289
                            'eng-GB' => 'two',
290
                        ],
291
                    ],
292
                    [
293
                        'always-available' => false,
294
                        'translations' => [
295
                            'cro-HR' => 'tri',
296
                            'eng-GB' => 'three',
297
                            'ger-DE' => 'drei',
298
                        ],
299
                    ],
300
                ],
301
                ['ger-DE'],
302
                false,
303
                316,
304
                '3-1d8d2fd0a99802b89eb356a86e029d25',
305
            ],
306
            [
307
                'jedan/two/drei',
308
                [
309
                    [
310
                        'always-available' => true,
311
                        'translations' => [
312
                            'cro-HR' => 'jedan',
313
                        ],
314
                    ],
315
                    [
316
                        'always-available' => false,
317
                        'translations' => [
318
                            'cro-HR' => 'dva',
319
                            'eng-GB' => 'two',
320
                        ],
321
                    ],
322
                    [
323
                        'always-available' => false,
324
                        'translations' => [
325
                            'cro-HR' => 'tri',
326
                            'eng-GB' => 'three',
327
                            'ger-DE' => 'drei',
328
                        ],
329
                    ],
330
                ],
331
                ['ger-DE'],
332
                false,
333
                316,
334
                '3-1d8d2fd0a99802b89eb356a86e029d25',
335
            ],
336
        ];
337
    }
338
339
    /**
340
     * Test for the lookup() method.
341
     *
342
     * Testing that UrlAlias is found and has expected state.
343
     *
344
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
345
     * @dataProvider providerForTestLookupLocationUrlAlias
346
     * @depends testLookup
347
     * @group location
348
     */
349 View Code Duplication
    public function testLookupLocationUrlAlias(
350
        $url,
351
        array $pathData,
352
        array $languageCodes,
353
        $alwaysAvailable,
354
        $locationId,
355
        $id
356
    ) {
357
        $handler = $this->getHandler();
358
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
359
360
        $urlAlias = $handler->lookup($url);
361
362
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
363
        self::assertEquals(
364
            new UrlAlias(
365
                [
366
                    'id' => $id,
367
                    'type' => UrlAlias::LOCATION,
368
                    'destination' => $locationId,
369
                    'languageCodes' => $languageCodes,
370
                    'pathData' => $pathData,
371
                    'alwaysAvailable' => $alwaysAvailable,
372
                    'isHistory' => false,
373
                    'isCustom' => false,
374
                    'forward' => false,
375
                ]
376
            ),
377
            $urlAlias
378
        );
379
    }
380
381
    /**
382
     * Testing that looking up case incorrect URL results in redirection to case correct path.
383
     *
384
     * Note that case corrected path is not always equal to case corrected case incorrect path, eg. "JEDAN/TWO/THREE"
385
     * will not always redirect to "jedan/two/three".
386
     * In some cases, depending on list of prioritized languages and if Content available in the different language
387
     * higher in the list of prioritized languages, path showing to that Content will be used.
388
     * Example: "JEDAN/TWO/DREI" with "eng-GB" and "ger-DE" as prioritized languages will produce redirection
389
     * to the "jedan/two/three", as "eng-GB" is the most prioritized language and Content that URL alias is pointing
390
     * to is available in it.
391
     *
392
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
393
     * @dataProvider providerForTestLookupLocationUrlAlias
394
     * @depends testLookup
395
     * @group case-correction
396
     * @group location
397
     *
398
     * @todo refactor, only forward pertinent
399
     */
400 View Code Duplication
    public function testLookupLocationCaseCorrection(
401
        $url,
402
        array $pathData,
403
        array $languageCodes,
404
        $alwaysAvailable,
405
        $locationId,
406
        $id
407
    ) {
408
        $handler = $this->getHandler();
409
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
410
411
        $urlAlias = $handler->lookup(strtoupper($url));
412
413
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
414
        self::assertEquals(
415
            new UrlAlias(
416
                [
417
                    'id' => $id,
418
                    'type' => UrlAlias::LOCATION,
419
                    'destination' => $locationId,
420
                    'languageCodes' => $languageCodes,
421
                    'pathData' => $pathData,
422
                    'alwaysAvailable' => $alwaysAvailable,
423
                    'isHistory' => false,
424
                    'isCustom' => false,
425
                    'forward' => false,
426
                ]
427
            ),
428
            $urlAlias
429
        );
430
    }
431
432
    public function providerForTestLookupLocationMultipleLanguages()
433
    {
434
        return [
435
            [
436
                'jedan/dva',
437
                [
438
                    [
439
                        'always-available' => true,
440
                        'translations' => [
441
                            'cro-HR' => 'jedan',
442
                        ],
443
                    ],
444
                    [
445
                        'always-available' => false,
446
                        'translations' => [
447
                            'cro-HR' => 'dva',
448
                            'eng-GB' => 'dva',
449
                        ],
450
                    ],
451
                ],
452
                ['cro-HR', 'eng-GB'],
453
                false,
454
                315,
455
                '2-c67ed9a09ab136fae610b6a087d82e21',
456
            ],
457
            [
458
                'jedan/dva/tri',
459
                [
460
                    [
461
                        'always-available' => true,
462
                        'translations' => [
463
                            'cro-HR' => 'jedan',
464
                        ],
465
                    ],
466
                    [
467
                        'always-available' => false,
468
                        'translations' => [
469
                            'cro-HR' => 'dva',
470
                            'eng-GB' => 'dva',
471
                        ],
472
                    ],
473
                    [
474
                        'always-available' => false,
475
                        'translations' => [
476
                            'cro-HR' => 'tri',
477
                            'eng-GB' => 'three',
478
                        ],
479
                    ],
480
                ],
481
                ['cro-HR'],
482
                false,
483
                316,
484
                '3-d2cfe69af2d64330670e08efb2c86df7',
485
            ],
486
            [
487
                'jedan/dva/three',
488
                [
489
                    [
490
                        'always-available' => true,
491
                        'translations' => [
492
                            'cro-HR' => 'jedan',
493
                        ],
494
                    ],
495
                    [
496
                        'always-available' => false,
497
                        'translations' => [
498
                            'cro-HR' => 'dva',
499
                            'eng-GB' => 'dva',
500
                        ],
501
                    ],
502
                    [
503
                        'always-available' => false,
504
                        'translations' => [
505
                            'cro-HR' => 'tri',
506
                            'eng-GB' => 'three',
507
                        ],
508
                    ],
509
                ],
510
                ['eng-GB'],
511
                false,
512
                316,
513
                '3-35d6d33467aae9a2e3dccb4b6b027878',
514
            ],
515
        ];
516
    }
517
518
    /**
519
     * Test for the lookup() method.
520
     *
521
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
522
     * @dataProvider providerForTestLookupLocationMultipleLanguages
523
     * @depends testLookup
524
     * @group multiple-languages
525
     * @group location
526
     */
527 View Code Duplication
    public function testLookupLocationMultipleLanguages(
528
        $url,
529
        array $pathData,
530
        array $languageCodes,
531
        $alwaysAvailable,
532
        $locationId,
533
        $id
534
    ) {
535
        $handler = $this->getHandler();
536
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
537
538
        $urlAlias = $handler->lookup($url);
539
540
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
541
        self::assertEquals(
542
            new UrlAlias(
543
                [
544
                    'id' => $id,
545
                    'type' => UrlAlias::LOCATION,
546
                    'destination' => $locationId,
547
                    'languageCodes' => $languageCodes,
548
                    'pathData' => $pathData,
549
                    'alwaysAvailable' => $alwaysAvailable,
550
                    'isHistory' => false,
551
                    'isCustom' => false,
552
                    'forward' => false,
553
                ]
554
            ),
555
            $urlAlias
556
        );
557
    }
558
559
    /**
560
     * Test for the lookup() method.
561
     *
562
     * @todo document
563
     *
564
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
565
     * @depends testLookup
566
     * @group history
567
     * @group location
568
     */
569
    public function testLookupLocationHistoryUrlAlias()
570
    {
571
        $handler = $this->getHandler();
572
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
573
574
        $urlAlias = $handler->lookup('jedan/dva/tri-history');
575
576
        self::assertEquals(
577
            $this->getHistoryAlias(),
578
            $urlAlias
579
        );
580
    }
581
582
    public function providerForTestLookupCustomLocationUrlAlias()
583
    {
584
        return [
585
            [
586
                'autogenerated-hello/everybody',
587
                [
588
                    [
589
                        'always-available' => true,
590
                        'translations' => [
591
                            'eng-GB' => 'autogenerated-hello',
592
                        ],
593
                    ],
594
                    [
595
                        'always-available' => true,
596
                        'translations' => [
597
                            'eng-GB' => 'everybody',
598
                        ],
599
                    ],
600
                ],
601
                ['eng-GB'],
602
                false,
603
                true,
604
                315,
605
                '2-88150d7d17390010ba6222de68bfafb5',
606
            ],
607
            [
608
                'hello',
609
                [
610
                    [
611
                        'always-available' => false,
612
                        'translations' => [
613
                            'eng-GB' => 'hello',
614
                        ],
615
                    ],
616
                ],
617
                ['eng-GB'],
618
                true,
619
                false,
620
                314,
621
                '0-5d41402abc4b2a76b9719d911017c592',
622
            ],
623
            [
624
                'hello/and/goodbye',
625
                [
626
                    [
627
                        'always-available' => false,
628
                        'translations' => [
629
                            'eng-GB' => 'hello',
630
                        ],
631
                    ],
632
                    [
633
                        'always-available' => true,
634
                        'translations' => [
635
                            'always-available' => 'and',
636
                        ],
637
                    ],
638
                    [
639
                        'always-available' => false,
640
                        'translations' => [
641
                            'eng-GB' => 'goodbye',
642
                        ],
643
                    ],
644
                ],
645
                ['eng-GB'],
646
                true,
647
                false,
648
                316,
649
                '8-69faab6268350295550de7d587bc323d',
650
            ],
651
            [
652
                'hello/everyone',
653
                [
654
                    [
655
                        'always-available' => false,
656
                        'translations' => [
657
                            'eng-GB' => 'hello',
658
                        ],
659
                    ],
660
                    [
661
                        'always-available' => false,
662
                        'translations' => [
663
                            'eng-GB' => 'everyone',
664
                        ],
665
                    ],
666
                ],
667
                ['eng-GB'],
668
                true,
669
                false,
670
                315,
671
                '6-ed881bac6397ede33c0a285c9f50bb83',
672
            ],
673
            [
674
                'well/ha-ha-ha',
675
                [
676
                    [
677
                        'always-available' => true,
678
                        'translations' => [
679
                            'always-available' => 'well',
680
                        ],
681
                    ],
682
                    [
683
                        'always-available' => false,
684
                        'translations' => [
685
                            'eng-GB' => 'ha-ha-ha',
686
                        ],
687
                    ],
688
                ],
689
                ['eng-GB'],
690
                false,
691
                false,
692
                317,
693
                '10-17a197f4bbe127c368b889a67effd1b3',
694
            ],
695
        ];
696
    }
697
698
    /**
699
     * Test for the lookup() method.
700
     *
701
     * Testing that UrlAlias is found and has expected state.
702
     *
703
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
704
     * @dataProvider providerForTestLookupCustomLocationUrlAlias
705
     * @depends testLookup
706
     * @group location
707
     * @group custom
708
     */
709 View Code Duplication
    public function testLookupCustomLocationUrlAlias(
710
        $url,
711
        array $pathData,
712
        array $languageCodes,
713
        $forward,
714
        $alwaysAvailable,
715
        $destination,
716
        $id
717
    ) {
718
        $handler = $this->getHandler();
719
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
720
721
        $urlAlias = $handler->lookup($url);
722
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
723
        self::assertEquals(
724
            new UrlAlias(
725
                [
726
                    'id' => $id,
727
                    'type' => UrlAlias::LOCATION,
728
                    'destination' => $destination,
729
                    'languageCodes' => $languageCodes,
730
                    'pathData' => $pathData,
731
                    'alwaysAvailable' => $alwaysAvailable,
732
                    'isHistory' => false,
733
                    'isCustom' => true,
734
                    'forward' => $forward,
735
                ]
736
            ),
737
            $urlAlias
738
        );
739
    }
740
741
    /**
742
     * Test for the lookup() method.
743
     *
744
     * Testing that UrlAlias is found and has expected state.
745
     *
746
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
747
     * @dataProvider providerForTestLookupCustomLocationUrlAlias
748
     * @depends testLookup
749
     * @group location
750
     * @group custom
751
     */
752 View Code Duplication
    public function testLookupCustomLocationUrlAliasCaseCorrection(
753
        $url,
754
        array $pathData,
755
        array $languageCodes,
756
        $forward,
757
        $alwaysAvailable,
758
        $destination,
759
        $id
760
    ) {
761
        $handler = $this->getHandler();
762
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
763
764
        $urlAlias = $handler->lookup(strtoupper($url));
765
766
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
767
        self::assertEquals(
768
            new UrlAlias(
769
                [
770
                    'id' => $id,
771
                    'type' => UrlAlias::LOCATION,
772
                    'destination' => $destination,
773
                    'languageCodes' => $languageCodes,
774
                    'pathData' => $pathData,
775
                    'alwaysAvailable' => $alwaysAvailable,
776
                    'isHistory' => false,
777
                    'isCustom' => true,
778
                    'forward' => $forward,
779
                ]
780
            ),
781
            $urlAlias
782
        );
783
    }
784
785
    public function providerForTestLookupVirtualUrlAlias()
786
    {
787
        return [
788
            [
789
                'hello/and',
790
                '6-be5d5d37542d75f93a87094459f76678',
791
            ],
792
            [
793
                'HELLO/AND',
794
                '6-be5d5d37542d75f93a87094459f76678',
795
            ],
796
        ];
797
    }
798
799
    /**
800
     * Test for the lookup() method.
801
     *
802
     * Testing that NOP action redirects to site root.
803
     *
804
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
805
     * @dataProvider providerForTestLookupVirtualUrlAlias
806
     * @depends testLookup
807
     * @group virtual
808
     */
809 View Code Duplication
    public function testLookupVirtualUrlAlias($url, $id)
810
    {
811
        $handler = $this->getHandler();
812
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
813
814
        $urlAlias = $handler->lookup($url);
815
816
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
817
    }
818
819
    public function providerForTestLookupResourceUrlAlias()
820
    {
821
        return [
822
            [
823
                'is-alive',
824
                [
825
                    [
826
                        'always-available' => true,
827
                        'translations' => [
828
                            'eng-GB' => 'is-alive',
829
                        ],
830
                    ],
831
                ],
832
                ['eng-GB'],
833
                true,
834
                true,
835
                'ezinfo/isalive',
836
                '0-d003895fa282a14c8ec3eddf23ca4ca2',
837
            ],
838
            [
839
                'is-alive/then/search',
840
                [
841
                    [
842
                        'always-available' => true,
843
                        'translations' => [
844
                            'eng-GB' => 'is-alive',
845
                        ],
846
                    ],
847
                    [
848
                        'always-available' => true,
849
                        'translations' => [
850
                            'always-available' => 'then',
851
                        ],
852
                    ],
853
                    [
854
                        'always-available' => false,
855
                        'translations' => [
856
                            'cro-HR' => 'search',
857
                        ],
858
                    ],
859
                ],
860
                ['cro-HR'],
861
                false,
862
                false,
863
                'content/search',
864
                '3-06a943c59f33a34bb5924aaf72cd2995',
865
            ],
866
        ];
867
    }
868
869
    /**
870
     * Test for the lookup() method.
871
     *
872
     * Testing that UrlAlias is found and has expected state.
873
     *
874
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
875
     * @dataProvider providerForTestLookupResourceUrlAlias
876
     * @depends testLookup
877
     * @group resource
878
     */
879 View Code Duplication
    public function testLookupResourceUrlAlias(
880
        $url,
881
        $pathData,
882
        array $languageCodes,
883
        $forward,
884
        $alwaysAvailable,
885
        $destination,
886
        $id
887
    ) {
888
        $handler = $this->getHandler();
889
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
890
891
        $urlAlias = $handler->lookup($url);
892
893
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
894
        self::assertEquals(
895
            new UrlAlias(
896
                [
897
                    'id' => $id,
898
                    'type' => UrlAlias::RESOURCE,
899
                    'destination' => $destination,
900
                    'languageCodes' => $languageCodes,
901
                    'pathData' => $pathData,
902
                    'alwaysAvailable' => $alwaysAvailable,
903
                    'isHistory' => false,
904
                    'isCustom' => true,
905
                    'forward' => $forward,
906
                ]
907
            ),
908
            $urlAlias
909
        );
910
    }
911
912
    /**
913
     * Test for the lookup() method.
914
     *
915
     * Testing that UrlAlias is found and has expected state.
916
     *
917
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
918
     * @dataProvider providerForTestLookupResourceUrlAlias
919
     * @depends testLookup
920
     * @group resource
921
     */
922 View Code Duplication
    public function testLookupResourceUrlAliasCaseInsensitive(
923
        $url,
924
        $pathData,
925
        array $languageCodes,
926
        $forward,
927
        $alwaysAvailable,
928
        $destination,
929
        $id
930
    ) {
931
        $handler = $this->getHandler();
932
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
933
934
        $urlAlias = $handler->lookup(strtoupper($url));
935
936
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
937
        self::assertEquals(
938
            new UrlAlias(
939
                [
940
                    'id' => $id,
941
                    'type' => UrlAlias::RESOURCE,
942
                    'destination' => $destination,
943
                    'languageCodes' => $languageCodes,
944
                    'pathData' => $pathData,
945
                    'alwaysAvailable' => $alwaysAvailable,
946
                    'isHistory' => false,
947
                    'isCustom' => true,
948
                    'forward' => $forward,
949
                ]
950
            ),
951
            $urlAlias
952
        );
953
    }
954
955
    /**
956
     * Test for the lookup() method with uppercase utf8 characters.
957
     *
958
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
959
     * @depends testLookup
960
     */
961 View Code Duplication
    public function testLookupUppercaseIri()
962
    {
963
        $handler = $this->getHandler();
964
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_iri.php');
965
966
        $urlAlias = $handler->lookup('΀');
967
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
968
    }
969
970
    protected function assertVirtualUrlAliasValid(UrlAlias $urlAlias, $id)
971
    {
972
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
973
        self::assertEquals($id, $urlAlias->id);
974
        self::assertEquals(UrlAlias::VIRTUAL, $urlAlias->type);
975
        /*self::assertEquals(
976
            new UrlAlias(
977
                array(
978
                    "id" => $id,
979
                    "type" => UrlAlias::VIRTUAL,
980
                    "destination" => null,
981
                    "languageCodes" => array(),
982
                    "pathData" => null,
983
                    "alwaysAvailable" => true,
984
                    "isHistory" => true,
985
                    "isCustom" => false,
986
                    "forward" => false
987
                )
988
            ),
989
            $urlAlias
990
        );*/
991
    }
992
993
    /**
994
     * Test for the listURLAliasesForLocation() method.
995
     *
996
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listURLAliasesForLocation
997
     */
998
    public function testListURLAliasesForLocation()
999
    {
1000
        $handler = $this->getHandler();
1001
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
1002
1003
        $urlAliases = $handler->listURLAliasesForLocation(315);
1004
1005
        self::assertEquals(
1006
            [
1007
                new UrlAlias(
1008
                    [
1009
                        'id' => '2-b8a9f715dbb64fd5c56e7783c6820a61',
1010
                        'type' => UrlAlias::LOCATION,
1011
                        'destination' => 315,
1012
                        'languageCodes' => ['eng-GB'],
1013
                        'pathData' => [
1014
                            [
1015
                                'always-available' => true,
1016
                                'translations' => ['cro-HR' => 'jedan'],
1017
                            ],
1018
                            [
1019
                                'always-available' => false,
1020
                                'translations' => [
1021
                                    'cro-HR' => 'dva',
1022
                                    'eng-GB' => 'two',
1023
                                ],
1024
                            ],
1025
                        ],
1026
                        'alwaysAvailable' => false,
1027
                        'isHistory' => false,
1028
                        'isCustom' => false,
1029
                        'forward' => false,
1030
                    ]
1031
                ),
1032
                new UrlAlias(
1033
                    [
1034
                        'id' => '2-c67ed9a09ab136fae610b6a087d82e21',
1035
                        'type' => UrlAlias::LOCATION,
1036
                        'destination' => 315,
1037
                        'languageCodes' => ['cro-HR'],
1038
                        'pathData' => [
1039
                            [
1040
                                'always-available' => true,
1041
                                'translations' => ['cro-HR' => 'jedan'],
1042
                            ],
1043
                            [
1044
                                'always-available' => false,
1045
                                'translations' => [
1046
                                    'cro-HR' => 'dva',
1047
                                    'eng-GB' => 'two',
1048
                                ],
1049
                            ],
1050
                        ],
1051
                        'alwaysAvailable' => false,
1052
                        'isHistory' => false,
1053
                        'isCustom' => false,
1054
                        'forward' => false,
1055
                    ]
1056
                ),
1057
            ],
1058
            $urlAliases
1059
        );
1060
    }
1061
1062
    /**
1063
     * Test for the publishUrlAliasForLocation() method.
1064
     *
1065
     * @todo document
1066
     *
1067
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1068
     * @depends testLookupLocationUrlAlias
1069
     * @group publish
1070
     */
1071 View Code Duplication
    public function testPublishUrlAliasForLocation()
1072
    {
1073
        $handler = $this->getHandler();
1074
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1075
1076
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1077
        $publishedUrlAlias = $handler->lookup('simple');
1078
1079
        self::assertEquals(4, $this->countRows());
1080
        self::assertEquals(
1081
            new UrlAlias(
1082
                [
1083
                    'id' => '0-' . md5('simple'),
1084
                    'type' => UrlAlias::LOCATION,
1085
                    'destination' => 314,
1086
                    'languageCodes' => ['eng-GB'],
1087
                    'pathData' => [
1088
                        [
1089
                            'always-available' => true,
1090
                            'translations' => [
1091
                                'eng-GB' => 'simple',
1092
                                'cro-HR' => 'path314',
1093
                            ],
1094
                        ],
1095
                    ],
1096
                    'alwaysAvailable' => true,
1097
                    'isHistory' => false,
1098
                    'isCustom' => false,
1099
                    'forward' => false,
1100
                ]
1101
            ),
1102
            $publishedUrlAlias
1103
        );
1104
    }
1105
1106
    /**
1107
     * Test for the publishUrlAliasForLocation() method.
1108
     *
1109
     * @todo document
1110
     *
1111
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1112
     * @depends testPublishUrlAliasForLocation
1113
     * @group publish
1114
     */
1115
    public function testPublishUrlAliasForLocationRepublish()
1116
    {
1117
        $handler = $this->getHandler();
1118
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1119
1120
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1121
        $publishedUrlAlias = $handler->lookup('simple');
1122
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1123
        $republishedUrlAlias = $handler->lookup('simple');
1124
1125
        self::assertEquals(4, $this->countRows());
1126
        self::assertEquals(
1127
            $publishedUrlAlias,
1128
            $republishedUrlAlias
1129
        );
1130
    }
1131
1132
    /**
1133
     * Test for the publishUrlAliasForLocation() method.
1134
     *
1135
     * @todo document
1136
     *
1137
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1138
     * @depends testPublishUrlAliasForLocation
1139
     * @group publish
1140
     */
1141 View Code Duplication
    public function testPublishUrlAliasCreatesUniqueAlias()
1142
    {
1143
        $handler = $this->getHandler();
1144
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1145
1146
        $handler->publishUrlAliasForLocation(314, 2, 'simple', 'eng-GB', true);
1147
        $handler->publishUrlAliasForLocation(315, 2, 'simple', 'eng-GB', true);
1148
        self::assertEquals(5, $this->countRows());
1149
1150
        $urlAlias = $handler->lookup('simple2');
1151
        self::assertEquals(
1152
            new UrlAlias(
1153
                [
1154
                    'id' => '0-' . md5('simple2'),
1155
                    'type' => UrlAlias::LOCATION,
1156
                    'destination' => 315,
1157
                    'languageCodes' => ['eng-GB'],
1158
                    'pathData' => [
1159
                        [
1160
                            'always-available' => true,
1161
                            'translations' => [
1162
                                'eng-GB' => 'simple2',
1163
                            ],
1164
                        ],
1165
                    ],
1166
                    'alwaysAvailable' => true,
1167
                    'isHistory' => false,
1168
                    'isCustom' => false,
1169
                    'forward' => false,
1170
                ]
1171
            ),
1172
            $urlAlias
1173
        );
1174
    }
1175
1176
    /**
1177
     * @return array
1178
     */
1179
    public function providerForTestPublishUrlAliasForLocationComplex()
1180
    {
1181
        return $this->providerForTestLookupLocationUrlAlias();
1182
    }
1183
1184
    /**
1185
     * Test for the publishUrlAliasForLocation() method.
1186
     *
1187
     * @todo document
1188
     *
1189
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1190
     * @dataProvider providerForTestPublishUrlAliasForLocationComplex
1191
     * @depends testPublishUrlAliasForLocation
1192
     * @group publish
1193
     */
1194
    public function testPublishUrlAliasForLocationComplex(
1195
        $url,
1196
        $pathData,
1197
        array $languageCodes,
1198
        $alwaysAvailable,
1199
        $locationId,
1200
        $id
1201
    ) {
1202
        $handler = $this->getHandler();
1203
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1204
1205
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', true);
1206
        $handler->publishUrlAliasForLocation(315, 314, 'dva', 'cro-HR', false);
1207
        $handler->publishUrlAliasForLocation(315, 314, 'two', 'eng-GB', false);
1208
        $handler->publishUrlAliasForLocation(316, 315, 'tri', 'cro-HR', false);
1209
        $handler->publishUrlAliasForLocation(316, 315, 'three', 'eng-GB', false);
1210
        $handler->publishUrlAliasForLocation(316, 315, 'drei', 'ger-DE', false);
1211
1212
        $urlAlias = $handler->lookup($url);
1213
1214
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
1215
        self::assertEquals(
1216
            new UrlAlias(
1217
                [
1218
                    'id' => $id,
1219
                    'type' => UrlAlias::LOCATION,
1220
                    'destination' => $locationId,
1221
                    'languageCodes' => $languageCodes,
1222
                    'pathData' => $pathData,
1223
                    'alwaysAvailable' => $alwaysAvailable,
1224
                    'isHistory' => false,
1225
                    'isCustom' => false,
1226
                    'forward' => false,
1227
                ]
1228
            ),
1229
            $urlAlias
1230
        );
1231
    }
1232
1233
    /**
1234
     * Test for the publishUrlAliasForLocation() method.
1235
     *
1236
     * @todo document
1237
     *
1238
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1239
     * @depends testPublishUrlAliasForLocation
1240
     * @group publish
1241
     */
1242
    public function testPublishUrlAliasForLocationSameAliasForMultipleLanguages()
1243
    {
1244
        $handler = $this->getHandler();
1245
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1246
1247
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1248
        $urlAlias1 = $handler->lookup('jedan');
1249
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB', false);
1250
        $urlAlias2 = $handler->lookup('jedan');
1251
1252
        self::assertEquals(4, $this->countRows());
1253
1254
        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...
1255
            if ($propertyName === 'languageCodes') {
1256
                self::assertEquals(
1257
                    ['cro-HR', 'eng-GB'],
1258
                    $urlAlias2->languageCodes
1259
                );
1260
            } elseif ($propertyName === 'pathData') {
1261
                self::assertEquals(
1262
                    [
1263
                        [
1264
                            'always-available' => false,
1265
                            'translations' => [
1266
                                'cro-HR' => 'jedan',
1267
                                'eng-GB' => 'jedan',
1268
                            ],
1269
                        ],
1270
                    ],
1271
                    $urlAlias2->pathData
1272
                );
1273
            } else {
1274
                self::assertEquals(
1275
                    $urlAlias1->$propertyName,
1276
                    $urlAlias2->$propertyName
1277
                );
1278
            }
1279
        }
1280
    }
1281
1282
    /**
1283
     * Test for the publishUrlAliasForLocation() method.
1284
     *
1285
     * @todo document
1286
     *
1287
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1288
     * @depends testPublishUrlAliasForLocation
1289
     * @group publish
1290
     */
1291
    public function testPublishUrlAliasForLocationDowngradesOldEntryToHistory()
1292
    {
1293
        $handler = $this->getHandler();
1294
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1295
1296
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1297
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', true);
1298
1299
        self::assertEquals(5, $this->countRows());
1300
1301
        $newUrlAlias = $handler->lookup('dva');
1302
1303
        self::assertEquals(
1304
            new UrlAlias(
1305
                [
1306
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1307
                    'type' => 0,
1308
                    'destination' => 314,
1309
                    'languageCodes' => ['cro-HR'],
1310
                    'pathData' => [
1311
                        [
1312
                            'always-available' => true,
1313
                            'translations' => [
1314
                                'cro-HR' => 'dva',
1315
                            ],
1316
                        ],
1317
                    ],
1318
                    'alwaysAvailable' => true,
1319
                    'isHistory' => false,
1320
                    'isCustom' => false,
1321
                    'forward' => false,
1322
                ]
1323
            ),
1324
            $newUrlAlias
1325
        );
1326
1327
        $historyUrlAlias = $handler->lookup('jedan');
1328
1329
        self::assertEquals(
1330
            new UrlAlias(
1331
                [
1332
                    'id' => '0-6896260129051a949051c3847c34466f',
1333
                    'type' => 0,
1334
                    'destination' => 314,
1335
                    'languageCodes' => ['cro-HR'],
1336
                    'pathData' => [
1337
                        [
1338
                            'always-available' => false,
1339
                            'translations' => [
1340
                                'cro-HR' => 'jedan',
1341
                            ],
1342
                        ],
1343
                    ],
1344
                    'alwaysAvailable' => false,
1345
                    'isHistory' => true,
1346
                    'isCustom' => false,
1347
                    'forward' => false,
1348
                ]
1349
            ),
1350
            $historyUrlAlias
1351
        );
1352
    }
1353
1354
    /**
1355
     * Test for the publishUrlAliasForLocation() method.
1356
     *
1357
     * @todo document
1358
     *
1359
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1360
     * @depends testPublishUrlAliasForLocation
1361
     * @depends testPublishUrlAliasForLocationSameAliasForMultipleLanguages
1362
     * @group publish
1363
     * @group downgrade
1364
     */
1365
    public function testPublishUrlAliasForLocationDowngradesOldEntryRemovesLanguage()
1366
    {
1367
        $handler = $this->getHandler();
1368
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1369
1370
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1371
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB');
1372
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'eng-GB');
1373
1374
        self::assertEquals(5, $this->countRows());
1375
1376
        $urlAlias = $handler->lookup('dva');
1377
        self::assertEquals(
1378
            new UrlAlias(
1379
                [
1380
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1381
                    'type' => UrlAlias::LOCATION,
1382
                    'destination' => 314,
1383
                    'languageCodes' => ['eng-GB'],
1384
                    'pathData' => [
1385
                        [
1386
                            'always-available' => false,
1387
                            'translations' => [
1388
                                'cro-HR' => 'jedan',
1389
                                'eng-GB' => 'dva',
1390
                            ],
1391
                        ],
1392
                    ],
1393
                    'alwaysAvailable' => false,
1394
                    'isHistory' => false,
1395
                    'isCustom' => false,
1396
                    'forward' => false,
1397
                ]
1398
            ),
1399
            $urlAlias
1400
        );
1401
1402
        $downgradedUrlAlias = $handler->lookup('jedan');
1403
        self::assertEquals(
1404
            new UrlAlias(
1405
                [
1406
                    'id' => '0-6896260129051a949051c3847c34466f',
1407
                    'type' => UrlAlias::LOCATION,
1408
                    'destination' => 314,
1409
                    'languageCodes' => ['cro-HR'],
1410
                    'pathData' => [
1411
                        [
1412
                            'always-available' => false,
1413
                            'translations' => [
1414
                                'cro-HR' => 'jedan',
1415
                                'eng-GB' => 'dva',
1416
                            ],
1417
                        ],
1418
                    ],
1419
                    'alwaysAvailable' => false,
1420
                    'isHistory' => false,
1421
                    'isCustom' => false,
1422
                    'forward' => false,
1423
                ]
1424
            ),
1425
            $downgradedUrlAlias
1426
        );
1427
    }
1428
1429
    /**
1430
     * Test for the publishUrlAliasForLocation() method.
1431
     *
1432
     * @todo document
1433
     *
1434
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1435
     * @depends testPublishUrlAliasForLocation
1436
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1437
     * @group publish
1438
     */
1439
    public function testPublishUrlAliasForLocationReusesHistory()
1440
    {
1441
        $handler = $this->getHandler();
1442
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1443
1444
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1445
        $urlAlias = $handler->lookup('jedan');
1446
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR');
1447
        $countBeforeReusing = $this->countRows();
1448
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1449
        $urlAliasReusesHistory = $handler->lookup('jedan');
1450
1451
        self::assertEquals(
1452
            $countBeforeReusing,
1453
            $this->countRows()
1454
        );
1455
1456
        self::assertEquals(
1457
            $urlAlias,
1458
            $urlAliasReusesHistory
1459
        );
1460
    }
1461
1462
    /**
1463
     * Test for the publishUrlAliasForLocation() method.
1464
     *
1465
     * @todo document
1466
     *
1467
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1468
     * @depends testPublishUrlAliasForLocation
1469
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1470
     * @group publish
1471
     */
1472
    public function testPublishUrlAliasForLocationReusesHistoryOfDifferentLanguage()
1473
    {
1474
        $handler = $this->getHandler();
1475
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1476
1477
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1478
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'eng-GB');
1479
        $handler->publishUrlAliasForLocation(314, 2, 'one-new', 'eng-GB');
1480
        $countBeforeReusing = $this->countRows();
1481
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'cro-HR');
1482
        $urlAliasReusesHistory = $handler->lookup('one-history');
1483
1484
        self::assertEquals(
1485
            $countBeforeReusing,
1486
            $this->countRows()
1487
        );
1488
1489
        self::assertEquals(
1490
            new UrlAlias(
1491
                [
1492
                    'id' => '0-' . md5('one-history'),
1493
                    'type' => UrlAlias::LOCATION,
1494
                    'destination' => 314,
1495
                    'languageCodes' => ['cro-HR'],
1496
                    'pathData' => [
1497
                        [
1498
                            'always-available' => false,
1499
                            'translations' => [
1500
                                'cro-HR' => 'one-history',
1501
                                'eng-GB' => 'one-new',
1502
                            ],
1503
                        ],
1504
                    ],
1505
                    'alwaysAvailable' => false,
1506
                    'isHistory' => false,
1507
                    'isCustom' => false,
1508
                    'forward' => false,
1509
                ]
1510
            ),
1511
            $urlAliasReusesHistory
1512
        );
1513
    }
1514
1515
    /**
1516
     * Test for the publishUrlAliasForLocation() method.
1517
     *
1518
     * @todo document
1519
     *
1520
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1521
     * @depends testPublishUrlAliasForLocation
1522
     * @group publish
1523
     */
1524 View Code Duplication
    public function testPublishUrlAliasForLocationReusesCustomAlias()
1525
    {
1526
        $handler = $this->getHandler();
1527
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1528
1529
        $countBeforeReusing = $this->countRows();
1530
        $handler->publishUrlAliasForLocation(314, 2, 'custom-hello', 'eng-GB', false);
1531
        $urlAlias = $handler->lookup('custom-hello');
1532
1533
        self::assertEquals(
1534
            $countBeforeReusing,
1535
            $this->countRows()
1536
        );
1537
        self::assertFalse($urlAlias->isCustom);
1538
    }
1539
1540
    /**
1541
     * Test for the publishUrlAliasForLocation() method.
1542
     *
1543
     * @todo document
1544
     *
1545
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1546
     * @depends testPublishUrlAliasForLocation
1547
     */
1548
    public function testPublishUrlAliasForLocationReusingNopElement()
1549
    {
1550
        $handler = $this->getHandler();
1551
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1552
1553
        $countBeforeReusing = $this->countRows();
1554
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1555
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1556
        $publishedLocationUrlAlias = $handler->lookup('nop-element');
1557
1558
        self::assertEquals(
1559
            $countBeforeReusing,
1560
            $this->countRows()
1561
        );
1562
1563
        self::assertInstanceOf(UrlAlias::class, $publishedLocationUrlAlias);
1564
        self::assertEquals(
1565
            new UrlAlias(
1566
                [
1567
                    'id' => '0-de55c2fff721217cc4cb67b58dc35f85',
1568
                    'type' => UrlAlias::LOCATION,
1569
                    'destination' => 315,
1570
                    'languageCodes' => ['eng-GB'],
1571
                    'pathData' => [
1572
                        [
1573
                            'always-available' => false,
1574
                            'translations' => ['eng-GB' => 'nop-element'],
1575
                        ],
1576
                    ],
1577
                    'alwaysAvailable' => false,
1578
                    'isHistory' => false,
1579
                    'isCustom' => false,
1580
                    'forward' => false,
1581
                ]
1582
            ),
1583
            $publishedLocationUrlAlias
1584
        );
1585
1586
        $virtualUrlAliasReloaded = $handler->lookup('nop-element/search');
1587 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...
1588
            if ($propertyName === 'pathData') {
1589
                self::assertEquals(
1590
                    [
1591
                        [
1592
                            'always-available' => false,
1593
                            'translations' => ['eng-GB' => 'nop-element'],
1594
                        ],
1595
                        [
1596
                            'always-available' => false,
1597
                            'translations' => ['eng-GB' => 'search'],
1598
                        ],
1599
                    ],
1600
                    $virtualUrlAliasReloaded->pathData
1601
                );
1602
            } else {
1603
                self::assertEquals(
1604
                    $virtualUrlAlias->$propertyName,
1605
                    $virtualUrlAliasReloaded->$propertyName
1606
                );
1607
            }
1608
        }
1609
    }
1610
1611
    /**
1612
     * Test for the publishUrlAliasForLocation() method.
1613
     *
1614
     * @todo document
1615
     *
1616
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1617
     * @depends testPublishUrlAliasForLocation
1618
     * @depends testPublishUrlAliasForLocationReusingNopElement
1619
     */
1620
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPath()
1621
    {
1622
        $handler = $this->getHandler();
1623
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1624
1625
        $countBeforeReusing = $this->countRows();
1626
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1627
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1628
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1629
        $virtualUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1630
1631
        self::assertEquals(
1632
            $countBeforeReusing + 1,
1633
            $this->countRows()
1634
        );
1635
1636 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...
1637
            if ($propertyName === 'pathData') {
1638
                self::assertEquals(
1639
                    [
1640
                        [
1641
                            'always-available' => false,
1642
                            'translations' => ['eng-GB' => 'nop-element-renamed'],
1643
                        ],
1644
                        [
1645
                            'always-available' => false,
1646
                            'translations' => ['eng-GB' => 'search'],
1647
                        ],
1648
                    ],
1649
                    $virtualUrlAliasChanged->pathData
1650
                );
1651
            } else {
1652
                self::assertEquals(
1653
                    $virtualUrlAlias->$propertyName,
1654
                    $virtualUrlAliasChanged->$propertyName
1655
                );
1656
            }
1657
        }
1658
    }
1659
1660
    /**
1661
     * Test for the publishUrlAliasForLocation() method.
1662
     *
1663
     * @todo document
1664
     *
1665
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1666
     * @depends testPublishUrlAliasForLocation
1667
     * @depends testPublishUrlAliasForLocationReusingNopElementChangesCustomPath
1668
     */
1669
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPathAndCreatesHistory()
1670
    {
1671
        $handler = $this->getHandler();
1672
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1673
1674
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1675
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1676
1677
        $customUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1678
        $customUrlAliasHistory = $handler->lookup('nop-element/search');
1679
1680
        self::assertTrue($customUrlAliasHistory->isHistory);
1681
        $customUrlAliasHistory->isHistory = false;
1682
        self::assertEquals(
1683
            $customUrlAliasChanged,
1684
            $customUrlAliasHistory
1685
        );
1686
    }
1687
1688
    /**
1689
     * Test for the publishUrlAliasForLocation() method.
1690
     *
1691
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1692
     */
1693
    public function testPublishUrlAliasForLocationUpdatesLocationPathIdentificationString()
1694
    {
1695
        $handler = $this->getHandler();
1696
        $locationGateway = $this->getLocationGateway();
1697
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1698
1699
        // Publishes the alias indicating that language is main, triggering updating of path_identification_string
1700
        $handler->publishUrlAliasForLocation(316, 315, 'TEST TEST TEST', 'eng-GB', false, true);
1701
1702
        $locationData = $locationGateway->getBasicNodeData(316);
1703
1704
        self::assertEquals('path314/path315/test_test_test', $locationData['path_identification_string']);
1705
    }
1706
1707
    /**
1708
     * Test for the publishUrlAliasForLocation() method.
1709
     *
1710
     * @group cleanup
1711
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1712
     */
1713
    public function testPublishUrlAliasReuseNopCleanupCustomAliasIsDestroyed()
1714
    {
1715
        $handler = $this->getHandler();
1716
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_nop.php');
1717
1718
        $handler->lookup('nop-element/search');
1719
        $handler->publishUrlAliasForLocation(314, 2, 'nop-element', 'cro-HR', false);
1720
1721
        $urlAlias = $handler->lookup('jedan');
1722
        $this->assertEquals(
1723
            new UrlAlias(
1724
                [
1725
                    'id' => '0-' . md5('jedan'),
1726
                    'type' => UrlAlias::LOCATION,
1727
                    'destination' => 314,
1728
                    'pathData' => [
1729
                        [
1730
                            'always-available' => false,
1731
                            'translations' => ['cro-HR' => 'jedan'],
1732
                        ],
1733
                    ],
1734
                    'languageCodes' => ['cro-HR'],
1735
                    'alwaysAvailable' => false,
1736
                    'isHistory' => true,
1737
                    'isCustom' => false,
1738
                    'forward' => false,
1739
                ]
1740
            ),
1741
            $urlAlias
1742
        );
1743
1744
        $urlAlias = $handler->lookup('nop-element');
1745
        $this->assertEquals(
1746
            new UrlAlias(
1747
                [
1748
                    'id' => '0-' . md5('nop-element'),
1749
                    'type' => UrlAlias::LOCATION,
1750
                    'destination' => 314,
1751
                    'pathData' => [
1752
                        [
1753
                            'always-available' => false,
1754
                            'translations' => [
1755
                                'cro-HR' => 'nop-element',
1756
                                'eng-GB' => 'dva',
1757
                            ],
1758
                        ],
1759
                    ],
1760
                    'languageCodes' => [
1761
                        'cro-HR',
1762
                    ],
1763
                    'alwaysAvailable' => false,
1764
                    'isHistory' => false,
1765
                    'isCustom' => false,
1766
                    'forward' => false,
1767
                ]
1768
            ),
1769
            $urlAlias
1770
        );
1771
1772
        try {
1773
            $handler->lookup('nop-element/search');
1774
            $this->fail('Custom alias is not destroyed');
1775
        } catch (NotFoundException $e) {
1776
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
1777
            // on the same level (that means link and ID are updated to the existing alias ID,
1778
            // so custom alias children entries are no longer properly linked (parent-link))
1779
        }
1780
    }
1781
1782
    /**
1783
     * Test for the publishUrlAliasForLocation() method.
1784
     *
1785
     * @group cleanup
1786
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1787
     */
1788 View Code Duplication
    public function testPublishUrlAliasReuseHistoryCleanup()
1789
    {
1790
        $handler = $this->getHandler();
1791
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_history.php');
1792
1793
        $handler->publishUrlAliasForLocation(314, 2, 'tri', 'cro-HR', false);
1794
1795
        $urlAlias = $handler->lookup('jedan');
1796
        $this->assertEquals(
1797
            new UrlAlias(
1798
                [
1799
                    'id' => '0-' . md5('jedan'),
1800
                    'type' => UrlAlias::LOCATION,
1801
                    'destination' => 314,
1802
                    'pathData' => [
1803
                        [
1804
                            'always-available' => false,
1805
                            'translations' => ['cro-HR' => 'jedan'],
1806
                        ],
1807
                    ],
1808
                    'languageCodes' => ['cro-HR'],
1809
                    'alwaysAvailable' => false,
1810
                    'isHistory' => true,
1811
                    'isCustom' => false,
1812
                    'forward' => false,
1813
                ]
1814
            ),
1815
            $urlAlias
1816
        );
1817
1818
        $urlAlias = $handler->lookup('tri');
1819
        $this->assertEquals(
1820
            new UrlAlias(
1821
                [
1822
                    'id' => '0-' . md5('tri'),
1823
                    'type' => UrlAlias::LOCATION,
1824
                    'destination' => 314,
1825
                    'pathData' => [
1826
                        [
1827
                            'always-available' => false,
1828
                            'translations' => [
1829
                                'cro-HR' => 'tri',
1830
                                'eng-GB' => 'dva',
1831
                            ],
1832
                        ],
1833
                    ],
1834
                    'languageCodes' => [
1835
                        'cro-HR',
1836
                    ],
1837
                    'alwaysAvailable' => false,
1838
                    'isHistory' => false,
1839
                    'isCustom' => false,
1840
                    'forward' => false,
1841
                ]
1842
            ),
1843
            $urlAlias
1844
        );
1845
    }
1846
1847
    /**
1848
     * Test for the publishUrlAliasForLocation() method.
1849
     *
1850
     * @group cleanup
1851
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1852
     */
1853 View Code Duplication
    public function testPublishUrlAliasReuseAutogeneratedCleanup()
1854
    {
1855
        $handler = $this->getHandler();
1856
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_reusing.php');
1857
1858
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', false);
1859
1860
        $urlAlias = $handler->lookup('jedan');
1861
        $this->assertEquals(
1862
            new UrlAlias(
1863
                [
1864
                    'id' => '0-' . md5('jedan'),
1865
                    'type' => UrlAlias::LOCATION,
1866
                    'destination' => 314,
1867
                    'pathData' => [
1868
                        [
1869
                            'always-available' => false,
1870
                            'translations' => ['cro-HR' => 'jedan'],
1871
                        ],
1872
                    ],
1873
                    'languageCodes' => ['cro-HR'],
1874
                    'alwaysAvailable' => false,
1875
                    'isHistory' => true,
1876
                    'isCustom' => false,
1877
                    'forward' => false,
1878
                ]
1879
            ),
1880
            $urlAlias
1881
        );
1882
1883
        $urlAlias = $handler->lookup('dva');
1884
        $this->assertEquals(
1885
            new UrlAlias(
1886
                [
1887
                    'id' => '0-' . md5('dva'),
1888
                    'type' => UrlAlias::LOCATION,
1889
                    'destination' => 314,
1890
                    'pathData' => [
1891
                        [
1892
                            'always-available' => false,
1893
                            'translations' => [
1894
                                'cro-HR' => 'dva',
1895
                                'eng-GB' => 'dva',
1896
                            ],
1897
                        ],
1898
                    ],
1899
                    'languageCodes' => [
1900
                        'cro-HR',
1901
                        'eng-GB',
1902
                    ],
1903
                    'alwaysAvailable' => false,
1904
                    'isHistory' => false,
1905
                    'isCustom' => false,
1906
                    'forward' => false,
1907
                ]
1908
            ),
1909
            $urlAlias
1910
        );
1911
    }
1912
1913
    /**
1914
     * Test for the createCustomUrlAlias() method.
1915
     *
1916
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createCustomUrlAlias
1917
     * @group create
1918
     * @group custom
1919
     */
1920 View Code Duplication
    public function testCreateCustomUrlAliasBehaviour()
1921
    {
1922
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1923
1924
        $handlerMock->expects(
1925
            $this->once()
1926
        )->method(
1927
            'createUrlAlias'
1928
        )->with(
1929
            $this->equalTo('eznode:1'),
1930
            $this->equalTo('path'),
1931
            $this->equalTo(false),
1932
            $this->equalTo(null),
1933
            $this->equalTo(false)
1934
        )->will(
1935
            $this->returnValue(
1936
                new UrlAlias()
1937
            )
1938
        );
1939
1940
        $this->assertInstanceOf(
1941
            UrlAlias::class,
1942
            $handlerMock->createCustomUrlAlias(1, 'path')
1943
        );
1944
    }
1945
1946
    /**
1947
     * Test for the createGlobalUrlAlias() method.
1948
     *
1949
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createGlobalUrlAlias
1950
     * @group create
1951
     * @group global
1952
     */
1953 View Code Duplication
    public function testCreateGlobalUrlAliasBehaviour()
1954
    {
1955
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1956
1957
        $handlerMock->expects(
1958
            $this->once()
1959
        )->method(
1960
            'createUrlAlias'
1961
        )->with(
1962
            $this->equalTo('module/module'),
1963
            $this->equalTo('path'),
1964
            $this->equalTo(false),
1965
            $this->equalTo(null),
1966
            $this->equalTo(false)
1967
        )->will(
1968
            $this->returnValue(
1969
                new UrlAlias()
1970
            )
1971
        );
1972
1973
        $this->assertInstanceOf(
1974
            UrlAlias::class,
1975
            $handlerMock->createGlobalUrlAlias('module/module', 'path')
1976
        );
1977
    }
1978
1979
    /**
1980
     * Test for the createUrlAlias() method.
1981
     *
1982
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
1983
     * @group create
1984
     * @group custom
1985
     */
1986
    public function testCreateCustomUrlAlias()
1987
    {
1988
        $handler = $this->getHandler();
1989
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1990
1991
        $path = 'custom-location-alias';
1992
        $customUrlAlias = $handler->createCustomUrlAlias(
1993
            314,
1994
            $path,
1995
            false,
1996
            'cro-HR',
1997
            false
1998
        );
1999
2000
        self::assertEquals(4, $this->countRows());
2001
        self::assertEquals(
2002
            new UrlAlias(
2003
                [
2004
                    'id' => '0-' . md5($path),
2005
                    'type' => UrlAlias::LOCATION,
2006
                    'destination' => 314,
2007
                    'pathData' => [
2008
                        [
2009
                            'always-available' => false,
2010
                            'translations' => [
2011
                                'cro-HR' => 'custom-location-alias',
2012
                            ],
2013
                        ],
2014
                    ],
2015
                    'languageCodes' => ['cro-HR'],
2016
                    'alwaysAvailable' => false,
2017
                    'isHistory' => false,
2018
                    'isCustom' => true,
2019
                    'forward' => false,
2020
                ]
2021
            ),
2022
            $customUrlAlias
2023
        );
2024
    }
2025
2026
    /**
2027
     * Test for the createUrlAlias() method.
2028
     *
2029
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2030
     * @group create
2031
     * @group custom
2032
     */
2033
    public function testCreateCustomUrlAliasWithNonameParts()
2034
    {
2035
        $handler = $this->getHandler();
2036
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2037
2038
        $path = 'there-is-a//custom-location-alias//here';
2039
        $customUrlAlias = $handler->createCustomUrlAlias(
2040
            314,
2041
            $path,
2042
            false,
2043
            'cro-HR',
2044
            false
2045
        );
2046
2047
        self::assertEquals(8, $this->countRows());
2048
2049
        self::assertEquals(
2050
            new UrlAlias(
2051
                [
2052
                    'id' => '7-' . md5('here'),
2053
                    'type' => UrlAlias::LOCATION,
2054
                    'destination' => 314,
2055
                    'pathData' => [
2056
                        [
2057
                            'always-available' => true,
2058
                            'translations' => [
2059
                                'always-available' => 'there-is-a',
2060
                            ],
2061
                        ],
2062
                        [
2063
                            'always-available' => true,
2064
                            'translations' => [
2065
                                'always-available' => 'noname2',
2066
                            ],
2067
                        ],
2068
                        [
2069
                            'always-available' => true,
2070
                            'translations' => [
2071
                                'always-available' => 'custom-location-alias',
2072
                            ],
2073
                        ],
2074
                        [
2075
                            'always-available' => true,
2076
                            'translations' => [
2077
                                'always-available' => 'noname4',
2078
                            ],
2079
                        ],
2080
                        [
2081
                            'always-available' => false,
2082
                            'translations' => [
2083
                                'cro-HR' => 'here',
2084
                            ],
2085
                        ],
2086
                    ],
2087
                    'languageCodes' => ['cro-HR'],
2088
                    'alwaysAvailable' => false,
2089
                    'isHistory' => false,
2090
                    'isCustom' => true,
2091
                    'forward' => false,
2092
                ]
2093
            ),
2094
            $customUrlAlias
2095
        );
2096
    }
2097
2098
    /**
2099
     * Test for the createUrlAlias() method.
2100
     *
2101
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2102
     * @group create
2103
     * @group custom
2104
     *
2105
     * @todo pathData
2106
     */
2107
    public function testCreatedCustomUrlAliasIsLoadable()
2108
    {
2109
        $handler = $this->getHandler();
2110
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2111
2112
        $path = 'custom-location-alias';
2113
        $customUrlAlias = $handler->createCustomUrlAlias(
2114
            314,
2115
            $path,
2116
            false,
2117
            'cro-HR',
2118
            false
2119
        );
2120
        $loadedCustomUrlAlias = $handler->lookup($path);
2121
2122
        self::assertEquals(4, $this->countRows());
2123
2124
        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...
2125
            if ($propertyName === 'pathData') {
2126
                self::assertEquals(
2127
                    [
2128
                        [
2129
                            'always-available' => false,
2130
                            'translations' => ['cro-HR' => $path],
2131
                        ],
2132
                    ],
2133
                    $loadedCustomUrlAlias->$propertyName
2134
                );
2135
            } else {
2136
                self::assertEquals(
2137
                    $customUrlAlias->$propertyName,
2138
                    $loadedCustomUrlAlias->$propertyName
2139
                );
2140
            }
2141
        }
2142
    }
2143
2144
    /**
2145
     * Test for the createUrlAlias() method.
2146
     *
2147
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2148
     * @group create
2149
     * @group custom
2150
     */
2151
    public function testCreateCustomUrlAliasWithNopElement()
2152
    {
2153
        $handler = $this->getHandler();
2154
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2155
2156
        $path = 'ribar/palunko';
2157
        $customUrlAlias = $handler->createCustomUrlAlias(
2158
            314,
2159
            $path,
2160
            false,
2161
            'cro-HR',
2162
            true
2163
        );
2164
2165
        self::assertEquals(5, $this->countRows());
2166
        self::assertEquals(
2167
            new UrlAlias(
2168
                [
2169
                    'id' => '4-' . md5('palunko'),
2170
                    'type' => UrlAlias::LOCATION,
2171
                    'destination' => 314,
2172
                    'pathData' => [
2173
                        [
2174
                            'always-available' => true,
2175
                            'translations' => [
2176
                                'always-available' => 'ribar',
2177
                            ],
2178
                        ],
2179
                        [
2180
                            'always-available' => true,
2181
                            'translations' => [
2182
                                'cro-HR' => 'palunko',
2183
                            ],
2184
                        ],
2185
                    ],
2186
                    'languageCodes' => ['cro-HR'],
2187
                    'alwaysAvailable' => true,
2188
                    'isHistory' => false,
2189
                    'isCustom' => true,
2190
                    'forward' => false,
2191
                ]
2192
            ),
2193
            $customUrlAlias
2194
        );
2195
2196
        return $handler;
2197
    }
2198
2199
    /**
2200
     * Test for the createUrlAlias() method.
2201
     *
2202
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2203
     * @depends testCreateCustomUrlAliasWithNopElement
2204
     * @group create
2205
     * @group custom
2206
     */
2207
    public function testCreateUrlAliasWithNopElementCreatesValidNopElement(Handler $handler)
2208
    {
2209
        $url = 'ribar';
2210
        $urlAlias = $handler->lookup($url);
2211
2212
        $this->assertVirtualUrlAliasValid(
2213
            $urlAlias,
2214
            '0-' . md5($url)
2215
        );
2216
    }
2217
2218
    /**
2219
     * Test for the createUrlAlias() method.
2220
     *
2221
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2222
     * @group create
2223
     * @group custom
2224
     */
2225 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistory()
2226
    {
2227
        $handler = $this->getHandler();
2228
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2229
2230
        $countBeforeReusing = $this->countRows();
2231
        $handler->createCustomUrlAlias(
2232
            314,
2233
            'history-hello',
2234
            true,
2235
            'eng-GB',
2236
            true
2237
        );
2238
2239
        self::assertEquals(
2240
            $countBeforeReusing,
2241
            $this->countRows()
2242
        );
2243
        self::assertEquals(
2244
            new UrlAlias(
2245
                [
2246
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2247
                    'type' => UrlAlias::LOCATION,
2248
                    'destination' => 314,
2249
                    'languageCodes' => ['eng-GB'],
2250
                    'pathData' => [
2251
                        [
2252
                            'always-available' => true,
2253
                            'translations' => ['eng-GB' => 'history-hello'],
2254
                        ],
2255
                    ],
2256
                    'alwaysAvailable' => true,
2257
                    'isHistory' => false,
2258
                    'isCustom' => true,
2259
                    'forward' => true,
2260
                ]
2261
            ),
2262
            $handler->lookup('history-hello')
2263
        );
2264
    }
2265
2266
    /**
2267
     * Test for the createUrlAlias() method.
2268
     *
2269
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2270
     * @group create
2271
     * @group custom
2272
     */
2273
    public function testCreateCustomUrlAliasAddLanguage()
2274
    {
2275
        $handler = $this->getHandler();
2276
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2277
2278
        $countBeforeReusing = $this->countRows();
2279
        $handler->createCustomUrlAlias(
2280
            314,
2281
            'path314',
2282
            false,
2283
            'eng-GB',
2284
            true
2285
        );
2286
2287
        self::assertEquals(
2288
            $countBeforeReusing,
2289
            $this->countRows()
2290
        );
2291
        self::assertEquals(
2292
            new UrlAlias(
2293
                [
2294
                    'id' => '0-fdbbfa1e24e78ef56cb16ba4482c7771',
2295
                    'type' => UrlAlias::LOCATION,
2296
                    'destination' => '314',
2297
                    'languageCodes' => ['cro-HR', 'eng-GB'],
2298
                    'pathData' => [
2299
                        [
2300
                            'always-available' => true,
2301
                            'translations' => [
2302
                                'cro-HR' => 'path314',
2303
                                'eng-GB' => 'path314',
2304
                            ],
2305
                        ],
2306
                    ],
2307
                    'alwaysAvailable' => true,
2308
                    'isHistory' => false,
2309
                    'isCustom' => true,
2310
                    'forward' => false,
2311
                ]
2312
            ),
2313
            $handler->lookup('path314')
2314
        );
2315
    }
2316
2317
    /**
2318
     * Test for the createUrlAlias() method.
2319
     *
2320
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2321
     * @group create
2322
     * @group custom
2323
     */
2324 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistoryOfDifferentLanguage()
2325
    {
2326
        $handler = $this->getHandler();
2327
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2328
2329
        $countBeforeReusing = $this->countRows();
2330
        $handler->createCustomUrlAlias(
2331
            314,
2332
            'history-hello',
2333
            true,
2334
            'cro-HR',
2335
            true
2336
        );
2337
2338
        self::assertEquals(
2339
            $countBeforeReusing,
2340
            $this->countRows()
2341
        );
2342
        self::assertEquals(
2343
            new UrlAlias(
2344
                [
2345
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2346
                    'type' => UrlAlias::LOCATION,
2347
                    'destination' => 314,
2348
                    'languageCodes' => ['cro-HR'],
2349
                    'pathData' => [
2350
                        [
2351
                            'always-available' => true,
2352
                            'translations' => ['cro-HR' => 'history-hello'],
2353
                        ],
2354
                    ],
2355
                    'alwaysAvailable' => true,
2356
                    'isHistory' => false,
2357
                    'isCustom' => true,
2358
                    'forward' => true,
2359
                ]
2360
            ),
2361
            $handler->lookup('history-hello')
2362
        );
2363
    }
2364
2365
    /**
2366
     * Test for the createUrlAlias() method.
2367
     *
2368
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2369
     * @group create
2370
     * @group custom
2371
     */
2372
    public function testCreateCustomUrlAliasReusesNopElement()
2373
    {
2374
        $handler = $this->getHandler();
2375
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2376
2377
        $countBeforeReusing = $this->countRows();
2378
        $handler->createCustomUrlAlias(
2379
            314,
2380
            'nop-element',
2381
            true,
2382
            'cro-HR',
2383
            true
2384
        );
2385
2386
        self::assertEquals(
2387
            $countBeforeReusing,
2388
            $this->countRows()
2389
        );
2390
2391
        // Check that custom alias whose nop element was reused still works as expected
2392
        self::assertEquals(
2393
            new UrlAlias(
2394
                [
2395
                    'id' => '2-06a943c59f33a34bb5924aaf72cd2995',
2396
                    'type' => UrlAlias::RESOURCE,
2397
                    'destination' => 'content/search',
2398
                    'languageCodes' => ['eng-GB'],
2399
                    'pathData' => [
2400
                        [
2401
                            'always-available' => true,
2402
                            'translations' => ['cro-HR' => 'nop-element'],
2403
                        ],
2404
                        [
2405
                            'always-available' => false,
2406
                            'translations' => ['eng-GB' => 'search'],
2407
                        ],
2408
                    ],
2409
                    'alwaysAvailable' => false,
2410
                    'isHistory' => false,
2411
                    'isCustom' => true,
2412
                    'forward' => false,
2413
                ]
2414
            ),
2415
            $handler->lookup('nop-element/search')
2416
        );
2417
    }
2418
2419
    /**
2420
     * Test for the createUrlAlias() method.
2421
     *
2422
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2423
     * @group create
2424
     * @group custom
2425
     */
2426 View Code Duplication
    public function testCreateCustomUrlAliasReusesLocationElement()
2427
    {
2428
        $handler = $this->getHandler();
2429
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2430
2431
        $countBeforeReusing = $this->countRows();
2432
        $locationUrlAlias = $handler->lookup('autogenerated-hello');
2433
        $handler->createCustomUrlAlias(
2434
            315,
2435
            'autogenerated-hello/custom-location-alias-for-315',
2436
            true,
2437
            'cro-HR',
2438
            true
2439
        );
2440
2441
        self::assertEquals(
2442
            $countBeforeReusing + 1,
2443
            $this->countRows()
2444
        );
2445
2446
        // Check that location alias still works as expected
2447
        self::assertEquals(
2448
            $locationUrlAlias,
2449
            $handler->lookup('autogenerated-hello')
2450
        );
2451
    }
2452
2453
    /**
2454
     * Test for the listGlobalURLAliases() method.
2455
     *
2456
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2457
     * @depends testLookupResourceUrlAlias
2458
     */
2459
    public function testListGlobalURLAliases()
2460
    {
2461
        $handler = $this->getHandler();
2462
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2463
2464
        $globalAliasList = $handler->listGlobalURLAliases();
2465
2466
        self::assertEquals(
2467
            [
2468
                $handler->lookup('is-alive'),
2469
                $handler->lookup('is-alive/then/search'),
2470
                $handler->lookup('nop-element/search'),
2471
            ],
2472
            $globalAliasList
2473
        );
2474
    }
2475
2476
    /**
2477
     * Test for the listGlobalURLAliases() method.
2478
     *
2479
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2480
     * @depends testLookupResourceUrlAlias
2481
     */
2482 View Code Duplication
    public function testListGlobalURLAliasesWithLanguageCode()
2483
    {
2484
        $handler = $this->getHandler();
2485
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2486
2487
        $globalAliasList = $handler->listGlobalURLAliases('eng-GB');
2488
2489
        self::assertEquals(
2490
            [
2491
                $handler->lookup('is-alive'),
2492
                $handler->lookup('nop-element/search'),
2493
            ],
2494
            $globalAliasList
2495
        );
2496
    }
2497
2498
    /**
2499
     * Test for the listGlobalURLAliases() method.
2500
     *
2501
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2502
     * @depends testLookupResourceUrlAlias
2503
     */
2504
    public function testListGlobalURLAliasesWithOffset()
2505
    {
2506
        $handler = $this->getHandler();
2507
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2508
2509
        $globalAliasList = $handler->listGlobalURLAliases(null, 2);
2510
2511
        self::assertEquals(
2512
            [
2513
                $handler->lookup('nop-element/search'),
2514
            ],
2515
            $globalAliasList
2516
        );
2517
    }
2518
2519
    /**
2520
     * Test for the listGlobalURLAliases() method.
2521
     *
2522
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2523
     * @depends testLookupResourceUrlAlias
2524
     */
2525
    public function testListGlobalURLAliasesWithOffsetAndLimit()
2526
    {
2527
        $handler = $this->getHandler();
2528
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2529
2530
        $globalAliasList = $handler->listGlobalURLAliases(null, 1, 1);
2531
2532
        self::assertEquals(
2533
            [
2534
                $handler->lookup('is-alive/then/search'),
2535
            ],
2536
            $globalAliasList
2537
        );
2538
    }
2539
2540
    /**
2541
     * Test for the locationDeleted() method.
2542
     *
2543
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationDeleted
2544
     */
2545
    public function testLocationDeleted()
2546
    {
2547
        $handler = $this->getHandler();
2548
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_delete.php');
2549
2550
        $countBeforeDeleting = $this->countRows();
2551
2552
        $handler->locationDeleted(5);
2553
2554
        self::assertEquals(
2555
            $countBeforeDeleting - 5,
2556
            $this->countRows()
2557
        );
2558
2559
        self::assertEmpty(
2560
            $handler->listURLAliasesForLocation(5)
2561
        );
2562
2563
        $removedAliases = [
2564
            'moved-original-parent/moved-history',
2565
            'moved-original-parent/sub',
2566
            'moved-original-parent',
2567
            'moved-original-parent-history',
2568
            'custom-below/moved-original-parent-custom',
2569
        ];
2570
        foreach ($removedAliases as $path) {
2571
            try {
2572
                $handler->lookup($path);
2573
                $this->fail("Alias '$path' not removed!");
2574
            } catch (NotFoundException $e) {
2575
                // Do nothing
2576
            }
2577
        }
2578
    }
2579
2580
    /**
2581
     * Test for the locationMoved() method.
2582
     *
2583
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2584
     */
2585 View Code Duplication
    public function testLocationMovedHistorize()
2586
    {
2587
        $handler = $this->getHandler();
2588
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2589
2590
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2591
        $handler->locationMoved(4, 2, 3);
2592
2593
        $urlAlias = $handler->lookup('move-this');
2594
        self::assertEquals(
2595
            new UrlAlias(
2596
                [
2597
                    'id' => '0-' . md5('move-this'),
2598
                    'type' => UrlAlias::LOCATION,
2599
                    'destination' => '4',
2600
                    'languageCodes' => ['eng-GB'],
2601
                    'pathData' => [
2602
                        [
2603
                            'always-available' => false,
2604
                            'translations' => ['eng-GB' => 'move-this'],
2605
                        ],
2606
                    ],
2607
                    'alwaysAvailable' => false,
2608
                    'isHistory' => true,
2609
                    'isCustom' => false,
2610
                    'forward' => false,
2611
                ]
2612
            ),
2613
            $urlAlias
2614
        );
2615
    }
2616
2617
    /**
2618
     * Test for the locationMoved() method.
2619
     *
2620
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2621
     */
2622 View Code Duplication
    public function testLocationMovedHistory()
2623
    {
2624
        $handler = $this->getHandler();
2625
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2626
2627
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2628
        $handler->locationMoved(4, 2, 3);
2629
2630
        $urlAlias = $handler->lookup('move-this-history');
2631
        self::assertEquals(
2632
            new UrlAlias(
2633
                [
2634
                    'id' => '0-' . md5('move-this-history'),
2635
                    'type' => UrlAlias::LOCATION,
2636
                    'destination' => '4',
2637
                    'languageCodes' => ['eng-GB'],
2638
                    'pathData' => [
2639
                        [
2640
                            'always-available' => false,
2641
                            'translations' => ['eng-GB' => 'move-this-history'],
2642
                        ],
2643
                    ],
2644
                    'alwaysAvailable' => false,
2645
                    'isHistory' => true,
2646
                    'isCustom' => false,
2647
                    'forward' => false,
2648
                ]
2649
            ),
2650
            $urlAlias
2651
        );
2652
    }
2653
2654
    /**
2655
     * Test for the locationMoved() method.
2656
     *
2657
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2658
     */
2659 View Code Duplication
    public function testLocationMovedHistorySubtree()
2660
    {
2661
        $handler = $this->getHandler();
2662
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2663
2664
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2665
        $handler->locationMoved(4, 2, 3);
2666
2667
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2668
        self::assertEquals(
2669
            new UrlAlias(
2670
                [
2671
                    'id' => '5-' . md5('sub2'),
2672
                    'type' => UrlAlias::LOCATION,
2673
                    'destination' => '6',
2674
                    'languageCodes' => ['eng-GB'],
2675
                    'pathData' => [
2676
                        [
2677
                            'always-available' => false,
2678
                            'translations' => ['eng-GB' => 'move-this'],
2679
                        ],
2680
                        [
2681
                            'always-available' => false,
2682
                            'translations' => ['eng-GB' => 'sub1'],
2683
                        ],
2684
                        [
2685
                            'always-available' => false,
2686
                            'translations' => ['eng-GB' => 'sub2'],
2687
                        ],
2688
                    ],
2689
                    'alwaysAvailable' => false,
2690
                    'isHistory' => true,
2691
                    'isCustom' => false,
2692
                    'forward' => false,
2693
                ]
2694
            ),
2695
            $urlAlias
2696
        );
2697
    }
2698
2699
    /**
2700
     * Test for the locationMoved() method.
2701
     *
2702
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2703
     */
2704 View Code Duplication
    public function testLocationMovedReparent()
2705
    {
2706
        $handler = $this->getHandler();
2707
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2708
2709
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2710
        $handler->locationMoved(4, 2, 3);
2711
2712
        $urlAlias = $handler->lookup('move-here/move-this/sub1');
2713
        self::assertEquals(
2714
            new UrlAlias(
2715
                [
2716
                    'id' => '9-' . md5('sub1'),
2717
                    'type' => UrlAlias::LOCATION,
2718
                    'destination' => '5',
2719
                    'languageCodes' => ['eng-GB'],
2720
                    'pathData' => [
2721
                        [
2722
                            'always-available' => false,
2723
                            'translations' => ['eng-GB' => 'move-here'],
2724
                        ],
2725
                        [
2726
                            'always-available' => false,
2727
                            'translations' => ['eng-GB' => 'move-this'],
2728
                        ],
2729
                        [
2730
                            'always-available' => false,
2731
                            'translations' => ['eng-GB' => 'sub1'],
2732
                        ],
2733
                    ],
2734
                    'alwaysAvailable' => false,
2735
                    'isHistory' => false,
2736
                    'isCustom' => false,
2737
                    'forward' => false,
2738
                ]
2739
            ),
2740
            $urlAlias
2741
        );
2742
    }
2743
2744
    /**
2745
     * Test for the locationMoved() method.
2746
     *
2747
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2748
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2749
     */
2750 View Code Duplication
    public function testLocationMovedReparentHistory()
2751
    {
2752
        $handler = $this->getHandler();
2753
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2754
2755
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2756
        $handler->locationMoved(4, 2, 3);
2757
2758
        $handler->lookup('move-here/move-this-history');
2759
    }
2760
2761
    /**
2762
     * Test for the locationMoved() method.
2763
     *
2764
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2765
     */
2766 View Code Duplication
    public function testLocationMovedReparentSubtree()
2767
    {
2768
        $handler = $this->getHandler();
2769
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2770
2771
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2772
        $handler->locationMoved(4, 2, 3);
2773
2774
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2775
        self::assertEquals(
2776
            new UrlAlias(
2777
                [
2778
                    'id' => '5-' . md5('sub2'),
2779
                    'type' => UrlAlias::LOCATION,
2780
                    'destination' => '6',
2781
                    'languageCodes' => ['eng-GB'],
2782
                    'pathData' => [
2783
                        [
2784
                            'always-available' => false,
2785
                            'translations' => ['eng-GB' => 'move-here'],
2786
                        ],
2787
                        [
2788
                            'always-available' => false,
2789
                            'translations' => ['eng-GB' => 'move-this'],
2790
                        ],
2791
                        [
2792
                            'always-available' => false,
2793
                            'translations' => ['eng-GB' => 'sub1'],
2794
                        ],
2795
                        [
2796
                            'always-available' => false,
2797
                            'translations' => ['eng-GB' => 'sub2'],
2798
                        ],
2799
                    ],
2800
                    'alwaysAvailable' => false,
2801
                    'isHistory' => false,
2802
                    'isCustom' => false,
2803
                    'forward' => false,
2804
                ]
2805
            ),
2806
            $urlAlias
2807
        );
2808
    }
2809
2810
    /**
2811
     * Test for the locationMoved() method.
2812
     *
2813
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2814
     */
2815 View Code Duplication
    public function testLocationMovedReparentSubtreeHistory()
2816
    {
2817
        $handler = $this->getHandler();
2818
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2819
2820
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2821
        $handler->locationMoved(4, 2, 3);
2822
2823
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2-history');
2824
        self::assertEquals(
2825
            new UrlAlias(
2826
                [
2827
                    'id' => '5-' . md5('sub2-history'),
2828
                    'type' => UrlAlias::LOCATION,
2829
                    'destination' => '6',
2830
                    'languageCodes' => ['eng-GB'],
2831
                    'pathData' => [
2832
                        [
2833
                            'always-available' => false,
2834
                            'translations' => ['eng-GB' => 'move-here'],
2835
                        ],
2836
                        [
2837
                            'always-available' => false,
2838
                            'translations' => ['eng-GB' => 'move-this'],
2839
                        ],
2840
                        [
2841
                            'always-available' => false,
2842
                            'translations' => ['eng-GB' => 'sub1'],
2843
                        ],
2844
                        [
2845
                            'always-available' => false,
2846
                            'translations' => ['eng-GB' => 'sub2-history'],
2847
                        ],
2848
                    ],
2849
                    'alwaysAvailable' => false,
2850
                    'isHistory' => true,
2851
                    'isCustom' => false,
2852
                    'forward' => false,
2853
                ]
2854
            ),
2855
            $urlAlias
2856
        );
2857
    }
2858
2859
    /**
2860
     * Test for the locationCopied() method.
2861
     *
2862
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2863
     */
2864 View Code Duplication
    public function testLocationCopiedCopiedLocationAliasIsValid()
2865
    {
2866
        $handler = $this->getHandler();
2867
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2868
2869
        $urlAlias = $handler->lookup('move-this');
2870
2871
        $handler->locationCopied(4, 400, 3);
2872
2873
        self::assertEquals(
2874
            $urlAlias,
2875
            $handler->lookup('move-this')
2876
        );
2877
    }
2878
2879
    /**
2880
     * Test for the locationCopied() method.
2881
     *
2882
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2883
     */
2884 View Code Duplication
    public function testLocationCopiedCopiedSubtreeIsValid()
2885
    {
2886
        $handler = $this->getHandler();
2887
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2888
2889
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2890
2891
        $handler->locationCopied(4, 400, 3);
2892
2893
        self::assertEquals(
2894
            $urlAlias,
2895
            $handler->lookup('move-this/sub1/sub2')
2896
        );
2897
    }
2898
2899
    /**
2900
     * Test for the locationCopied() method.
2901
     *
2902
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2903
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2904
     */
2905 View Code Duplication
    public function testLocationCopiedHistoryNotCopied()
2906
    {
2907
        $handler = $this->getHandler();
2908
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2909
2910
        $handler->locationCopied(4, 400, 3);
2911
2912
        $handler->lookup('move-here/move-this-history');
2913
    }
2914
2915
    /**
2916
     * Test for the locationCopied() method.
2917
     *
2918
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2919
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2920
     */
2921 View Code Duplication
    public function testLocationCopiedSubtreeHistoryNotCopied()
2922
    {
2923
        $handler = $this->getHandler();
2924
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2925
2926
        $handler->locationCopied(4, 400, 3);
2927
2928
        $handler->lookup('move-here/move-this/sub1/sub2-history');
2929
    }
2930
2931
    /**
2932
     * Test for the locationCopied() method.
2933
     *
2934
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2935
     */
2936
    public function testLocationCopiedSubtree()
2937
    {
2938
        $handler = $this->getHandler();
2939
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2940
2941
        $countBeforeCopying = $this->countRows();
2942
2943
        $handler->locationCopied(4, 400, 3);
2944
2945
        self::assertEquals(
2946
            $countBeforeCopying + 2,
2947
            $this->countRows()
2948
        );
2949
2950
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2951
        self::assertEquals(
2952
            new UrlAlias(
2953
                [
2954
                    'id' => '10-' . md5('sub2'),
2955
                    'type' => UrlAlias::LOCATION,
2956
                    'destination' => 600,
2957
                    'languageCodes' => ['eng-GB'],
2958
                    'pathData' => [
2959
                        [
2960
                            'always-available' => false,
2961
                            'translations' => ['eng-GB' => 'move-here'],
2962
                        ],
2963
                        [
2964
                            'always-available' => false,
2965
                            'translations' => ['eng-GB' => 'move-this'],
2966
                        ],
2967
                        [
2968
                            'always-available' => false,
2969
                            'translations' => ['eng-GB' => 'sub1'],
2970
                        ],
2971
                        [
2972
                            'always-available' => false,
2973
                            'translations' => ['eng-GB' => 'sub2'],
2974
                        ],
2975
                    ],
2976
                    'alwaysAvailable' => false,
2977
                    'isHistory' => false,
2978
                    'isCustom' => false,
2979
                    'forward' => false,
2980
                ]
2981
            ),
2982
            $urlAlias
2983
        );
2984
    }
2985
2986
    /**
2987
     * Test for the loadUrlAlias() method.
2988
     *
2989
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2990
     * @dataProvider providerForTestLookupLocationMultipleLanguages
2991
     */
2992 View Code Duplication
    public function testLoadAutogeneratedUrlAlias(
2993
        $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...
2994
        array $pathData,
2995
        array $languageCodes,
2996
        $alwaysAvailable,
2997
        $locationId,
2998
        $id
2999
    ) {
3000
        $handler = $this->getHandler();
3001
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
3002
3003
        $urlAlias = $handler->loadUrlAlias($id);
3004
3005
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
3006
        self::assertEquals(
3007
            new UrlAlias(
3008
                [
3009
                    'id' => $id,
3010
                    'type' => UrlAlias::LOCATION,
3011
                    'destination' => $locationId,
3012
                    'languageCodes' => $languageCodes,
3013
                    'pathData' => $pathData,
3014
                    'alwaysAvailable' => $alwaysAvailable,
3015
                    'isHistory' => false,
3016
                    'isCustom' => false,
3017
                    'forward' => false,
3018
                ]
3019
            ),
3020
            $urlAlias
3021
        );
3022
    }
3023
3024
    /**
3025
     * Test for the loadUrlAlias() method.
3026
     *
3027
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3028
     * @dataProvider providerForTestLookupResourceUrlAlias
3029
     */
3030 View Code Duplication
    public function testLoadResourceUrlAlias(
3031
        $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...
3032
        $pathData,
3033
        array $languageCodes,
3034
        $forward,
3035
        $alwaysAvailable,
3036
        $destination,
3037
        $id
3038
    ) {
3039
        $handler = $this->getHandler();
3040
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
3041
3042
        $urlAlias = $handler->loadUrlAlias($id);
3043
3044
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
3045
        self::assertEquals(
3046
            new UrlAlias(
3047
                [
3048
                    'id' => $id,
3049
                    'type' => UrlAlias::RESOURCE,
3050
                    'destination' => $destination,
3051
                    'languageCodes' => $languageCodes,
3052
                    'pathData' => $pathData,
3053
                    'alwaysAvailable' => $alwaysAvailable,
3054
                    'isHistory' => false,
3055
                    'isCustom' => true,
3056
                    'forward' => $forward,
3057
                ]
3058
            ),
3059
            $urlAlias
3060
        );
3061
    }
3062
3063
    /**
3064
     * Test for the loadUrlAlias() method.
3065
     *
3066
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3067
     * @dataProvider providerForTestLookupVirtualUrlAlias
3068
     */
3069 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...
3070
    {
3071
        $handler = $this->getHandler();
3072
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
3073
3074
        $urlAlias = $handler->loadUrlAlias($id);
3075
3076
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
3077
    }
3078
3079
    protected function getHistoryAlias()
3080
    {
3081
        return new UrlAlias(
3082
            [
3083
                'id' => '3-5f46413bb0ba5998caef84ab1ea590e1',
3084
                'type' => UrlAlias::LOCATION,
3085
                'destination' => '316',
3086
                'pathData' => [
3087
                    [
3088
                        'always-available' => true,
3089
                        'translations' => ['cro-HR' => 'jedan'],
3090
                    ],
3091
                    [
3092
                        'always-available' => false,
3093
                        'translations' => [
3094
                            'cro-HR' => 'dva',
3095
                            'eng-GB' => 'two',
3096
                        ],
3097
                    ],
3098
                    [
3099
                        'always-available' => false,
3100
                        'translations' => [
3101
                            'cro-HR' => 'tri-history',
3102
                        ],
3103
                    ],
3104
                ],
3105
                'languageCodes' => ['cro-HR'],
3106
                'alwaysAvailable' => false,
3107
                'isHistory' => true,
3108
                'isCustom' => false,
3109
                'forward' => false,
3110
            ]
3111
        );
3112
    }
3113
3114
    /**
3115
     * Test for the loadUrlAlias() method.
3116
     *
3117
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3118
     */
3119
    public function testLoadHistoryUrlAlias()
3120
    {
3121
        $handler = $this->getHandler();
3122
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
3123
3124
        $historyAlias = $this->getHistoryAlias();
3125
        $urlAlias = $handler->loadUrlAlias($historyAlias->id);
3126
3127
        self::assertEquals(
3128
            $historyAlias,
3129
            $urlAlias
3130
        );
3131
    }
3132
3133
    /**
3134
     * Test for the loadUrlAlias() method.
3135
     *
3136
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3137
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3138
     */
3139
    public function testLoadUrlAliasThrowsNotFoundException()
3140
    {
3141
        $handler = $this->getHandler();
3142
3143
        $handler->loadUrlAlias('non-existent');
3144
    }
3145
3146
    public function providerForTestPublishUrlAliasForLocationSkipsReservedWord()
3147
    {
3148
        return [
3149
            [
3150
                'section',
3151
                'section2',
3152
            ],
3153
            [
3154
                'claß',
3155
                'class2',
3156
            ],
3157
        ];
3158
    }
3159
3160
    /**
3161
     * Test for the publishUrlAliasForLocation() method.
3162
     *
3163
     * @dataProvider providerForTestPublishUrlAliasForLocationSkipsReservedWord
3164
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
3165
     * @group publish
3166
     */
3167
    public function testPublishUrlAliasForLocationSkipsReservedWord($text, $alias)
3168
    {
3169
        $handler = $this->getHandler();
3170
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
3171
3172
        $handler->publishUrlAliasForLocation(314, 2, $text, 'kli-KR');
3173
3174
        $urlAlias = $handler->lookup($alias);
3175
3176
        $this->assertEquals(314, $urlAlias->destination);
3177
        $this->assertEquals(['kli-KR'], $urlAlias->languageCodes);
3178
    }
3179
3180
    /**
3181
     * Test for the locationSwapped() method.
3182
     *
3183
     * @group swap
3184
     */
3185
    public function testLocationSwappedSimple()
3186
    {
3187
        $handler = $this->getHandler();
3188
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple.php');
3189
3190
        $countBeforeReusing = $this->countRows();
3191
3192
        $handler->locationSwapped(316, 314, 317, 315);
3193
3194
        $this->assertEquals(
3195
            $countBeforeReusing,
3196
            $this->countRows()
3197
        );
3198
3199
        $urlAlias = $handler->lookup('jedan/swap');
3200
        $this->assertEquals(
3201
            new UrlAlias(
3202
                [
3203
                    'id' => '2-' . md5('swap'),
3204
                    'type' => UrlAlias::LOCATION,
3205
                    'destination' => 316,
3206
                    'languageCodes' => [
3207
                        'cro-HR',
3208
                    ],
3209
                    'pathData' => [
3210
                        [
3211
                            'always-available' => false,
3212
                            'translations' => [
3213
                                'cro-HR' => 'jedan',
3214
                            ],
3215
                        ],
3216
                        [
3217
                            'always-available' => false,
3218
                            'translations' => [
3219
                                'cro-HR' => 'swap',
3220
                            ],
3221
                        ],
3222
                    ],
3223
                    'alwaysAvailable' => false,
3224
                    'isHistory' => false,
3225
                    'isCustom' => false,
3226
                    'forward' => false,
3227
                ]
3228
            ),
3229
            $urlAlias
3230
        );
3231
3232
        $urlAlias = $handler->lookup('dva/swap');
3233
        $this->assertEquals(
3234
            new UrlAlias(
3235
                [
3236
                    'id' => '3-' . md5('swap'),
3237
                    'type' => UrlAlias::LOCATION,
3238
                    'destination' => 317,
3239
                    'languageCodes' => [
3240
                        'cro-HR',
3241
                    ],
3242
                    'pathData' => [
3243
                        [
3244
                            'always-available' => false,
3245
                            'translations' => [
3246
                                'cro-HR' => 'dva',
3247
                            ],
3248
                        ],
3249
                        [
3250
                            'always-available' => false,
3251
                            'translations' => [
3252
                                'cro-HR' => 'swap',
3253
                            ],
3254
                        ],
3255
                    ],
3256
                    'alwaysAvailable' => false,
3257
                    'isHistory' => false,
3258
                    'isCustom' => false,
3259
                    'forward' => false,
3260
                ]
3261
            ),
3262
            $urlAlias
3263
        );
3264
    }
3265
3266
    /**
3267
     * Test for the locationSwapped() method.
3268
     *
3269
     * @group swap
3270
     */
3271 View Code Duplication
    public function testLocationSwappedSimpleWithHistory()
3272
    {
3273
        $handler = $this->getHandler();
3274
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_history.php');
3275
3276
        $countBeforeReusing = $this->countRows();
3277
3278
        $handler->locationSwapped(316, 314, 317, 315);
3279
3280
        $this->assertEquals(
3281
            $countBeforeReusing,
3282
            $this->countRows()
3283
        );
3284
3285
        $urlAlias = $handler->lookup('jedan/swap');
3286
        $this->assertEquals(
3287
            new UrlAlias(
3288
                [
3289
                    'id' => '2-' . md5('swap'),
3290
                    'type' => UrlAlias::LOCATION,
3291
                    'destination' => 316,
3292
                    'languageCodes' => [
3293
                        'cro-HR',
3294
                    ],
3295
                    'pathData' => [
3296
                        [
3297
                            'always-available' => false,
3298
                            'translations' => [
3299
                                'cro-HR' => 'jedan',
3300
                            ],
3301
                        ],
3302
                        [
3303
                            'always-available' => false,
3304
                            'translations' => [
3305
                                'cro-HR' => 'swap',
3306
                            ],
3307
                        ],
3308
                    ],
3309
                    'alwaysAvailable' => false,
3310
                    'isHistory' => true,
3311
                    'isCustom' => false,
3312
                    'forward' => false,
3313
                ]
3314
            ),
3315
            $urlAlias
3316
        );
3317
3318
        $urlAlias = $handler->lookup('dva/swap');
3319
        $this->assertEquals(
3320
            new UrlAlias(
3321
                [
3322
                    'id' => '3-' . md5('swap'),
3323
                    'type' => UrlAlias::LOCATION,
3324
                    'destination' => 317,
3325
                    'languageCodes' => [
3326
                        'cro-HR',
3327
                    ],
3328
                    'pathData' => [
3329
                        [
3330
                            'always-available' => false,
3331
                            'translations' => [
3332
                                'cro-HR' => 'dva',
3333
                            ],
3334
                        ],
3335
                        [
3336
                            'always-available' => false,
3337
                            'translations' => [
3338
                                'cro-HR' => 'swap',
3339
                            ],
3340
                        ],
3341
                    ],
3342
                    'alwaysAvailable' => false,
3343
                    'isHistory' => true,
3344
                    'isCustom' => false,
3345
                    'forward' => false,
3346
                ]
3347
            ),
3348
            $urlAlias
3349
        );
3350
3351
        $urlAlias = $handler->lookup('jedan/swap-new');
3352
        $this->assertEquals(
3353
            new UrlAlias(
3354
                [
3355
                    'id' => '2-' . md5('swap-new'),
3356
                    'type' => UrlAlias::LOCATION,
3357
                    'destination' => 316,
3358
                    'languageCodes' => [
3359
                        'cro-HR',
3360
                    ],
3361
                    'pathData' => [
3362
                        [
3363
                            'always-available' => false,
3364
                            'translations' => [
3365
                                'cro-HR' => 'jedan',
3366
                            ],
3367
                        ],
3368
                        [
3369
                            'always-available' => false,
3370
                            'translations' => [
3371
                                'cro-HR' => 'swap-new',
3372
                            ],
3373
                        ],
3374
                    ],
3375
                    'alwaysAvailable' => false,
3376
                    'isHistory' => false,
3377
                    'isCustom' => false,
3378
                    'forward' => false,
3379
                ]
3380
            ),
3381
            $urlAlias
3382
        );
3383
3384
        $urlAlias = $handler->lookup('dva/swap-new');
3385
        $this->assertEquals(
3386
            new UrlAlias(
3387
                [
3388
                    'id' => '3-' . md5('swap-new'),
3389
                    'type' => UrlAlias::LOCATION,
3390
                    'destination' => 317,
3391
                    'languageCodes' => [
3392
                        'cro-HR',
3393
                    ],
3394
                    'pathData' => [
3395
                        [
3396
                            'always-available' => false,
3397
                            'translations' => [
3398
                                'cro-HR' => 'dva',
3399
                            ],
3400
                        ],
3401
                        [
3402
                            'always-available' => false,
3403
                            'translations' => [
3404
                                'cro-HR' => 'swap-new',
3405
                            ],
3406
                        ],
3407
                    ],
3408
                    'alwaysAvailable' => false,
3409
                    'isHistory' => false,
3410
                    'isCustom' => false,
3411
                    'forward' => false,
3412
                ]
3413
            ),
3414
            $urlAlias
3415
        );
3416
    }
3417
3418
    /**
3419
     * Test for the locationSwapped() method.
3420
     *
3421
     * @group swap
3422
     */
3423
    public function testLocationSwappedSimpleWithConflict()
3424
    {
3425
        $handler = $this->getHandler();
3426
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_conflict.php');
3427
3428
        $urlAlias1TakenExpected = $handler->lookup('jedan/swap-new-2');
3429
        $urlAlias2TakenExpected = $handler->lookup('dva/swap-new-1');
3430
3431
        $urlAlias1HistorizedExpected = $handler->lookup('jedan/swap-new-1');
3432
        $urlAlias1HistorizedExpected->isHistory = true;
3433
        $urlAlias2HistorizedExpected = $handler->lookup('dva/swap-new-2');
3434
        $urlAlias2HistorizedExpected->isHistory = true;
3435
3436
        $countBeforeReusing = $this->countRows();
3437
3438
        $handler->locationSwapped(316, 314, 317, 315);
3439
3440
        $this->assertEquals(
3441
            $countBeforeReusing + 2,
3442
            $this->countRows()
3443
        );
3444
3445
        $urlAlias1Taken = $handler->lookup('jedan/swap-new-2');
3446
        $urlAlias2Taken = $handler->lookup('dva/swap-new-1');
3447
3448
        $urlAlias1Historized = $handler->lookup('jedan/swap-new-1');
3449
        $urlAlias2Historized = $handler->lookup('dva/swap-new-2');
3450
3451
        $this->assertEquals($urlAlias1TakenExpected, $urlAlias1Taken);
3452
        $this->assertEquals($urlAlias2TakenExpected, $urlAlias2Taken);
3453
3454
        $this->assertEquals($urlAlias1HistorizedExpected, $urlAlias1Historized);
3455
        $this->assertEquals($urlAlias2HistorizedExpected, $urlAlias2Historized);
3456
3457
        $urlAlias1New = $handler->lookup('jedan/swap-new-22');
3458
        $this->assertEquals(
3459
            new UrlAlias(
3460
                [
3461
                    'id' => '2-' . md5('swap-new-22'),
3462
                    'type' => UrlAlias::LOCATION,
3463
                    'destination' => 316,
3464
                    'languageCodes' => [
3465
                        'cro-HR',
3466
                    ],
3467
                    'pathData' => [
3468
                        [
3469
                            'always-available' => false,
3470
                            'translations' => [
3471
                                'cro-HR' => 'jedan',
3472
                            ],
3473
                        ],
3474
                        [
3475
                            'always-available' => false,
3476
                            'translations' => [
3477
                                'cro-HR' => 'swap-new-22',
3478
                            ],
3479
                        ],
3480
                    ],
3481
                    'alwaysAvailable' => false,
3482
                    'isHistory' => false,
3483
                    'isCustom' => false,
3484
                    'forward' => false,
3485
                ]
3486
            ),
3487
            $urlAlias1New
3488
        );
3489
3490
        $urlAlias2New = $handler->lookup('dva/swap-new-12');
3491
        $this->assertEquals(
3492
            new UrlAlias(
3493
                [
3494
                    'id' => '3-' . md5('swap-new-12'),
3495
                    'type' => UrlAlias::LOCATION,
3496
                    'destination' => 317,
3497
                    'languageCodes' => [
3498
                        'cro-HR',
3499
                    ],
3500
                    'pathData' => [
3501
                        [
3502
                            'always-available' => false,
3503
                            'translations' => [
3504
                                'cro-HR' => 'dva',
3505
                            ],
3506
                        ],
3507
                        [
3508
                            'always-available' => false,
3509
                            'translations' => [
3510
                                'cro-HR' => 'swap-new-12',
3511
                            ],
3512
                        ],
3513
                    ],
3514
                    'alwaysAvailable' => false,
3515
                    'isHistory' => false,
3516
                    'isCustom' => false,
3517
                    'forward' => false,
3518
                ]
3519
            ),
3520
            $urlAlias2New
3521
        );
3522
    }
3523
3524
    /**
3525
     * Test for the locationSwapped() method.
3526
     *
3527
     * @group swap
3528
     */
3529 View Code Duplication
    public function testLocationSwappedSiblingsSimple()
3530
    {
3531
        $handler = $this->getHandler();
3532
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3533
3534
        $countBeforeReusing = $this->countRows();
3535
3536
        $handler->locationSwapped(314, 2, 315, 2);
3537
3538
        $this->assertEquals(
3539
            $countBeforeReusing,
3540
            $this->countRows()
3541
        );
3542
3543
        $urlAlias = $handler->lookup('jedan');
3544
        $this->assertEquals(
3545
            new UrlAlias(
3546
                [
3547
                    'id' => '0-' . md5('jedan'),
3548
                    'type' => UrlAlias::LOCATION,
3549
                    'destination' => 315,
3550
                    'languageCodes' => [
3551
                        'cro-HR',
3552
                    ],
3553
                    'pathData' => [
3554
                        [
3555
                            'always-available' => false,
3556
                            'translations' => [
3557
                                'cro-HR' => 'jedan',
3558
                            ],
3559
                        ],
3560
                    ],
3561
                    'alwaysAvailable' => false,
3562
                    'isHistory' => false,
3563
                    'isCustom' => false,
3564
                    'forward' => false,
3565
                ]
3566
            ),
3567
            $urlAlias
3568
        );
3569
3570
        $urlAlias = $handler->lookup('dva');
3571
        $this->assertEquals(
3572
            new UrlAlias(
3573
                [
3574
                    'id' => '0-' . md5('dva'),
3575
                    'type' => UrlAlias::LOCATION,
3576
                    'destination' => 314,
3577
                    'languageCodes' => [
3578
                        'cro-HR',
3579
                    ],
3580
                    'pathData' => [
3581
                        [
3582
                            'always-available' => false,
3583
                            'translations' => [
3584
                                'cro-HR' => 'dva',
3585
                            ],
3586
                        ],
3587
                    ],
3588
                    'alwaysAvailable' => false,
3589
                    'isHistory' => false,
3590
                    'isCustom' => false,
3591
                    'forward' => false,
3592
                ]
3593
            ),
3594
            $urlAlias
3595
        );
3596
    }
3597
3598
    /**
3599
     * Test for the locationSwapped() method.
3600
     *
3601
     * @group swap
3602
     */
3603 View Code Duplication
    public function testLocationSwappedSiblingsSimpleReverse()
3604
    {
3605
        $handler = $this->getHandler();
3606
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3607
3608
        $countBeforeReusing = $this->countRows();
3609
3610
        $handler->locationSwapped(315, 2, 314, 2);
3611
3612
        $this->assertEquals(
3613
            $countBeforeReusing,
3614
            $this->countRows()
3615
        );
3616
3617
        $urlAlias = $handler->lookup('jedan');
3618
        $this->assertEquals(
3619
            new UrlAlias(
3620
                [
3621
                    'id' => '0-' . md5('jedan'),
3622
                    'type' => UrlAlias::LOCATION,
3623
                    'destination' => 315,
3624
                    'languageCodes' => [
3625
                        'cro-HR',
3626
                    ],
3627
                    'pathData' => [
3628
                        [
3629
                            'always-available' => false,
3630
                            'translations' => [
3631
                                'cro-HR' => 'jedan',
3632
                            ],
3633
                        ],
3634
                    ],
3635
                    'alwaysAvailable' => false,
3636
                    'isHistory' => false,
3637
                    'isCustom' => false,
3638
                    'forward' => false,
3639
                ]
3640
            ),
3641
            $urlAlias
3642
        );
3643
3644
        $urlAlias = $handler->lookup('dva');
3645
        $this->assertEquals(
3646
            new UrlAlias(
3647
                [
3648
                    'id' => '0-' . md5('dva'),
3649
                    'type' => UrlAlias::LOCATION,
3650
                    'destination' => 314,
3651
                    'languageCodes' => [
3652
                        'cro-HR',
3653
                    ],
3654
                    'pathData' => [
3655
                        [
3656
                            'always-available' => false,
3657
                            'translations' => [
3658
                                'cro-HR' => 'dva',
3659
                            ],
3660
                        ],
3661
                    ],
3662
                    'alwaysAvailable' => false,
3663
                    'isHistory' => false,
3664
                    'isCustom' => false,
3665
                    'forward' => false,
3666
                ]
3667
            ),
3668
            $urlAlias
3669
        );
3670
    }
3671
3672
    /**
3673
     * Test for the locationSwapped() method.
3674
     *
3675
     * @group swap
3676
     */
3677 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistory()
3678
    {
3679
        $handler = $this->getHandler();
3680
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3681
3682
        $countBeforeReusing = $this->countRows();
3683
3684
        $handler->locationSwapped(314, 2, 315, 2);
3685
3686
        $this->assertEquals(
3687
            $countBeforeReusing,
3688
            $this->countRows()
3689
        );
3690
3691
        $urlAlias = $handler->lookup('jedan');
3692
        $this->assertEquals(
3693
            new UrlAlias(
3694
                [
3695
                    'id' => '0-' . md5('jedan'),
3696
                    'type' => UrlAlias::LOCATION,
3697
                    'destination' => 314,
3698
                    'languageCodes' => [
3699
                        'cro-HR',
3700
                    ],
3701
                    'pathData' => [
3702
                        [
3703
                            'always-available' => false,
3704
                            'translations' => [
3705
                                'cro-HR' => 'jedan',
3706
                            ],
3707
                        ],
3708
                    ],
3709
                    'alwaysAvailable' => false,
3710
                    'isHistory' => true,
3711
                    'isCustom' => false,
3712
                    'forward' => false,
3713
                ]
3714
            ),
3715
            $urlAlias
3716
        );
3717
3718
        $urlAlias = $handler->lookup('dva');
3719
        $this->assertEquals(
3720
            new UrlAlias(
3721
                [
3722
                    'id' => '0-' . md5('dva'),
3723
                    'type' => UrlAlias::LOCATION,
3724
                    'destination' => 315,
3725
                    'languageCodes' => [
3726
                        'cro-HR',
3727
                    ],
3728
                    'pathData' => [
3729
                        [
3730
                            'always-available' => false,
3731
                            'translations' => [
3732
                                'cro-HR' => 'dva',
3733
                            ],
3734
                        ],
3735
                    ],
3736
                    'alwaysAvailable' => false,
3737
                    'isHistory' => true,
3738
                    'isCustom' => false,
3739
                    'forward' => false,
3740
                ]
3741
            ),
3742
            $urlAlias
3743
        );
3744
3745
        $urlAlias = $handler->lookup('jedan-new');
3746
        $this->assertEquals(
3747
            new UrlAlias(
3748
                [
3749
                    'id' => '0-' . md5('jedan-new'),
3750
                    'type' => UrlAlias::LOCATION,
3751
                    'destination' => 315,
3752
                    'languageCodes' => [
3753
                        'cro-HR',
3754
                    ],
3755
                    'pathData' => [
3756
                        [
3757
                            'always-available' => false,
3758
                            'translations' => [
3759
                                'cro-HR' => 'jedan-new',
3760
                            ],
3761
                        ],
3762
                    ],
3763
                    'alwaysAvailable' => false,
3764
                    'isHistory' => false,
3765
                    'isCustom' => false,
3766
                    'forward' => false,
3767
                ]
3768
            ),
3769
            $urlAlias
3770
        );
3771
3772
        $urlAlias = $handler->lookup('dva-new');
3773
        $this->assertEquals(
3774
            new UrlAlias(
3775
                [
3776
                    'id' => '0-' . md5('dva-new'),
3777
                    'type' => UrlAlias::LOCATION,
3778
                    'destination' => 314,
3779
                    'languageCodes' => [
3780
                        'cro-HR',
3781
                    ],
3782
                    'pathData' => [
3783
                        [
3784
                            'always-available' => false,
3785
                            'translations' => [
3786
                                'cro-HR' => 'dva-new',
3787
                            ],
3788
                        ],
3789
                    ],
3790
                    'alwaysAvailable' => false,
3791
                    'isHistory' => false,
3792
                    'isCustom' => false,
3793
                    'forward' => false,
3794
                ]
3795
            ),
3796
            $urlAlias
3797
        );
3798
    }
3799
3800
    /**
3801
     * Test for the locationSwapped() method.
3802
     *
3803
     * @group swap
3804
     */
3805 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistoryReverse()
3806
    {
3807
        $handler = $this->getHandler();
3808
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3809
3810
        $countBeforeReusing = $this->countRows();
3811
3812
        $handler->locationSwapped(315, 2, 314, 2);
3813
3814
        $this->assertEquals(
3815
            $countBeforeReusing,
3816
            $this->countRows()
3817
        );
3818
3819
        $urlAlias = $handler->lookup('jedan');
3820
        $this->assertEquals(
3821
            new UrlAlias(
3822
                [
3823
                    'id' => '0-' . md5('jedan'),
3824
                    'type' => UrlAlias::LOCATION,
3825
                    'destination' => 314,
3826
                    'languageCodes' => [
3827
                        'cro-HR',
3828
                    ],
3829
                    'pathData' => [
3830
                        [
3831
                            'always-available' => false,
3832
                            'translations' => [
3833
                                'cro-HR' => 'jedan',
3834
                            ],
3835
                        ],
3836
                    ],
3837
                    'alwaysAvailable' => false,
3838
                    'isHistory' => true,
3839
                    'isCustom' => false,
3840
                    'forward' => false,
3841
                ]
3842
            ),
3843
            $urlAlias
3844
        );
3845
3846
        $urlAlias = $handler->lookup('dva');
3847
        $this->assertEquals(
3848
            new UrlAlias(
3849
                [
3850
                    'id' => '0-' . md5('dva'),
3851
                    'type' => UrlAlias::LOCATION,
3852
                    'destination' => 315,
3853
                    'languageCodes' => [
3854
                        'cro-HR',
3855
                    ],
3856
                    'pathData' => [
3857
                        [
3858
                            'always-available' => false,
3859
                            'translations' => [
3860
                                'cro-HR' => 'dva',
3861
                            ],
3862
                        ],
3863
                    ],
3864
                    'alwaysAvailable' => false,
3865
                    'isHistory' => true,
3866
                    'isCustom' => false,
3867
                    'forward' => false,
3868
                ]
3869
            ),
3870
            $urlAlias
3871
        );
3872
3873
        $urlAlias = $handler->lookup('jedan-new');
3874
        $this->assertEquals(
3875
            new UrlAlias(
3876
                [
3877
                    'id' => '0-' . md5('jedan-new'),
3878
                    'type' => UrlAlias::LOCATION,
3879
                    'destination' => 315,
3880
                    'languageCodes' => [
3881
                        'cro-HR',
3882
                    ],
3883
                    'pathData' => [
3884
                        [
3885
                            'always-available' => false,
3886
                            'translations' => [
3887
                                'cro-HR' => 'jedan-new',
3888
                            ],
3889
                        ],
3890
                    ],
3891
                    'alwaysAvailable' => false,
3892
                    'isHistory' => false,
3893
                    'isCustom' => false,
3894
                    'forward' => false,
3895
                ]
3896
            ),
3897
            $urlAlias
3898
        );
3899
3900
        $urlAlias = $handler->lookup('dva-new');
3901
        $this->assertEquals(
3902
            new UrlAlias(
3903
                [
3904
                    'id' => '0-' . md5('dva-new'),
3905
                    'type' => UrlAlias::LOCATION,
3906
                    'destination' => 314,
3907
                    'languageCodes' => [
3908
                        'cro-HR',
3909
                    ],
3910
                    'pathData' => [
3911
                        [
3912
                            'always-available' => false,
3913
                            'translations' => [
3914
                                'cro-HR' => 'dva-new',
3915
                            ],
3916
                        ],
3917
                    ],
3918
                    'alwaysAvailable' => false,
3919
                    'isHistory' => false,
3920
                    'isCustom' => false,
3921
                    'forward' => false,
3922
                ]
3923
            ),
3924
            $urlAlias
3925
        );
3926
    }
3927
3928
    /**
3929
     * Test for the locationSwapped() method.
3930
     *
3931
     * @group swap
3932
     */
3933 View Code Duplication
    public function testLocationSwappedSiblingsSameName()
3934
    {
3935
        $handler = $this->getHandler();
3936
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3937
3938
        $countBeforeReusing = $this->countRows();
3939
3940
        $handler->locationSwapped(314, 2, 315, 2);
3941
3942
        $this->assertEquals(
3943
            $countBeforeReusing,
3944
            $this->countRows()
3945
        );
3946
3947
        $urlAlias = $handler->lookup('swap');
3948
        $this->assertEquals(
3949
            new UrlAlias(
3950
                [
3951
                    'id' => '0-' . md5('swap'),
3952
                    'type' => UrlAlias::LOCATION,
3953
                    'destination' => 314,
3954
                    'languageCodes' => [
3955
                        'cro-HR',
3956
                    ],
3957
                    'pathData' => [
3958
                        [
3959
                            'always-available' => false,
3960
                            'translations' => [
3961
                                'cro-HR' => 'swap',
3962
                            ],
3963
                        ],
3964
                    ],
3965
                    'alwaysAvailable' => false,
3966
                    'isHistory' => false,
3967
                    'isCustom' => false,
3968
                    'forward' => false,
3969
                ]
3970
            ),
3971
            $urlAlias
3972
        );
3973
3974
        $urlAlias = $handler->lookup('swap2');
3975
        $this->assertEquals(
3976
            new UrlAlias(
3977
                [
3978
                    'id' => '0-' . md5('swap2'),
3979
                    'type' => UrlAlias::LOCATION,
3980
                    'destination' => 315,
3981
                    'languageCodes' => [
3982
                        'cro-HR',
3983
                    ],
3984
                    'pathData' => [
3985
                        [
3986
                            'always-available' => false,
3987
                            'translations' => [
3988
                                'cro-HR' => 'swap2',
3989
                            ],
3990
                        ],
3991
                    ],
3992
                    'alwaysAvailable' => false,
3993
                    'isHistory' => false,
3994
                    'isCustom' => false,
3995
                    'forward' => false,
3996
                ]
3997
            ),
3998
            $urlAlias
3999
        );
4000
    }
4001
4002
    /**
4003
     * Test for the locationSwapped() method.
4004
     *
4005
     * @group swap
4006
     */
4007 View Code Duplication
    public function testLocationSwappedSiblingsSameNameReverse()
4008
    {
4009
        $handler = $this->getHandler();
4010
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
4011
4012
        $countBeforeReusing = $this->countRows();
4013
4014
        $handler->locationSwapped(315, 2, 314, 2);
4015
4016
        $this->assertEquals(
4017
            $countBeforeReusing,
4018
            $this->countRows()
4019
        );
4020
4021
        $urlAlias = $handler->lookup('swap');
4022
        $this->assertEquals(
4023
            new UrlAlias(
4024
                [
4025
                    'id' => '0-' . md5('swap'),
4026
                    'type' => UrlAlias::LOCATION,
4027
                    'destination' => 314,
4028
                    'languageCodes' => [
4029
                        'cro-HR',
4030
                    ],
4031
                    'pathData' => [
4032
                        [
4033
                            'always-available' => false,
4034
                            'translations' => [
4035
                                'cro-HR' => 'swap',
4036
                            ],
4037
                        ],
4038
                    ],
4039
                    'alwaysAvailable' => false,
4040
                    'isHistory' => false,
4041
                    'isCustom' => false,
4042
                    'forward' => false,
4043
                ]
4044
            ),
4045
            $urlAlias
4046
        );
4047
4048
        $urlAlias = $handler->lookup('swap2');
4049
        $this->assertEquals(
4050
            new UrlAlias(
4051
                [
4052
                    'id' => '0-' . md5('swap2'),
4053
                    'type' => UrlAlias::LOCATION,
4054
                    'destination' => 315,
4055
                    'languageCodes' => [
4056
                        'cro-HR',
4057
                    ],
4058
                    'pathData' => [
4059
                        [
4060
                            'always-available' => false,
4061
                            'translations' => [
4062
                                'cro-HR' => 'swap2',
4063
                            ],
4064
                        ],
4065
                    ],
4066
                    'alwaysAvailable' => false,
4067
                    'isHistory' => false,
4068
                    'isCustom' => false,
4069
                    'forward' => false,
4070
                ]
4071
            ),
4072
            $urlAlias
4073
        );
4074
    }
4075
4076
    /**
4077
     * Test for the locationSwapped() method.
4078
     *
4079
     * @group swap
4080
     */
4081
    public function testLocationSwappedSiblingsSameNameMultipleLanguages()
4082
    {
4083
        $handler = $this->getHandler();
4084
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name_multilang.php');
4085
4086
        $countBeforeReusing = $this->countRows();
4087
4088
        $handler->locationSwapped(314, 2, 315, 2);
4089
4090
        $this->assertEquals(
4091
            $countBeforeReusing,
4092
            $this->countRows()
4093
        );
4094
4095
        $urlAlias = $handler->lookup('swap-hr');
4096
        $this->assertEquals(
4097
            new UrlAlias(
4098
                [
4099
                    'id' => '0-' . md5('swap-hr'),
4100
                    'type' => UrlAlias::LOCATION,
4101
                    'destination' => 314,
4102
                    'languageCodes' => [
4103
                        'cro-HR',
4104
                    ],
4105
                    'pathData' => [
4106
                        [
4107
                            'always-available' => false,
4108
                            'translations' => [
4109
                                'cro-HR' => 'swap-hr',
4110
                                'eng-GB' => 'swap-en2',
4111
                            ],
4112
                        ],
4113
                    ],
4114
                    'alwaysAvailable' => false,
4115
                    'isHistory' => false,
4116
                    'isCustom' => false,
4117
                    'forward' => false,
4118
                ]
4119
            ),
4120
            $urlAlias
4121
        );
4122
4123
        $urlAlias = $handler->lookup('swap-hr2');
4124
        $this->assertEquals(
4125
            new UrlAlias(
4126
                [
4127
                    'id' => '0-' . md5('swap-hr2'),
4128
                    'type' => UrlAlias::LOCATION,
4129
                    'destination' => 315,
4130
                    'languageCodes' => [
4131
                        'cro-HR',
4132
                    ],
4133
                    'pathData' => [
4134
                        [
4135
                            'always-available' => false,
4136
                            'translations' => [
4137
                                'cro-HR' => 'swap-hr2',
4138
                                'eng-GB' => 'swap-en',
4139
                            ],
4140
                        ],
4141
                    ],
4142
                    'alwaysAvailable' => false,
4143
                    'isHistory' => false,
4144
                    'isCustom' => false,
4145
                    'forward' => false,
4146
                ]
4147
            ),
4148
            $urlAlias
4149
        );
4150
4151
        $urlAlias = $handler->lookup('swap-en');
4152
        $this->assertEquals(
4153
            new UrlAlias(
4154
                [
4155
                    'id' => '0-' . md5('swap-en'),
4156
                    'type' => UrlAlias::LOCATION,
4157
                    'destination' => 315,
4158
                    'languageCodes' => [
4159
                        'eng-GB',
4160
                    ],
4161
                    'pathData' => [
4162
                        [
4163
                            'always-available' => false,
4164
                            'translations' => [
4165
                                'cro-HR' => 'swap-hr2',
4166
                                'eng-GB' => 'swap-en',
4167
                            ],
4168
                        ],
4169
                    ],
4170
                    'alwaysAvailable' => false,
4171
                    'isHistory' => false,
4172
                    'isCustom' => false,
4173
                    'forward' => false,
4174
                ]
4175
            ),
4176
            $urlAlias
4177
        );
4178
4179
        $urlAlias = $handler->lookup('swap-en2');
4180
        $this->assertEquals(
4181
            new UrlAlias(
4182
                [
4183
                    'id' => '0-' . md5('swap-en2'),
4184
                    'type' => UrlAlias::LOCATION,
4185
                    'destination' => 314,
4186
                    'languageCodes' => [
4187
                        'eng-GB',
4188
                    ],
4189
                    'pathData' => [
4190
                        [
4191
                            'always-available' => false,
4192
                            'translations' => [
4193
                                'cro-HR' => 'swap-hr',
4194
                                'eng-GB' => 'swap-en2',
4195
                            ],
4196
                        ],
4197
                    ],
4198
                    'alwaysAvailable' => false,
4199
                    'isHistory' => false,
4200
                    'isCustom' => false,
4201
                    'forward' => false,
4202
                ]
4203
            ),
4204
            $urlAlias
4205
        );
4206
    }
4207
4208
    /**
4209
     * Test for the locationSwapped() method.
4210
     *
4211
     * @group swap
4212
     */
4213
    public function testLocationSwappedMultipleLanguagesSimple()
4214
    {
4215
        $handler = $this->getHandler();
4216
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_simple.php');
4217
4218
        $urlAlias1HRExpected = $handler->lookup('jedan/swap-hr');
4219
        $urlAlias1ENExpected = $handler->lookup('jedan/swap-en');
4220
        $urlAlias2HRExpected = $handler->lookup('dva/swap-hr');
4221
        $urlAlias2ENExpected = $handler->lookup('dva/swap-en');
4222
4223
        $countBeforeReusing = $this->countRows();
4224
4225
        $handler->locationSwapped(316, 314, 317, 315);
4226
4227
        $this->assertEquals(
4228
            $countBeforeReusing,
4229
            $this->countRows()
4230
        );
4231
4232
        $urlAlias1HR = $handler->lookup('jedan/swap-hr');
4233
        $urlAlias1EN = $handler->lookup('jedan/swap-en');
4234
        $urlAlias2HR = $handler->lookup('dva/swap-hr');
4235
        $urlAlias2EN = $handler->lookup('dva/swap-en');
4236
4237
        $this->assertEquals($urlAlias1HRExpected, $urlAlias1HR);
4238
        $this->assertEquals($urlAlias1ENExpected, $urlAlias1EN);
4239
        $this->assertEquals($urlAlias2HRExpected, $urlAlias2HR);
4240
        $this->assertEquals($urlAlias2ENExpected, $urlAlias2EN);
4241
    }
4242
4243
    /**
4244
     * Test for the locationSwapped() method.
4245
     *
4246
     * @group swap
4247
     */
4248
    public function testLocationSwappedMultipleLanguagesDifferentLanguagesSimple()
4249
    {
4250
        $handler = $this->getHandler();
4251
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff_simple.php');
4252
4253
        $countBeforeReusing = $this->countRows();
4254
4255
        $handler->locationSwapped(316, 314, 317, 315);
4256
4257
        $this->assertEquals(
4258
            $countBeforeReusing + 2,
4259
            $this->countRows()
4260
        );
4261
4262
        $urlAlias = $handler->lookup('jedan/swap-hr');
4263
        $this->assertEquals(
4264
            new UrlAlias(
4265
                [
4266
                    'id' => '2-' . md5('swap-hr'),
4267
                    'type' => UrlAlias::LOCATION,
4268
                    'destination' => 316,
4269
                    'languageCodes' => [
4270
                        'cro-HR',
4271
                    ],
4272
                    'pathData' => [
4273
                        [
4274
                            'always-available' => false,
4275
                            'translations' => [
4276
                                'cro-HR' => 'jedan',
4277
                            ],
4278
                        ],
4279
                        [
4280
                            'always-available' => false,
4281
                            'translations' => [
4282
                                'cro-HR' => 'swap-hr',
4283
                                'ger-DE' => 'swap-de',
4284
                            ],
4285
                        ],
4286
                    ],
4287
                    'alwaysAvailable' => false,
4288
                    'isHistory' => false,
4289
                    'isCustom' => false,
4290
                    'forward' => false,
4291
                ]
4292
            ),
4293
            $urlAlias
4294
        );
4295
4296
        $urlAlias = $handler->lookup('jedan/swap-de');
4297
        $this->assertEquals(
4298
            new UrlAlias(
4299
                [
4300
                    'id' => '2-' . md5('swap-de'),
4301
                    'type' => UrlAlias::LOCATION,
4302
                    'destination' => 316,
4303
                    'languageCodes' => [
4304
                        'ger-DE',
4305
                    ],
4306
                    'pathData' => [
4307
                        [
4308
                            'always-available' => false,
4309
                            'translations' => [
4310
                                'cro-HR' => 'jedan',
4311
                            ],
4312
                        ],
4313
                        [
4314
                            'always-available' => false,
4315
                            'translations' => [
4316
                                'cro-HR' => 'swap-hr',
4317
                                'ger-DE' => 'swap-de',
4318
                            ],
4319
                        ],
4320
                    ],
4321
                    'alwaysAvailable' => false,
4322
                    'isHistory' => false,
4323
                    'isCustom' => false,
4324
                    'forward' => false,
4325
                ]
4326
            ),
4327
            $urlAlias
4328
        );
4329
4330
        $urlAlias = $handler->lookup('jedan/swap-en');
4331
        $this->assertEquals(
4332
            new UrlAlias(
4333
                [
4334
                    'id' => '2-' . md5('swap-en'),
4335
                    'type' => UrlAlias::LOCATION,
4336
                    'destination' => 316,
4337
                    'languageCodes' => [
4338
                        'eng-GB',
4339
                    ],
4340
                    'pathData' => [
4341
                        [
4342
                            'always-available' => false,
4343
                            'translations' => [
4344
                                'cro-HR' => 'jedan',
4345
                            ],
4346
                        ],
4347
                        [
4348
                            'always-available' => false,
4349
                            'translations' => [
4350
                                'eng-GB' => 'swap-en',
4351
                            ],
4352
                        ],
4353
                    ],
4354
                    'alwaysAvailable' => false,
4355
                    'isHistory' => true,
4356
                    'isCustom' => false,
4357
                    'forward' => false,
4358
                ]
4359
            ),
4360
            $urlAlias
4361
        );
4362
4363
        $urlAlias = $handler->lookup('dva/swap-hr');
4364
        $this->assertEquals(
4365
            new UrlAlias(
4366
                [
4367
                    'id' => '3-' . md5('swap-hr'),
4368
                    'type' => UrlAlias::LOCATION,
4369
                    'destination' => 317,
4370
                    'languageCodes' => [
4371
                        'cro-HR',
4372
                    ],
4373
                    'pathData' => [
4374
                        [
4375
                            'always-available' => false,
4376
                            'translations' => [
4377
                                'cro-HR' => 'dva',
4378
                            ],
4379
                        ],
4380
                        [
4381
                            'always-available' => false,
4382
                            'translations' => [
4383
                                'eng-GB' => 'swap-en',
4384
                                'cro-HR' => 'swap-hr',
4385
                            ],
4386
                        ],
4387
                    ],
4388
                    'alwaysAvailable' => false,
4389
                    'isHistory' => false,
4390
                    'isCustom' => false,
4391
                    'forward' => false,
4392
                ]
4393
            ),
4394
            $urlAlias
4395
        );
4396
4397
        $urlAlias = $handler->lookup('dva/swap-en');
4398
        $this->assertEquals(
4399
            new UrlAlias(
4400
                [
4401
                    'id' => '3-' . md5('swap-en'),
4402
                    'type' => UrlAlias::LOCATION,
4403
                    'destination' => 317,
4404
                    'languageCodes' => [
4405
                        'eng-GB',
4406
                    ],
4407
                    'pathData' => [
4408
                        [
4409
                            'always-available' => false,
4410
                            'translations' => [
4411
                                'cro-HR' => 'dva',
4412
                            ],
4413
                        ],
4414
                        [
4415
                            'always-available' => false,
4416
                            'translations' => [
4417
                                'eng-GB' => 'swap-en',
4418
                                'cro-HR' => 'swap-hr',
4419
                            ],
4420
                        ],
4421
                    ],
4422
                    'alwaysAvailable' => false,
4423
                    'isHistory' => false,
4424
                    'isCustom' => false,
4425
                    'forward' => false,
4426
                ]
4427
            ),
4428
            $urlAlias
4429
        );
4430
4431
        $urlAlias = $handler->lookup('dva/swap-de');
4432
        $this->assertEquals(
4433
            new UrlAlias(
4434
                [
4435
                    'id' => '3-' . md5('swap-de'),
4436
                    'type' => UrlAlias::LOCATION,
4437
                    'destination' => 317,
4438
                    'languageCodes' => [
4439
                        'ger-DE',
4440
                    ],
4441
                    'pathData' => [
4442
                        [
4443
                            'always-available' => false,
4444
                            'translations' => [
4445
                                'cro-HR' => 'dva',
4446
                            ],
4447
                        ],
4448
                        [
4449
                            'always-available' => false,
4450
                            'translations' => [
4451
                                'ger-DE' => 'swap-de',
4452
                            ],
4453
                        ],
4454
                    ],
4455
                    'alwaysAvailable' => false,
4456
                    'isHistory' => true,
4457
                    'isCustom' => false,
4458
                    'forward' => false,
4459
                ]
4460
            ),
4461
            $urlAlias
4462
        );
4463
    }
4464
4465
    /**
4466
     * Test for the locationSwapped() method.
4467
     *
4468
     * @group swap
4469
     */
4470
    public function testLocationSwappedMultipleLanguagesDifferentLanguages()
4471
    {
4472
        $handler = $this->getHandler();
4473
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff.php');
4474
4475
        $countBeforeReusing = $this->countRows();
4476
4477
        $handler->locationSwapped(317, 315, 316, 314);
4478
4479
        $this->assertEquals(
4480
            $countBeforeReusing + 2,
4481
            $this->countRows()
4482
        );
4483
4484
        $urlAlias = $handler->lookup('jedan/swap-this');
4485
        $this->assertEquals(
4486
            new UrlAlias(
4487
                [
4488
                    'id' => '2-' . md5('swap-this'),
4489
                    'type' => UrlAlias::LOCATION,
4490
                    'destination' => 316,
4491
                    'languageCodes' => [
4492
                        'ger-DE',
4493
                        'nor-NO',
4494
                    ],
4495
                    'pathData' => [
4496
                        [
4497
                            'always-available' => false,
4498
                            'translations' => [
4499
                                'cro-HR' => 'jedan',
4500
                            ],
4501
                        ],
4502
                        [
4503
                            'always-available' => false,
4504
                            'translations' => [
4505
                                'cro-HR' => 'swap-hr',
4506
                                'ger-DE' => 'swap-this',
4507
                                'nor-NO' => 'swap-this',
4508
                            ],
4509
                        ],
4510
                    ],
4511
                    'alwaysAvailable' => false,
4512
                    'isHistory' => false,
4513
                    'isCustom' => false,
4514
                    'forward' => false,
4515
                ]
4516
            ),
4517
            $urlAlias
4518
        );
4519
4520
        $urlAlias = $handler->lookup('jedan/swap-en');
4521
        $this->assertEquals(
4522
            new UrlAlias(
4523
                [
4524
                    'id' => '2-' . md5('swap-en'),
4525
                    'type' => UrlAlias::LOCATION,
4526
                    'destination' => 316,
4527
                    'languageCodes' => [
4528
                        'eng-GB',
4529
                    ],
4530
                    'pathData' => [
4531
                        [
4532
                            'always-available' => false,
4533
                            'translations' => [
4534
                                'cro-HR' => 'jedan',
4535
                            ],
4536
                        ],
4537
                        [
4538
                            'always-available' => false,
4539
                            'translations' => [
4540
                                'eng-GB' => 'swap-en',
4541
                            ],
4542
                        ],
4543
                    ],
4544
                    'alwaysAvailable' => false,
4545
                    'isHistory' => true,
4546
                    'isCustom' => false,
4547
                    'forward' => false,
4548
                ]
4549
            ),
4550
            $urlAlias
4551
        );
4552
4553
        $urlAlias = $handler->lookup('dva/swap-hr');
4554
        $this->assertEquals(
4555
            new UrlAlias(
4556
                [
4557
                    'id' => '3-' . md5('swap-hr'),
4558
                    'type' => UrlAlias::LOCATION,
4559
                    'destination' => 317,
4560
                    'languageCodes' => [
4561
                        'cro-HR',
4562
                    ],
4563
                    'pathData' => [
4564
                        [
4565
                            'always-available' => false,
4566
                            'translations' => [
4567
                                'cro-HR' => 'dva',
4568
                            ],
4569
                        ],
4570
                        [
4571
                            'always-available' => false,
4572
                            'translations' => [
4573
                                'cro-HR' => 'swap-hr',
4574
                            ],
4575
                        ],
4576
                    ],
4577
                    'alwaysAvailable' => false,
4578
                    'isHistory' => true,
4579
                    'isCustom' => false,
4580
                    'forward' => false,
4581
                ]
4582
            ),
4583
            $urlAlias
4584
        );
4585
4586
        $urlAlias = $handler->lookup('dva/swap-this');
4587
        $this->assertEquals(
4588
            new UrlAlias(
4589
                [
4590
                    'id' => '3-' . md5('swap-this'),
4591
                    'type' => UrlAlias::LOCATION,
4592
                    'destination' => 317,
4593
                    'languageCodes' => [
4594
                        'cro-HR',
4595
                        'ger-DE',
4596
                    ],
4597
                    'pathData' => [
4598
                        [
4599
                            'always-available' => false,
4600
                            'translations' => [
4601
                                'cro-HR' => 'dva',
4602
                            ],
4603
                        ],
4604
                        [
4605
                            'always-available' => false,
4606
                            'translations' => [
4607
                                'cro-HR' => 'swap-this',
4608
                                'ger-DE' => 'swap-this',
4609
                                'eng-GB' => 'swap-en',
4610
                            ],
4611
                        ],
4612
                    ],
4613
                    'alwaysAvailable' => false,
4614
                    'isHistory' => false,
4615
                    'isCustom' => false,
4616
                    'forward' => false,
4617
                ]
4618
            ),
4619
            $urlAlias
4620
        );
4621
    }
4622
4623
    /**
4624
     * Test for the locationSwapped() method.
4625
     *
4626
     * @group swap
4627
     */
4628
    public function testLocationSwappedMultipleLanguagesWithCompositeHistory()
4629
    {
4630
        $handler = $this->getHandler();
4631
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_cleanup_composite.php');
4632
4633
        $countBeforeReusing = $this->countRows();
4634
4635
        $handler->locationSwapped(317, 315, 316, 314);
4636
4637
        $this->assertEquals(
4638
            $countBeforeReusing + 4,
4639
            $this->countRows()
4640
        );
4641
4642
        $urlAlias = $handler->lookup('jedan/swap-this');
4643
        $this->assertEquals(
4644
            new UrlAlias(
4645
                [
4646
                    'id' => '2-' . md5('swap-this'),
4647
                    'type' => UrlAlias::LOCATION,
4648
                    'destination' => 316,
4649
                    'languageCodes' => [
4650
                        'cro-HR',
4651
                    ],
4652
                    'pathData' => [
4653
                        [
4654
                            'always-available' => false,
4655
                            'translations' => [
4656
                                'cro-HR' => 'jedan',
4657
                            ],
4658
                        ],
4659
                        [
4660
                            'always-available' => false,
4661
                            'translations' => [
4662
                                'cro-HR' => 'swap-this',
4663
                            ],
4664
                        ],
4665
                    ],
4666
                    'alwaysAvailable' => false,
4667
                    'isHistory' => true,
4668
                    'isCustom' => false,
4669
                    'forward' => false,
4670
                ]
4671
            ),
4672
            $urlAlias
4673
        );
4674
4675
        $urlAlias = $handler->lookup('jedan/swap-en');
4676
        $this->assertEquals(
4677
            new UrlAlias(
4678
                [
4679
                    'id' => '2-' . md5('swap-en'),
4680
                    'type' => UrlAlias::LOCATION,
4681
                    'destination' => 316,
4682
                    'languageCodes' => [
4683
                        'eng-GB',
4684
                    ],
4685
                    'pathData' => [
4686
                        [
4687
                            'always-available' => false,
4688
                            'translations' => [
4689
                                'cro-HR' => 'jedan',
4690
                            ],
4691
                        ],
4692
                        [
4693
                            'always-available' => false,
4694
                            'translations' => [
4695
                                'eng-GB' => 'swap-en',
4696
                            ],
4697
                        ],
4698
                    ],
4699
                    'alwaysAvailable' => false,
4700
                    'isHistory' => true,
4701
                    'isCustom' => false,
4702
                    'forward' => false,
4703
                ]
4704
            ),
4705
            $urlAlias
4706
        );
4707
4708
        $urlAlias = $handler->lookup('jedan/swap-hr');
4709
        $this->assertEquals(
4710
            new UrlAlias(
4711
                [
4712
                    'id' => '2-' . md5('swap-hr'),
4713
                    'type' => UrlAlias::LOCATION,
4714
                    'destination' => 316,
4715
                    'languageCodes' => [
4716
                        'cro-HR',
4717
                    ],
4718
                    'pathData' => [
4719
                        [
4720
                            'always-available' => false,
4721
                            'translations' => [
4722
                                'cro-HR' => 'jedan',
4723
                            ],
4724
                        ],
4725
                        [
4726
                            'always-available' => false,
4727
                            'translations' => [
4728
                                'cro-HR' => 'swap-hr',
4729
                                'ger-DE' => 'swap-that',
4730
                                'nor-NO' => 'swap-that',
4731
                            ],
4732
                        ],
4733
                    ],
4734
                    'alwaysAvailable' => false,
4735
                    'isHistory' => false,
4736
                    'isCustom' => false,
4737
                    'forward' => false,
4738
                ]
4739
            ),
4740
            $urlAlias
4741
        );
4742
4743
        $urlAlias = $handler->lookup('jedan/swap-that');
4744
        $this->assertEquals(
4745
            new UrlAlias(
4746
                [
4747
                    'id' => '2-' . md5('swap-that'),
4748
                    'type' => UrlAlias::LOCATION,
4749
                    'destination' => 316,
4750
                    'languageCodes' => [
4751
                        'ger-DE',
4752
                        'nor-NO',
4753
                    ],
4754
                    'pathData' => [
4755
                        [
4756
                            'always-available' => false,
4757
                            'translations' => [
4758
                                'cro-HR' => 'jedan',
4759
                            ],
4760
                        ],
4761
                        [
4762
                            'always-available' => false,
4763
                            'translations' => [
4764
                                'cro-HR' => 'swap-hr',
4765
                                'ger-DE' => 'swap-that',
4766
                                'nor-NO' => 'swap-that',
4767
                            ],
4768
                        ],
4769
                    ],
4770
                    'alwaysAvailable' => false,
4771
                    'isHistory' => false,
4772
                    'isCustom' => false,
4773
                    'forward' => false,
4774
                ]
4775
            ),
4776
            $urlAlias
4777
        );
4778
4779
        $urlAlias = $handler->lookup('dva/swap-hr');
4780
        $this->assertEquals(
4781
            new UrlAlias(
4782
                [
4783
                    'id' => '3-' . md5('swap-hr'),
4784
                    'type' => UrlAlias::LOCATION,
4785
                    'destination' => 317,
4786
                    'languageCodes' => [
4787
                        'cro-HR',
4788
                    ],
4789
                    'pathData' => [
4790
                        [
4791
                            'always-available' => false,
4792
                            'translations' => [
4793
                                'cro-HR' => 'dva',
4794
                            ],
4795
                        ],
4796
                        [
4797
                            'always-available' => false,
4798
                            'translations' => [
4799
                                'cro-HR' => 'swap-hr',
4800
                            ],
4801
                        ],
4802
                    ],
4803
                    'alwaysAvailable' => false,
4804
                    'isHistory' => true,
4805
                    'isCustom' => false,
4806
                    'forward' => false,
4807
                ]
4808
            ),
4809
            $urlAlias
4810
        );
4811
4812
        $urlAlias = $handler->lookup('dva/swap-that');
4813
        $this->assertEquals(
4814
            new UrlAlias(
4815
                [
4816
                    'id' => '3-' . md5('swap-that'),
4817
                    'type' => UrlAlias::LOCATION,
4818
                    'destination' => 317,
4819
                    'languageCodes' => [
4820
                        'ger-DE',
4821
                        'nor-NO',
4822
                    ],
4823
                    'pathData' => [
4824
                        [
4825
                            'always-available' => false,
4826
                            'translations' => [
4827
                                'cro-HR' => 'dva',
4828
                            ],
4829
                        ],
4830
                        [
4831
                            'always-available' => false,
4832
                            'translations' => [
4833
                                'ger-DE' => 'swap-that',
4834
                                'nor-NO' => 'swap-that',
4835
                            ],
4836
                        ],
4837
                    ],
4838
                    'alwaysAvailable' => false,
4839
                    'isHistory' => true,
4840
                    'isCustom' => false,
4841
                    'forward' => false,
4842
                ]
4843
            ),
4844
            $urlAlias
4845
        );
4846
4847
        $urlAlias = $handler->lookup('dva/swap-this');
4848
        $this->assertEquals(
4849
            new UrlAlias(
4850
                [
4851
                    'id' => '3-' . md5('swap-this'),
4852
                    'type' => UrlAlias::LOCATION,
4853
                    'destination' => 317,
4854
                    'languageCodes' => [
4855
                        'cro-HR',
4856
                    ],
4857
                    'pathData' => [
4858
                        [
4859
                            'always-available' => false,
4860
                            'translations' => [
4861
                                'cro-HR' => 'dva',
4862
                            ],
4863
                        ],
4864
                        [
4865
                            'always-available' => false,
4866
                            'translations' => [
4867
                                'cro-HR' => 'swap-this',
4868
                                'eng-GB' => 'swap-en',
4869
                            ],
4870
                        ],
4871
                    ],
4872
                    'alwaysAvailable' => false,
4873
                    'isHistory' => false,
4874
                    'isCustom' => false,
4875
                    'forward' => false,
4876
                ]
4877
            ),
4878
            $urlAlias
4879
        );
4880
4881
        $urlAlias = $handler->lookup('dva/swap-en');
4882
        $this->assertEquals(
4883
            new UrlAlias(
4884
                [
4885
                    'id' => '3-' . md5('swap-en'),
4886
                    'type' => UrlAlias::LOCATION,
4887
                    'destination' => 317,
4888
                    'languageCodes' => [
4889
                        'eng-GB',
4890
                    ],
4891
                    'pathData' => [
4892
                        [
4893
                            'always-available' => false,
4894
                            'translations' => [
4895
                                'cro-HR' => 'dva',
4896
                            ],
4897
                        ],
4898
                        [
4899
                            'always-available' => false,
4900
                            'translations' => [
4901
                                'cro-HR' => 'swap-this',
4902
                                'eng-GB' => 'swap-en',
4903
                            ],
4904
                        ],
4905
                    ],
4906
                    'alwaysAvailable' => false,
4907
                    'isHistory' => false,
4908
                    'isCustom' => false,
4909
                    'forward' => false,
4910
                ]
4911
            ),
4912
            $urlAlias
4913
        );
4914
    }
4915
4916
    /**
4917
     * Test for the locationSwapped() method.
4918
     *
4919
     * @group swap
4920
     */
4921 View Code Duplication
    public function testLocationSwappedWithReusingExternalHistory()
4922
    {
4923
        $handler = $this->getHandler();
4924
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_external_history.php');
4925
4926
        $countBeforeReusing = $this->countRows();
4927
4928
        $handler->locationSwapped(318, 314, 319, 315);
4929
4930
        $this->assertEquals(
4931
            $countBeforeReusing,
4932
            $this->countRows()
4933
        );
4934
4935
        $urlAlias = $handler->lookup('jedan/swap-that');
4936
        $this->assertEquals(
4937
            new UrlAlias(
4938
                [
4939
                    'id' => '2-' . md5('swap-that'),
4940
                    'type' => UrlAlias::LOCATION,
4941
                    'destination' => 318,
4942
                    'languageCodes' => [
4943
                        'cro-HR',
4944
                    ],
4945
                    'pathData' => [
4946
                        [
4947
                            'always-available' => false,
4948
                            'translations' => [
4949
                                'cro-HR' => 'jedan',
4950
                            ],
4951
                        ],
4952
                        [
4953
                            'always-available' => false,
4954
                            'translations' => [
4955
                                'cro-HR' => 'swap-that',
4956
                            ],
4957
                        ],
4958
                    ],
4959
                    'alwaysAvailable' => false,
4960
                    'isHistory' => false,
4961
                    'isCustom' => false,
4962
                    'forward' => false,
4963
                ]
4964
            ),
4965
            $urlAlias
4966
        );
4967
4968
        $urlAlias = $handler->lookup('dva/swap-this');
4969
        $this->assertEquals(
4970
            new UrlAlias(
4971
                [
4972
                    'id' => '3-' . md5('swap-this'),
4973
                    'type' => UrlAlias::LOCATION,
4974
                    'destination' => 319,
4975
                    'languageCodes' => [
4976
                        'cro-HR',
4977
                    ],
4978
                    'pathData' => [
4979
                        [
4980
                            'always-available' => false,
4981
                            'translations' => [
4982
                                'cro-HR' => 'dva',
4983
                            ],
4984
                        ],
4985
                        [
4986
                            'always-available' => false,
4987
                            'translations' => [
4988
                                'cro-HR' => 'swap-this',
4989
                            ],
4990
                        ],
4991
                    ],
4992
                    'alwaysAvailable' => false,
4993
                    'isHistory' => false,
4994
                    'isCustom' => false,
4995
                    'forward' => false,
4996
                ]
4997
            ),
4998
            $urlAlias
4999
        );
5000
5001
        $urlAlias = $handler->lookup('dva/swap-that');
5002
        $this->assertEquals(
5003
            new UrlAlias(
5004
                [
5005
                    'id' => '3-' . md5('swap-that'),
5006
                    'type' => UrlAlias::LOCATION,
5007
                    'destination' => 319,
5008
                    'languageCodes' => [
5009
                        'cro-HR',
5010
                    ],
5011
                    'pathData' => [
5012
                        [
5013
                            'always-available' => false,
5014
                            'translations' => [
5015
                                'cro-HR' => 'dva',
5016
                            ],
5017
                        ],
5018
                        [
5019
                            'always-available' => false,
5020
                            'translations' => [
5021
                                'cro-HR' => 'swap-that',
5022
                            ],
5023
                        ],
5024
                    ],
5025
                    'alwaysAvailable' => false,
5026
                    'isHistory' => true,
5027
                    'isCustom' => false,
5028
                    'forward' => false,
5029
                ]
5030
            ),
5031
            $urlAlias
5032
        );
5033
5034
        $urlAlias = $handler->lookup('jedan/swap-this');
5035
        $this->assertEquals(
5036
            new UrlAlias(
5037
                [
5038
                    'id' => '2-' . md5('swap-this'),
5039
                    'type' => UrlAlias::LOCATION,
5040
                    'destination' => 318,
5041
                    'languageCodes' => [
5042
                        'cro-HR',
5043
                    ],
5044
                    'pathData' => [
5045
                        [
5046
                            'always-available' => false,
5047
                            'translations' => [
5048
                                'cro-HR' => 'jedan',
5049
                            ],
5050
                        ],
5051
                        [
5052
                            'always-available' => false,
5053
                            'translations' => [
5054
                                'cro-HR' => 'swap-this',
5055
                            ],
5056
                        ],
5057
                    ],
5058
                    'alwaysAvailable' => false,
5059
                    'isHistory' => true,
5060
                    'isCustom' => false,
5061
                    'forward' => false,
5062
                ]
5063
            ),
5064
            $urlAlias
5065
        );
5066
    }
5067
5068
    /**
5069
     * Test for the locationSwapped() method.
5070
     *
5071
     * @group swap
5072
     */
5073 View Code Duplication
    public function testLocationSwappedWithReusingNopEntry()
5074
    {
5075
        $handler = $this->getHandler();
5076
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5077
5078
        $countBeforeReusing = $this->countRows();
5079
5080
        $handler->locationSwapped(316, 314, 317, 315);
5081
5082
        $this->assertEquals(
5083
            $countBeforeReusing + 1,
5084
            $this->countRows()
5085
        );
5086
5087
        $urlAlias = $handler->lookup('jedan/swap-that');
5088
        $this->assertEquals(
5089
            new UrlAlias(
5090
                [
5091
                    'id' => '2-' . md5('swap-that'),
5092
                    'type' => UrlAlias::LOCATION,
5093
                    'destination' => 316,
5094
                    'languageCodes' => [
5095
                        'cro-HR',
5096
                    ],
5097
                    'pathData' => [
5098
                        [
5099
                            'always-available' => false,
5100
                            'translations' => [
5101
                                'cro-HR' => 'jedan',
5102
                            ],
5103
                        ],
5104
                        [
5105
                            'always-available' => false,
5106
                            'translations' => [
5107
                                'cro-HR' => 'swap-that',
5108
                            ],
5109
                        ],
5110
                    ],
5111
                    'alwaysAvailable' => false,
5112
                    'isHistory' => false,
5113
                    'isCustom' => false,
5114
                    'forward' => false,
5115
                ]
5116
            ),
5117
            $urlAlias
5118
        );
5119
5120
        $urlAlias = $handler->lookup('dva/swap-this');
5121
        $this->assertEquals(
5122
            new UrlAlias(
5123
                [
5124
                    'id' => '3-' . md5('swap-this'),
5125
                    'type' => UrlAlias::LOCATION,
5126
                    'destination' => 317,
5127
                    'languageCodes' => [
5128
                        'cro-HR',
5129
                    ],
5130
                    'pathData' => [
5131
                        [
5132
                            'always-available' => false,
5133
                            'translations' => [
5134
                                'cro-HR' => 'dva',
5135
                            ],
5136
                        ],
5137
                        [
5138
                            'always-available' => false,
5139
                            'translations' => [
5140
                                'cro-HR' => 'swap-this',
5141
                            ],
5142
                        ],
5143
                    ],
5144
                    'alwaysAvailable' => false,
5145
                    'isHistory' => false,
5146
                    'isCustom' => false,
5147
                    'forward' => false,
5148
                ]
5149
            ),
5150
            $urlAlias
5151
        );
5152
5153
        $urlAlias = $handler->lookup('dva/swap-that');
5154
        $this->assertEquals(
5155
            new UrlAlias(
5156
                [
5157
                    'id' => '3-' . md5('swap-that'),
5158
                    'type' => UrlAlias::LOCATION,
5159
                    'destination' => 317,
5160
                    'languageCodes' => [
5161
                        'cro-HR',
5162
                    ],
5163
                    'pathData' => [
5164
                        [
5165
                            'always-available' => false,
5166
                            'translations' => [
5167
                                'cro-HR' => 'dva',
5168
                            ],
5169
                        ],
5170
                        [
5171
                            'always-available' => false,
5172
                            'translations' => [
5173
                                'cro-HR' => 'swap-that',
5174
                            ],
5175
                        ],
5176
                    ],
5177
                    'alwaysAvailable' => false,
5178
                    'isHistory' => true,
5179
                    'isCustom' => false,
5180
                    'forward' => false,
5181
                ]
5182
            ),
5183
            $urlAlias
5184
        );
5185
5186
        $urlAlias = $handler->lookup('jedan/swap-this');
5187
        $this->assertEquals(
5188
            new UrlAlias(
5189
                [
5190
                    'id' => '2-' . md5('swap-this'),
5191
                    'type' => UrlAlias::LOCATION,
5192
                    'destination' => 316,
5193
                    'languageCodes' => [
5194
                        'cro-HR',
5195
                    ],
5196
                    'pathData' => [
5197
                        [
5198
                            'always-available' => false,
5199
                            'translations' => [
5200
                                'cro-HR' => 'jedan',
5201
                            ],
5202
                        ],
5203
                        [
5204
                            'always-available' => false,
5205
                            'translations' => [
5206
                                'cro-HR' => 'swap-this',
5207
                            ],
5208
                        ],
5209
                    ],
5210
                    'alwaysAvailable' => false,
5211
                    'isHistory' => true,
5212
                    'isCustom' => false,
5213
                    'forward' => false,
5214
                ]
5215
            ),
5216
            $urlAlias
5217
        );
5218
    }
5219
5220
    /**
5221
     * Test for the locationSwapped() method.
5222
     *
5223
     * @depends testLocationSwappedWithReusingNopEntry
5224
     * @group swap
5225
     */
5226 View Code Duplication
    public function testLocationSwappedWithReusingNopEntryCustomAliasIsDestroyed()
5227
    {
5228
        $handler = $this->getHandler();
5229
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5230
5231
        $handler->lookup('jedan/swap-that/search');
5232
        $handler->locationSwapped(316, 314, 317, 315);
5233
5234
        try {
5235
            $handler->lookup('jedan/swap-that/search');
5236
            $this->fail('Custom alias is not destroyed');
5237
        } catch (NotFoundException $e) {
5238
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
5239
            // on the same level (that means link and ID are updated to the existing alias ID,
5240
            // so custom alias children entries are no longer properly linked (parent-link))
5241
        }
5242
    }
5243
5244
    /**
5245
     * Test for the locationSwapped() method.
5246
     *
5247
     * @group swap
5248
     *
5249
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5250
     */
5251 View Code Duplication
    public function testLocationSwappedUpdatesLocationPathIdentificationString()
5252
    {
5253
        $handler = $this->getHandler();
5254
        $locationGateway = $this->getLocationGateway();
5255
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_path_identification_string.php');
5256
5257
        $countBeforeReusing = $this->countRows();
5258
5259
        $handler->locationSwapped(314, 2, 315, 2);
5260
5261
        $this->assertEquals(
5262
            $countBeforeReusing,
5263
            $this->countRows()
5264
        );
5265
5266
        $locationData = $locationGateway->getBasicNodeData(314);
5267
        self::assertEquals('dva', $locationData['path_identification_string']);
5268
5269
        $locationData = $locationGateway->getBasicNodeData(315);
5270
        self::assertEquals('jedan', $locationData['path_identification_string']);
5271
    }
5272
5273
    /**
5274
     * Test for the locationSwapped() method.
5275
     *
5276
     * @group swap
5277
     *
5278
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5279
     */
5280 View Code Duplication
    public function testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString()
5281
    {
5282
        $handler = $this->getHandler();
5283
        $locationGateway = $this->getLocationGateway();
5284
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_path_identification_string.php');
5285
5286
        $countBeforeReusing = $this->countRows();
5287
5288
        $handler->locationSwapped(314, 2, 315, 2);
5289
5290
        $this->assertEquals(
5291
            $countBeforeReusing,
5292
            $this->countRows()
5293
        );
5294
5295
        $locationData = $locationGateway->getBasicNodeData(314);
5296
        self::assertEquals('zwei', $locationData['path_identification_string']);
5297
5298
        $locationData = $locationGateway->getBasicNodeData(315);
5299
        self::assertEquals('jedan', $locationData['path_identification_string']);
5300
    }
5301
5302
    /**
5303
     * @return int
5304
     */
5305
    protected function countRows()
5306
    {
5307
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5308
        $query = $this->getDatabaseHandler()->createSelectQuery();
5309
        $query->select(
5310
            $query->expr->count('*')
5311
        )->from(
5312
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5313
        );
5314
5315
        $statement = $query->prepare();
5316
        $statement->execute();
5317
5318
        return (int)$statement->fetchColumn();
5319
    }
5320
5321
    protected function dump()
5322
    {
5323
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5324
        $query = $this->getDatabaseHandler()->createSelectQuery();
5325
        $query->select(
5326
            '*'
5327
        )->from(
5328
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5329
        );
5330
5331
        $statement = $query->prepare();
5332
        $statement->execute();
5333
5334
        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...
5335
    }
5336
5337
    /**
5338
     * @var \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler
5339
     * @deprecated Start to use DBAL $connection instead.
5340
     */
5341
    protected $dbHandler;
5342
5343
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway */
5344
    protected $locationGateway;
5345
5346
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler */
5347
    protected $languageHandler;
5348
5349
    /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator */
5350
    protected $languageMaskGenerator;
5351
5352
    /**
5353
     * @param array $methods
5354
     *
5355
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler|\PHPUnit\Framework\MockObject\MockObject
5356
     */
5357
    protected function getPartlyMockedHandler(array $methods)
5358
    {
5359
        return $this->getMockBuilder(Handler::class)
5360
            ->setConstructorArgs(
5361
                [
5362
                    $this->createMock(UrlAliasGateway::class),
5363
                    $this->createMock(Mapper::class),
5364
                    $this->createMock(LocationGateway::class),
5365
                    $this->createMock(LanguageHandler::class),
5366
                    $this->createMock(SlugConverter::class),
5367
                    $this->createMock(Gateway::class),
5368
                    $this->createMock(LanguageMaskGenerator::class),
5369
                    $this->createMock(TransactionHandler::class),
5370
                ]
5371
            )
5372
            ->setMethods($methods)
5373
            ->getMock();
5374
    }
5375
5376
    /**
5377
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5378
     */
5379
    protected function getHandler()
5380
    {
5381
        $languageHandler = $this->getLanguageHandler();
5382
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5383
        $databaseHandler = $this->getDatabaseHandler();
5384
        $gateway = new DoctrineDatabase(
5385
            $databaseHandler,
5386
            $languageMaskGenerator
5387
        );
5388
        $mapper = new Mapper($languageMaskGenerator);
5389
        $slugConverter = new SlugConverter($this->getProcessor());
5390
        $contentGateway = new ContentGateway(
5391
            $this->getDatabaseHandler(),
5392
            $this->getDatabaseConnection(),
5393
            new ContentGateway\QueryBuilder($this->getDatabaseHandler()),
5394
            $languageHandler,
5395
            $languageMaskGenerator
5396
        );
5397
5398
        return new Handler(
5399
            $gateway,
5400
            $mapper,
5401
            $this->getLocationGateway(),
5402
            $languageHandler,
5403
            $slugConverter,
5404
            $contentGateway,
5405
            $languageMaskGenerator,
5406
            $this->createMock(TransactionHandler::class)
5407
        );
5408
    }
5409
5410
    /**
5411
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5412
     */
5413
    protected function getLanguageHandler()
5414
    {
5415
        if (!isset($this->languageHandler)) {
5416
            $this->languageHandler = new LanguageHandler(
5417
                new LanguageGateway(
5418
                    $this->getDatabaseHandler()
5419
                ),
5420
                new LanguageMapper()
5421
            );
5422
        }
5423
5424
        return $this->languageHandler;
5425
    }
5426
5427
    /**
5428
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5429
     */
5430
    protected function getLanguageMaskGenerator()
5431
    {
5432
        if (!isset($this->languageMaskGenerator)) {
5433
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5434
                $this->getLanguageHandler()
5435
            );
5436
        }
5437
5438
        return $this->languageMaskGenerator;
5439
    }
5440
5441
    /**
5442
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5443
     */
5444
    protected function getLocationGateway()
5445
    {
5446
        if (!isset($this->locationGateway)) {
5447
            $this->locationGateway = new DoctrineDatabaseLocation(
5448
                $this->getDatabaseHandler(),
5449
                $this->getLanguageMaskGenerator()
5450
            );
5451
        }
5452
5453
        return $this->locationGateway;
5454
    }
5455
5456
    /**
5457
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5458
     */
5459
    public function getProcessor()
5460
    {
5461
        return new DefinitionBased(
5462
            new Parser(),
5463
            new PcreCompiler(new Utf8Converter()),
5464
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5465
        );
5466
    }
5467
5468
    /**
5469
     * Data provider for tests of archiveUrlAliasesForDeletedTranslations.
5470
     *
5471
     * @see testArchiveUrlAliasesForDeletedTranslations for the description of parameters
5472
     *
5473
     * @return array
5474
     */
5475
    public function providerForArchiveUrlAliasesForDeletedTranslations()
5476
    {
5477
        return [
5478
            [2, ['eng-GB', 'pol-PL'], 'pol-PL'],
5479
            [3, ['eng-GB', 'pol-PL', 'nor-NO'], 'pol-PL'],
5480
        ];
5481
    }
5482
5483
    /**
5484
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::archiveUrlAliasesForDeletedTranslations()
5485
     *
5486
     * @dataProvider providerForArchiveUrlAliasesForDeletedTranslations
5487
     *
5488
     * @param int $locationId
5489
     * @param string[] $expectedLanguages expected language codes before deleting
5490
     * @param string $removeLanguage language code to be deleted
5491
     */
5492
    public function testArchiveUrlAliasesForDeletedTranslations(
5493
        $locationId,
5494
        array $expectedLanguages,
5495
        $removeLanguage
5496
    ) {
5497
        $handler = $this->getHandler();
5498
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_multilingual.php');
5499
5500
        // collect data persisted from fixtures
5501
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5502
        $collectedLanguages = [];
5503
        $collectedUrls = [];
5504
        foreach ($urlAliases as $urlAlias) {
5505
            // collect languages of all URL aliases
5506
            $collectedLanguages = array_merge($collectedLanguages, $urlAlias->languageCodes);
5507
            $isComposite = count($urlAlias->languageCodes) > 1;
5508
            foreach ($urlAlias->pathData as $pathData) {
5509
                // collect also actual unique URLs to be removed to check them after removal
5510
                if (!empty($pathData['translations'][$removeLanguage])) {
5511
                    $url = $pathData['translations'][$removeLanguage];
5512
                    $collectedUrls[$url] = $isComposite;
5513
                }
5514
            }
5515
        }
5516
        // sanity check
5517
        self::assertEquals($expectedLanguages, $collectedLanguages);
5518
5519
        // remove language
5520
        $publishedLanguages = array_values(array_diff($collectedLanguages, [$removeLanguage]));
5521
        $handler->archiveUrlAliasesForDeletedTranslations($locationId, 1, $publishedLanguages);
5522
5523
        // check reloaded structures
5524
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5525 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...
5526
            self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5527
            foreach ($urlAlias->pathData as $pathData) {
5528
                self::assertNotContains($removeLanguage, $pathData['translations']);
5529
                foreach ($pathData['translations'] as $url) {
5530
                    $lookupUrlAlias = $handler->lookup($url);
5531
                    self::assertNotContains($removeLanguage, $lookupUrlAlias->languageCodes);
5532
                }
5533
            }
5534
        }
5535
5536
        // lookup removed URLs to check they're not found
5537 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...
5538
            $urlAlias = $handler->lookup($url);
5539
            if ($isComposite) {
5540
                // check if alias no longer refers to removed Translation
5541
                self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5542
                foreach ($urlAlias->pathData as $pathData) {
5543
                    self::assertNotContains($removeLanguage, $pathData['translations']);
5544
                }
5545
            } else {
5546
                // check if non composite alias for removed translation is historized
5547
                self::assertTrue($urlAlias->isHistory);
5548
            }
5549
        }
5550
    }
5551
}
5552