Completed
Push — 7.5 ( 966769...7b2167 )
by
unknown
19:17 queued 11s
created

testLoadUrlAliasThrowsNotFoundException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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