Completed
Push — 6.13 ( 9c335d...8c8805 )
by
unknown
16:33
created

UrlAliasHandlerTest::getLanguageMaskGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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

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

Loading history...
1637
            if ($propertyName === 'pathData') {
1638
                self::assertEquals(
1639
                    [
1640
                        [
1641
                            'always-available' => false,
1642
                            'translations' => ['eng-GB' => 'nop-element-renamed'],
1643
                        ],
1644
                        [
1645
                            'always-available' => false,
1646
                            'translations' => ['eng-GB' => 'search'],
1647
                        ],
1648
                    ],
1649
                    $virtualUrlAliasChanged->pathData
1650
                );
1651
            } else {
1652
                self::assertEquals(
1653
                    $virtualUrlAlias->$propertyName,
1654
                    $virtualUrlAliasChanged->$propertyName
1655
                );
1656
            }
1657
        }
1658
    }
1659
1660
    /**
1661
     * Test for the publishUrlAliasForLocation() method.
1662
     *
1663
     * @todo document
1664
     *
1665
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1666
     * @depends testPublishUrlAliasForLocation
1667
     * @depends testPublishUrlAliasForLocationReusingNopElementChangesCustomPath
1668
     */
1669
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPathAndCreatesHistory()
1670
    {
1671
        $handler = $this->getHandler();
1672
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1673
1674
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1675
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1676
1677
        $customUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1678
        $customUrlAliasHistory = $handler->lookup('nop-element/search');
1679
1680
        self::assertTrue($customUrlAliasHistory->isHistory);
1681
        $customUrlAliasHistory->isHistory = false;
1682
        self::assertEquals(
1683
            $customUrlAliasChanged,
1684
            $customUrlAliasHistory
1685
        );
1686
    }
1687
1688
    /**
1689
     * Test for the publishUrlAliasForLocation() method.
1690
     *
1691
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1692
     */
1693
    public function testPublishUrlAliasForLocationUpdatesLocationPathIdentificationString()
1694
    {
1695
        $handler = $this->getHandler();
1696
        $locationGateway = $this->getLocationGateway();
1697
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1698
1699
        // Publishes the alias indicating that language is main, triggering updating of path_identification_string
1700
        $handler->publishUrlAliasForLocation(316, 315, 'TEST TEST TEST', 'eng-GB', false, true);
1701
1702
        $locationData = $locationGateway->getBasicNodeData(316);
1703
1704
        self::assertEquals('path314/path315/test_test_test', $locationData['path_identification_string']);
1705
    }
1706
1707
    /**
1708
     * Test for the publishUrlAliasForLocation() method.
1709
     *
1710
     * @group cleanup
1711
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1712
     */
1713
    public function testPublishUrlAliasReuseNopCleanupCustomAliasIsDestroyed()
1714
    {
1715
        $handler = $this->getHandler();
1716
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_nop.php');
1717
1718
        $handler->lookup('nop-element/search');
1719
        $handler->publishUrlAliasForLocation(314, 2, 'nop-element', 'cro-HR', false);
1720
1721
        $urlAlias = $handler->lookup('jedan');
1722
        $this->assertEquals(
1723
            new UrlAlias(
1724
                [
1725
                    'id' => '0-' . md5('jedan'),
1726
                    'type' => UrlAlias::LOCATION,
1727
                    'destination' => 314,
1728
                    'pathData' => [
1729
                        [
1730
                            'always-available' => false,
1731
                            'translations' => ['cro-HR' => 'jedan'],
1732
                        ],
1733
                    ],
1734
                    'languageCodes' => ['cro-HR'],
1735
                    'alwaysAvailable' => false,
1736
                    'isHistory' => true,
1737
                    'isCustom' => false,
1738
                    'forward' => false,
1739
                ]
1740
            ),
1741
            $urlAlias
1742
        );
1743
1744
        $urlAlias = $handler->lookup('nop-element');
1745
        $this->assertEquals(
1746
            new UrlAlias(
1747
                [
1748
                    'id' => '0-' . md5('nop-element'),
1749
                    'type' => UrlAlias::LOCATION,
1750
                    'destination' => 314,
1751
                    'pathData' => [
1752
                        [
1753
                            'always-available' => false,
1754
                            'translations' => [
1755
                                'cro-HR' => 'nop-element',
1756
                                'eng-GB' => 'dva',
1757
                            ],
1758
                        ],
1759
                    ],
1760
                    'languageCodes' => [
1761
                        'cro-HR',
1762
                    ],
1763
                    'alwaysAvailable' => false,
1764
                    'isHistory' => false,
1765
                    'isCustom' => false,
1766
                    'forward' => false,
1767
                ]
1768
            ),
1769
            $urlAlias
1770
        );
1771
1772
        try {
1773
            $handler->lookup('nop-element/search');
1774
            $this->fail('Custom alias is not destroyed');
1775
        } catch (NotFoundException $e) {
1776
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
1777
            // on the same level (that means link and ID are updated to the existing alias ID,
1778
            // so custom alias children entries are no longer properly linked (parent-link))
1779
        }
1780
    }
1781
1782
    /**
1783
     * Test for the publishUrlAliasForLocation() method.
1784
     *
1785
     * @group cleanup
1786
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1787
     */
1788 View Code Duplication
    public function testPublishUrlAliasReuseHistoryCleanup()
1789
    {
1790
        $handler = $this->getHandler();
1791
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_history.php');
1792
1793
        $handler->publishUrlAliasForLocation(314, 2, 'tri', 'cro-HR', false);
1794
1795
        $urlAlias = $handler->lookup('jedan');
1796
        $this->assertEquals(
1797
            new UrlAlias(
1798
                [
1799
                    'id' => '0-' . md5('jedan'),
1800
                    'type' => UrlAlias::LOCATION,
1801
                    'destination' => 314,
1802
                    'pathData' => [
1803
                        [
1804
                            'always-available' => false,
1805
                            'translations' => ['cro-HR' => 'jedan'],
1806
                        ],
1807
                    ],
1808
                    'languageCodes' => ['cro-HR'],
1809
                    'alwaysAvailable' => false,
1810
                    'isHistory' => true,
1811
                    'isCustom' => false,
1812
                    'forward' => false,
1813
                ]
1814
            ),
1815
            $urlAlias
1816
        );
1817
1818
        $urlAlias = $handler->lookup('tri');
1819
        $this->assertEquals(
1820
            new UrlAlias(
1821
                [
1822
                    'id' => '0-' . md5('tri'),
1823
                    'type' => UrlAlias::LOCATION,
1824
                    'destination' => 314,
1825
                    'pathData' => [
1826
                        [
1827
                            'always-available' => false,
1828
                            'translations' => [
1829
                                'cro-HR' => 'tri',
1830
                                'eng-GB' => 'dva',
1831
                            ],
1832
                        ],
1833
                    ],
1834
                    'languageCodes' => [
1835
                        'cro-HR',
1836
                    ],
1837
                    'alwaysAvailable' => false,
1838
                    'isHistory' => false,
1839
                    'isCustom' => false,
1840
                    'forward' => false,
1841
                ]
1842
            ),
1843
            $urlAlias
1844
        );
1845
    }
1846
1847
    /**
1848
     * Test for the publishUrlAliasForLocation() method.
1849
     *
1850
     * @group cleanup
1851
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1852
     */
1853 View Code Duplication
    public function testPublishUrlAliasReuseAutogeneratedCleanup()
1854
    {
1855
        $handler = $this->getHandler();
1856
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_reusing.php');
1857
1858
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', false);
1859
1860
        $urlAlias = $handler->lookup('jedan');
1861
        $this->assertEquals(
1862
            new UrlAlias(
1863
                [
1864
                    'id' => '0-' . md5('jedan'),
1865
                    'type' => UrlAlias::LOCATION,
1866
                    'destination' => 314,
1867
                    'pathData' => [
1868
                        [
1869
                            'always-available' => false,
1870
                            'translations' => ['cro-HR' => 'jedan'],
1871
                        ],
1872
                    ],
1873
                    'languageCodes' => ['cro-HR'],
1874
                    'alwaysAvailable' => false,
1875
                    'isHistory' => true,
1876
                    'isCustom' => false,
1877
                    'forward' => false,
1878
                ]
1879
            ),
1880
            $urlAlias
1881
        );
1882
1883
        $urlAlias = $handler->lookup('dva');
1884
        $this->assertEquals(
1885
            new UrlAlias(
1886
                [
1887
                    'id' => '0-' . md5('dva'),
1888
                    'type' => UrlAlias::LOCATION,
1889
                    'destination' => 314,
1890
                    'pathData' => [
1891
                        [
1892
                            'always-available' => false,
1893
                            'translations' => [
1894
                                'cro-HR' => 'dva',
1895
                                'eng-GB' => 'dva',
1896
                            ],
1897
                        ],
1898
                    ],
1899
                    'languageCodes' => [
1900
                        'cro-HR',
1901
                        'eng-GB',
1902
                    ],
1903
                    'alwaysAvailable' => false,
1904
                    'isHistory' => false,
1905
                    'isCustom' => false,
1906
                    'forward' => false,
1907
                ]
1908
            ),
1909
            $urlAlias
1910
        );
1911
    }
1912
1913
    /**
1914
     * Test for the createCustomUrlAlias() method.
1915
     *
1916
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createCustomUrlAlias
1917
     * @group create
1918
     * @group custom
1919
     */
1920 View Code Duplication
    public function testCreateCustomUrlAliasBehaviour()
1921
    {
1922
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1923
1924
        $handlerMock->expects(
1925
            $this->once()
1926
        )->method(
1927
            'createUrlAlias'
1928
        )->with(
1929
            $this->equalTo('eznode:1'),
1930
            $this->equalTo('path'),
1931
            $this->equalTo(false),
1932
            $this->equalTo(null),
1933
            $this->equalTo(false)
1934
        )->will(
1935
            $this->returnValue(
1936
                new UrlAlias()
1937
            )
1938
        );
1939
1940
        $this->assertInstanceOf(
1941
            UrlAlias::class,
1942
            $handlerMock->createCustomUrlAlias(1, 'path')
1943
        );
1944
    }
1945
1946
    /**
1947
     * Test for the createGlobalUrlAlias() method.
1948
     *
1949
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createGlobalUrlAlias
1950
     * @group create
1951
     * @group global
1952
     */
1953 View Code Duplication
    public function testCreateGlobalUrlAliasBehaviour()
1954
    {
1955
        $handlerMock = $this->getPartlyMockedHandler(['createUrlAlias']);
1956
1957
        $handlerMock->expects(
1958
            $this->once()
1959
        )->method(
1960
            'createUrlAlias'
1961
        )->with(
1962
            $this->equalTo('module/module'),
1963
            $this->equalTo('path'),
1964
            $this->equalTo(false),
1965
            $this->equalTo(null),
1966
            $this->equalTo(false)
1967
        )->will(
1968
            $this->returnValue(
1969
                new UrlAlias()
1970
            )
1971
        );
1972
1973
        $this->assertInstanceOf(
1974
            UrlAlias::class,
1975
            $handlerMock->createGlobalUrlAlias('module/module', 'path')
1976
        );
1977
    }
1978
1979
    /**
1980
     * Test for the createUrlAlias() method.
1981
     *
1982
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
1983
     * @group create
1984
     * @group custom
1985
     */
1986
    public function testCreateCustomUrlAlias()
1987
    {
1988
        $handler = $this->getHandler();
1989
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1990
1991
        $path = 'custom-location-alias';
1992
        $customUrlAlias = $handler->createCustomUrlAlias(
1993
            314,
1994
            $path,
1995
            false,
1996
            'cro-HR',
1997
            false
1998
        );
1999
2000
        self::assertEquals(4, $this->countRows());
2001
        self::assertEquals(
2002
            new UrlAlias(
2003
                [
2004
                    'id' => '0-' . md5($path),
2005
                    'type' => UrlAlias::LOCATION,
2006
                    'destination' => 314,
2007
                    'pathData' => [
2008
                        [
2009
                            'always-available' => false,
2010
                            'translations' => [
2011
                                'cro-HR' => 'custom-location-alias',
2012
                            ],
2013
                        ],
2014
                    ],
2015
                    'languageCodes' => ['cro-HR'],
2016
                    'alwaysAvailable' => false,
2017
                    'isHistory' => false,
2018
                    'isCustom' => true,
2019
                    'forward' => false,
2020
                ]
2021
            ),
2022
            $customUrlAlias
2023
        );
2024
    }
2025
2026
    /**
2027
     * Test for the createUrlAlias() method.
2028
     *
2029
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2030
     * @group create
2031
     * @group custom
2032
     */
2033
    public function testCreateCustomUrlAliasWithNonameParts()
2034
    {
2035
        $handler = $this->getHandler();
2036
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2037
2038
        $path = 'there-is-a//custom-location-alias//here';
2039
        $customUrlAlias = $handler->createCustomUrlAlias(
2040
            314,
2041
            $path,
2042
            false,
2043
            'cro-HR',
2044
            false
2045
        );
2046
2047
        self::assertEquals(8, $this->countRows());
2048
2049
        self::assertEquals(
2050
            new UrlAlias(
2051
                [
2052
                    'id' => '7-' . md5('here'),
2053
                    'type' => UrlAlias::LOCATION,
2054
                    'destination' => 314,
2055
                    'pathData' => [
2056
                        [
2057
                            'always-available' => true,
2058
                            'translations' => [
2059
                                'always-available' => 'there-is-a',
2060
                            ],
2061
                        ],
2062
                        [
2063
                            'always-available' => true,
2064
                            'translations' => [
2065
                                'always-available' => 'noname2',
2066
                            ],
2067
                        ],
2068
                        [
2069
                            'always-available' => true,
2070
                            'translations' => [
2071
                                'always-available' => 'custom-location-alias',
2072
                            ],
2073
                        ],
2074
                        [
2075
                            'always-available' => true,
2076
                            'translations' => [
2077
                                'always-available' => 'noname4',
2078
                            ],
2079
                        ],
2080
                        [
2081
                            'always-available' => false,
2082
                            'translations' => [
2083
                                'cro-HR' => 'here',
2084
                            ],
2085
                        ],
2086
                    ],
2087
                    'languageCodes' => ['cro-HR'],
2088
                    'alwaysAvailable' => false,
2089
                    'isHistory' => false,
2090
                    'isCustom' => true,
2091
                    'forward' => false,
2092
                ]
2093
            ),
2094
            $customUrlAlias
2095
        );
2096
    }
2097
2098
    /**
2099
     * Test for the createUrlAlias() method.
2100
     *
2101
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2102
     * @group create
2103
     * @group custom
2104
     *
2105
     * @todo pathData
2106
     */
2107
    public function testCreatedCustomUrlAliasIsLoadable()
2108
    {
2109
        $handler = $this->getHandler();
2110
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2111
2112
        $path = 'custom-location-alias';
2113
        $customUrlAlias = $handler->createCustomUrlAlias(
2114
            314,
2115
            $path,
2116
            false,
2117
            'cro-HR',
2118
            false
2119
        );
2120
        $loadedCustomUrlAlias = $handler->lookup($path);
2121
2122
        self::assertEquals(4, $this->countRows());
2123
2124
        foreach ($loadedCustomUrlAlias as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $loadedCustomUrlAlias of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
2125
            if ($propertyName === 'pathData') {
2126
                self::assertEquals(
2127
                    [
2128
                        [
2129
                            'always-available' => false,
2130
                            'translations' => ['cro-HR' => $path],
2131
                        ],
2132
                    ],
2133
                    $loadedCustomUrlAlias->$propertyName
2134
                );
2135
            } else {
2136
                self::assertEquals(
2137
                    $customUrlAlias->$propertyName,
2138
                    $loadedCustomUrlAlias->$propertyName
2139
                );
2140
            }
2141
        }
2142
    }
2143
2144
    /**
2145
     * Test for the createUrlAlias() method.
2146
     *
2147
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2148
     * @group create
2149
     * @group custom
2150
     */
2151
    public function testCreateCustomUrlAliasWithNopElement()
2152
    {
2153
        $handler = $this->getHandler();
2154
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2155
2156
        $path = 'ribar/palunko';
2157
        $customUrlAlias = $handler->createCustomUrlAlias(
2158
            314,
2159
            $path,
2160
            false,
2161
            'cro-HR',
2162
            true
2163
        );
2164
2165
        self::assertEquals(5, $this->countRows());
2166
        self::assertEquals(
2167
            new UrlAlias(
2168
                [
2169
                    'id' => '4-' . md5('palunko'),
2170
                    'type' => UrlAlias::LOCATION,
2171
                    'destination' => 314,
2172
                    'pathData' => [
2173
                        [
2174
                            'always-available' => true,
2175
                            'translations' => [
2176
                                'always-available' => 'ribar',
2177
                            ],
2178
                        ],
2179
                        [
2180
                            'always-available' => true,
2181
                            'translations' => [
2182
                                'cro-HR' => 'palunko',
2183
                            ],
2184
                        ],
2185
                    ],
2186
                    'languageCodes' => ['cro-HR'],
2187
                    'alwaysAvailable' => true,
2188
                    'isHistory' => false,
2189
                    'isCustom' => true,
2190
                    'forward' => false,
2191
                ]
2192
            ),
2193
            $customUrlAlias
2194
        );
2195
2196
        return $handler;
2197
    }
2198
2199
    /**
2200
     * Test for the createUrlAlias() method.
2201
     *
2202
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2203
     * @depends testCreateCustomUrlAliasWithNopElement
2204
     * @group create
2205
     * @group custom
2206
     */
2207
    public function testCreateUrlAliasWithNopElementCreatesValidNopElement(Handler $handler)
2208
    {
2209
        $url = 'ribar';
2210
        $urlAlias = $handler->lookup($url);
2211
2212
        $this->assertVirtualUrlAliasValid(
2213
            $urlAlias,
2214
            '0-' . md5($url)
2215
        );
2216
    }
2217
2218
    /**
2219
     * Test for the createUrlAlias() method.
2220
     *
2221
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2222
     * @group create
2223
     * @group custom
2224
     */
2225 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistory()
2226
    {
2227
        $handler = $this->getHandler();
2228
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2229
2230
        $countBeforeReusing = $this->countRows();
2231
        $handler->createCustomUrlAlias(
2232
            314,
2233
            'history-hello',
2234
            true,
2235
            'eng-GB',
2236
            true
2237
        );
2238
2239
        self::assertEquals(
2240
            $countBeforeReusing,
2241
            $this->countRows()
2242
        );
2243
        self::assertEquals(
2244
            new UrlAlias(
2245
                [
2246
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2247
                    'type' => UrlAlias::LOCATION,
2248
                    'destination' => 314,
2249
                    'languageCodes' => ['eng-GB'],
2250
                    'pathData' => [
2251
                        [
2252
                            'always-available' => true,
2253
                            'translations' => ['eng-GB' => 'history-hello'],
2254
                        ],
2255
                    ],
2256
                    'alwaysAvailable' => true,
2257
                    'isHistory' => false,
2258
                    'isCustom' => true,
2259
                    'forward' => true,
2260
                ]
2261
            ),
2262
            $handler->lookup('history-hello')
2263
        );
2264
    }
2265
2266
    /**
2267
     * Test for the createUrlAlias() method.
2268
     *
2269
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2270
     * @group create
2271
     * @group custom
2272
     */
2273 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistoryOfDifferentLanguage()
2274
    {
2275
        $handler = $this->getHandler();
2276
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2277
2278
        $countBeforeReusing = $this->countRows();
2279
        $handler->createCustomUrlAlias(
2280
            314,
2281
            'history-hello',
2282
            true,
2283
            'cro-HR',
2284
            true
2285
        );
2286
2287
        self::assertEquals(
2288
            $countBeforeReusing,
2289
            $this->countRows()
2290
        );
2291
        self::assertEquals(
2292
            new UrlAlias(
2293
                [
2294
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2295
                    'type' => UrlAlias::LOCATION,
2296
                    'destination' => 314,
2297
                    'languageCodes' => ['cro-HR'],
2298
                    'pathData' => [
2299
                        [
2300
                            'always-available' => true,
2301
                            'translations' => ['cro-HR' => 'history-hello'],
2302
                        ],
2303
                    ],
2304
                    'alwaysAvailable' => true,
2305
                    'isHistory' => false,
2306
                    'isCustom' => true,
2307
                    'forward' => true,
2308
                ]
2309
            ),
2310
            $handler->lookup('history-hello')
2311
        );
2312
    }
2313
2314
    /**
2315
     * Test for the createUrlAlias() method.
2316
     *
2317
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2318
     * @group create
2319
     * @group custom
2320
     */
2321
    public function testCreateCustomUrlAliasReusesNopElement()
2322
    {
2323
        $handler = $this->getHandler();
2324
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2325
2326
        $countBeforeReusing = $this->countRows();
2327
        $handler->createCustomUrlAlias(
2328
            314,
2329
            'nop-element',
2330
            true,
2331
            'cro-HR',
2332
            true
2333
        );
2334
2335
        self::assertEquals(
2336
            $countBeforeReusing,
2337
            $this->countRows()
2338
        );
2339
2340
        // Check that custom alias whose nop element was reused still works as expected
2341
        self::assertEquals(
2342
            new UrlAlias(
2343
                [
2344
                    'id' => '2-06a943c59f33a34bb5924aaf72cd2995',
2345
                    'type' => UrlAlias::RESOURCE,
2346
                    'destination' => 'content/search',
2347
                    'languageCodes' => ['eng-GB'],
2348
                    'pathData' => [
2349
                        [
2350
                            'always-available' => true,
2351
                            'translations' => ['cro-HR' => 'nop-element'],
2352
                        ],
2353
                        [
2354
                            'always-available' => false,
2355
                            'translations' => ['eng-GB' => 'search'],
2356
                        ],
2357
                    ],
2358
                    'alwaysAvailable' => false,
2359
                    'isHistory' => false,
2360
                    'isCustom' => true,
2361
                    'forward' => false,
2362
                ]
2363
            ),
2364
            $handler->lookup('nop-element/search')
2365
        );
2366
    }
2367
2368
    /**
2369
     * Test for the createUrlAlias() method.
2370
     *
2371
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2372
     * @group create
2373
     * @group custom
2374
     */
2375 View Code Duplication
    public function testCreateCustomUrlAliasReusesLocationElement()
2376
    {
2377
        $handler = $this->getHandler();
2378
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2379
2380
        $countBeforeReusing = $this->countRows();
2381
        $locationUrlAlias = $handler->lookup('autogenerated-hello');
2382
        $handler->createCustomUrlAlias(
2383
            315,
2384
            'autogenerated-hello/custom-location-alias-for-315',
2385
            true,
2386
            'cro-HR',
2387
            true
2388
        );
2389
2390
        self::assertEquals(
2391
            $countBeforeReusing + 1,
2392
            $this->countRows()
2393
        );
2394
2395
        // Check that location alias still works as expected
2396
        self::assertEquals(
2397
            $locationUrlAlias,
2398
            $handler->lookup('autogenerated-hello')
2399
        );
2400
    }
2401
2402
    /**
2403
     * Test for the listGlobalURLAliases() method.
2404
     *
2405
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2406
     * @depends testLookupResourceUrlAlias
2407
     */
2408
    public function testListGlobalURLAliases()
2409
    {
2410
        $handler = $this->getHandler();
2411
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2412
2413
        $globalAliasList = $handler->listGlobalURLAliases();
2414
2415
        self::assertEquals(
2416
            [
2417
                $handler->lookup('is-alive'),
2418
                $handler->lookup('is-alive/then/search'),
2419
                $handler->lookup('nop-element/search'),
2420
            ],
2421
            $globalAliasList
2422
        );
2423
    }
2424
2425
    /**
2426
     * Test for the listGlobalURLAliases() method.
2427
     *
2428
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2429
     * @depends testLookupResourceUrlAlias
2430
     */
2431 View Code Duplication
    public function testListGlobalURLAliasesWithLanguageCode()
2432
    {
2433
        $handler = $this->getHandler();
2434
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2435
2436
        $globalAliasList = $handler->listGlobalURLAliases('eng-GB');
2437
2438
        self::assertEquals(
2439
            [
2440
                $handler->lookup('is-alive'),
2441
                $handler->lookup('nop-element/search'),
2442
            ],
2443
            $globalAliasList
2444
        );
2445
    }
2446
2447
    /**
2448
     * Test for the listGlobalURLAliases() method.
2449
     *
2450
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2451
     * @depends testLookupResourceUrlAlias
2452
     */
2453
    public function testListGlobalURLAliasesWithOffset()
2454
    {
2455
        $handler = $this->getHandler();
2456
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2457
2458
        $globalAliasList = $handler->listGlobalURLAliases(null, 2);
2459
2460
        self::assertEquals(
2461
            [
2462
                $handler->lookup('nop-element/search'),
2463
            ],
2464
            $globalAliasList
2465
        );
2466
    }
2467
2468
    /**
2469
     * Test for the listGlobalURLAliases() method.
2470
     *
2471
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2472
     * @depends testLookupResourceUrlAlias
2473
     */
2474
    public function testListGlobalURLAliasesWithOffsetAndLimit()
2475
    {
2476
        $handler = $this->getHandler();
2477
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2478
2479
        $globalAliasList = $handler->listGlobalURLAliases(null, 1, 1);
2480
2481
        self::assertEquals(
2482
            [
2483
                $handler->lookup('is-alive/then/search'),
2484
            ],
2485
            $globalAliasList
2486
        );
2487
    }
2488
2489
    /**
2490
     * Test for the locationDeleted() method.
2491
     *
2492
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationDeleted
2493
     */
2494
    public function testLocationDeleted()
2495
    {
2496
        $handler = $this->getHandler();
2497
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_delete.php');
2498
2499
        $countBeforeDeleting = $this->countRows();
2500
2501
        $handler->locationDeleted(5);
2502
2503
        self::assertEquals(
2504
            $countBeforeDeleting - 5,
2505
            $this->countRows()
2506
        );
2507
2508
        self::assertEmpty(
2509
            $handler->listURLAliasesForLocation(5)
2510
        );
2511
2512
        $removedAliases = [
2513
            'moved-original-parent/moved-history',
2514
            'moved-original-parent/sub',
2515
            'moved-original-parent',
2516
            'moved-original-parent-history',
2517
            'custom-below/moved-original-parent-custom',
2518
        ];
2519
        foreach ($removedAliases as $path) {
2520
            try {
2521
                $handler->lookup($path);
2522
                $this->fail("Alias '$path' not removed!");
2523
            } catch (NotFoundException $e) {
2524
                // Do nothing
2525
            }
2526
        }
2527
    }
2528
2529
    /**
2530
     * Test for the locationMoved() method.
2531
     *
2532
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2533
     */
2534 View Code Duplication
    public function testLocationMovedHistorize()
2535
    {
2536
        $handler = $this->getHandler();
2537
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2538
2539
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2540
        $handler->locationMoved(4, 2, 3);
2541
2542
        $urlAlias = $handler->lookup('move-this');
2543
        self::assertEquals(
2544
            new UrlAlias(
2545
                [
2546
                    'id' => '0-' . md5('move-this'),
2547
                    'type' => UrlAlias::LOCATION,
2548
                    'destination' => '4',
2549
                    'languageCodes' => ['eng-GB'],
2550
                    'pathData' => [
2551
                        [
2552
                            'always-available' => false,
2553
                            'translations' => ['eng-GB' => 'move-this'],
2554
                        ],
2555
                    ],
2556
                    'alwaysAvailable' => false,
2557
                    'isHistory' => true,
2558
                    'isCustom' => false,
2559
                    'forward' => false,
2560
                ]
2561
            ),
2562
            $urlAlias
2563
        );
2564
    }
2565
2566
    /**
2567
     * Test for the locationMoved() method.
2568
     *
2569
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2570
     */
2571 View Code Duplication
    public function testLocationMovedHistory()
2572
    {
2573
        $handler = $this->getHandler();
2574
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2575
2576
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2577
        $handler->locationMoved(4, 2, 3);
2578
2579
        $urlAlias = $handler->lookup('move-this-history');
2580
        self::assertEquals(
2581
            new UrlAlias(
2582
                [
2583
                    'id' => '0-' . md5('move-this-history'),
2584
                    'type' => UrlAlias::LOCATION,
2585
                    'destination' => '4',
2586
                    'languageCodes' => ['eng-GB'],
2587
                    'pathData' => [
2588
                        [
2589
                            'always-available' => false,
2590
                            'translations' => ['eng-GB' => 'move-this-history'],
2591
                        ],
2592
                    ],
2593
                    'alwaysAvailable' => false,
2594
                    'isHistory' => true,
2595
                    'isCustom' => false,
2596
                    'forward' => false,
2597
                ]
2598
            ),
2599
            $urlAlias
2600
        );
2601
    }
2602
2603
    /**
2604
     * Test for the locationMoved() method.
2605
     *
2606
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2607
     */
2608 View Code Duplication
    public function testLocationMovedHistorySubtree()
2609
    {
2610
        $handler = $this->getHandler();
2611
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2612
2613
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2614
        $handler->locationMoved(4, 2, 3);
2615
2616
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2617
        self::assertEquals(
2618
            new UrlAlias(
2619
                [
2620
                    'id' => '5-' . md5('sub2'),
2621
                    'type' => UrlAlias::LOCATION,
2622
                    'destination' => '6',
2623
                    'languageCodes' => ['eng-GB'],
2624
                    'pathData' => [
2625
                        [
2626
                            'always-available' => false,
2627
                            'translations' => ['eng-GB' => 'move-this'],
2628
                        ],
2629
                        [
2630
                            'always-available' => false,
2631
                            'translations' => ['eng-GB' => 'sub1'],
2632
                        ],
2633
                        [
2634
                            'always-available' => false,
2635
                            'translations' => ['eng-GB' => 'sub2'],
2636
                        ],
2637
                    ],
2638
                    'alwaysAvailable' => false,
2639
                    'isHistory' => true,
2640
                    'isCustom' => false,
2641
                    'forward' => false,
2642
                ]
2643
            ),
2644
            $urlAlias
2645
        );
2646
    }
2647
2648
    /**
2649
     * Test for the locationMoved() method.
2650
     *
2651
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2652
     */
2653 View Code Duplication
    public function testLocationMovedReparent()
2654
    {
2655
        $handler = $this->getHandler();
2656
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2657
2658
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2659
        $handler->locationMoved(4, 2, 3);
2660
2661
        $urlAlias = $handler->lookup('move-here/move-this/sub1');
2662
        self::assertEquals(
2663
            new UrlAlias(
2664
                [
2665
                    'id' => '9-' . md5('sub1'),
2666
                    'type' => UrlAlias::LOCATION,
2667
                    'destination' => '5',
2668
                    'languageCodes' => ['eng-GB'],
2669
                    'pathData' => [
2670
                        [
2671
                            'always-available' => false,
2672
                            'translations' => ['eng-GB' => 'move-here'],
2673
                        ],
2674
                        [
2675
                            'always-available' => false,
2676
                            'translations' => ['eng-GB' => 'move-this'],
2677
                        ],
2678
                        [
2679
                            'always-available' => false,
2680
                            'translations' => ['eng-GB' => 'sub1'],
2681
                        ],
2682
                    ],
2683
                    'alwaysAvailable' => false,
2684
                    'isHistory' => false,
2685
                    'isCustom' => false,
2686
                    'forward' => false,
2687
                ]
2688
            ),
2689
            $urlAlias
2690
        );
2691
    }
2692
2693
    /**
2694
     * Test for the locationMoved() method.
2695
     *
2696
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2697
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2698
     */
2699 View Code Duplication
    public function testLocationMovedReparentHistory()
2700
    {
2701
        $handler = $this->getHandler();
2702
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2703
2704
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2705
        $handler->locationMoved(4, 2, 3);
2706
2707
        $handler->lookup('move-here/move-this-history');
2708
    }
2709
2710
    /**
2711
     * Test for the locationMoved() method.
2712
     *
2713
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2714
     */
2715 View Code Duplication
    public function testLocationMovedReparentSubtree()
2716
    {
2717
        $handler = $this->getHandler();
2718
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2719
2720
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2721
        $handler->locationMoved(4, 2, 3);
2722
2723
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2724
        self::assertEquals(
2725
            new UrlAlias(
2726
                [
2727
                    'id' => '5-' . md5('sub2'),
2728
                    'type' => UrlAlias::LOCATION,
2729
                    'destination' => '6',
2730
                    'languageCodes' => ['eng-GB'],
2731
                    'pathData' => [
2732
                        [
2733
                            'always-available' => false,
2734
                            'translations' => ['eng-GB' => 'move-here'],
2735
                        ],
2736
                        [
2737
                            'always-available' => false,
2738
                            'translations' => ['eng-GB' => 'move-this'],
2739
                        ],
2740
                        [
2741
                            'always-available' => false,
2742
                            'translations' => ['eng-GB' => 'sub1'],
2743
                        ],
2744
                        [
2745
                            'always-available' => false,
2746
                            'translations' => ['eng-GB' => 'sub2'],
2747
                        ],
2748
                    ],
2749
                    'alwaysAvailable' => false,
2750
                    'isHistory' => false,
2751
                    'isCustom' => false,
2752
                    'forward' => false,
2753
                ]
2754
            ),
2755
            $urlAlias
2756
        );
2757
    }
2758
2759
    /**
2760
     * Test for the locationMoved() method.
2761
     *
2762
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2763
     */
2764 View Code Duplication
    public function testLocationMovedReparentSubtreeHistory()
2765
    {
2766
        $handler = $this->getHandler();
2767
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2768
2769
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2770
        $handler->locationMoved(4, 2, 3);
2771
2772
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2-history');
2773
        self::assertEquals(
2774
            new UrlAlias(
2775
                [
2776
                    'id' => '5-' . md5('sub2-history'),
2777
                    'type' => UrlAlias::LOCATION,
2778
                    'destination' => '6',
2779
                    'languageCodes' => ['eng-GB'],
2780
                    'pathData' => [
2781
                        [
2782
                            'always-available' => false,
2783
                            'translations' => ['eng-GB' => 'move-here'],
2784
                        ],
2785
                        [
2786
                            'always-available' => false,
2787
                            'translations' => ['eng-GB' => 'move-this'],
2788
                        ],
2789
                        [
2790
                            'always-available' => false,
2791
                            'translations' => ['eng-GB' => 'sub1'],
2792
                        ],
2793
                        [
2794
                            'always-available' => false,
2795
                            'translations' => ['eng-GB' => 'sub2-history'],
2796
                        ],
2797
                    ],
2798
                    'alwaysAvailable' => false,
2799
                    'isHistory' => true,
2800
                    'isCustom' => false,
2801
                    'forward' => false,
2802
                ]
2803
            ),
2804
            $urlAlias
2805
        );
2806
    }
2807
2808
    /**
2809
     * Test for the locationCopied() method.
2810
     *
2811
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2812
     */
2813 View Code Duplication
    public function testLocationCopiedCopiedLocationAliasIsValid()
2814
    {
2815
        $handler = $this->getHandler();
2816
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2817
2818
        $urlAlias = $handler->lookup('move-this');
2819
2820
        $handler->locationCopied(4, 400, 3);
2821
2822
        self::assertEquals(
2823
            $urlAlias,
2824
            $handler->lookup('move-this')
2825
        );
2826
    }
2827
2828
    /**
2829
     * Test for the locationCopied() method.
2830
     *
2831
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2832
     */
2833 View Code Duplication
    public function testLocationCopiedCopiedSubtreeIsValid()
2834
    {
2835
        $handler = $this->getHandler();
2836
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2837
2838
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2839
2840
        $handler->locationCopied(4, 400, 3);
2841
2842
        self::assertEquals(
2843
            $urlAlias,
2844
            $handler->lookup('move-this/sub1/sub2')
2845
        );
2846
    }
2847
2848
    /**
2849
     * Test for the locationCopied() method.
2850
     *
2851
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2852
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2853
     */
2854 View Code Duplication
    public function testLocationCopiedHistoryNotCopied()
2855
    {
2856
        $handler = $this->getHandler();
2857
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2858
2859
        $handler->locationCopied(4, 400, 3);
2860
2861
        $handler->lookup('move-here/move-this-history');
2862
    }
2863
2864
    /**
2865
     * Test for the locationCopied() method.
2866
     *
2867
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2868
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2869
     */
2870 View Code Duplication
    public function testLocationCopiedSubtreeHistoryNotCopied()
2871
    {
2872
        $handler = $this->getHandler();
2873
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2874
2875
        $handler->locationCopied(4, 400, 3);
2876
2877
        $handler->lookup('move-here/move-this/sub1/sub2-history');
2878
    }
2879
2880
    /**
2881
     * Test for the locationCopied() method.
2882
     *
2883
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2884
     */
2885
    public function testLocationCopiedSubtree()
2886
    {
2887
        $handler = $this->getHandler();
2888
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2889
2890
        $countBeforeCopying = $this->countRows();
2891
2892
        $handler->locationCopied(4, 400, 3);
2893
2894
        self::assertEquals(
2895
            $countBeforeCopying + 2,
2896
            $this->countRows()
2897
        );
2898
2899
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2900
        self::assertEquals(
2901
            new UrlAlias(
2902
                [
2903
                    'id' => '10-' . md5('sub2'),
2904
                    'type' => UrlAlias::LOCATION,
2905
                    'destination' => 600,
2906
                    'languageCodes' => ['eng-GB'],
2907
                    'pathData' => [
2908
                        [
2909
                            'always-available' => false,
2910
                            'translations' => ['eng-GB' => 'move-here'],
2911
                        ],
2912
                        [
2913
                            'always-available' => false,
2914
                            'translations' => ['eng-GB' => 'move-this'],
2915
                        ],
2916
                        [
2917
                            'always-available' => false,
2918
                            'translations' => ['eng-GB' => 'sub1'],
2919
                        ],
2920
                        [
2921
                            'always-available' => false,
2922
                            'translations' => ['eng-GB' => 'sub2'],
2923
                        ],
2924
                    ],
2925
                    'alwaysAvailable' => false,
2926
                    'isHistory' => false,
2927
                    'isCustom' => false,
2928
                    'forward' => false,
2929
                ]
2930
            ),
2931
            $urlAlias
2932
        );
2933
    }
2934
2935
    /**
2936
     * Test for the loadUrlAlias() method.
2937
     *
2938
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2939
     * @dataProvider providerForTestLookupLocationMultipleLanguages
2940
     */
2941 View Code Duplication
    public function testLoadAutogeneratedUrlAlias(
2942
        $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...
2943
        array $pathData,
2944
        array $languageCodes,
2945
        $alwaysAvailable,
2946
        $locationId,
2947
        $id
2948
    ) {
2949
        $handler = $this->getHandler();
2950
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
2951
2952
        $urlAlias = $handler->loadUrlAlias($id);
2953
2954
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
2955
        self::assertEquals(
2956
            new UrlAlias(
2957
                [
2958
                    'id' => $id,
2959
                    'type' => UrlAlias::LOCATION,
2960
                    'destination' => $locationId,
2961
                    'languageCodes' => $languageCodes,
2962
                    'pathData' => $pathData,
2963
                    'alwaysAvailable' => $alwaysAvailable,
2964
                    'isHistory' => false,
2965
                    'isCustom' => false,
2966
                    'forward' => false,
2967
                ]
2968
            ),
2969
            $urlAlias
2970
        );
2971
    }
2972
2973
    /**
2974
     * Test for the loadUrlAlias() method.
2975
     *
2976
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2977
     * @dataProvider providerForTestLookupResourceUrlAlias
2978
     */
2979 View Code Duplication
    public function testLoadResourceUrlAlias(
2980
        $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...
2981
        $pathData,
2982
        array $languageCodes,
2983
        $forward,
2984
        $alwaysAvailable,
2985
        $destination,
2986
        $id
2987
    ) {
2988
        $handler = $this->getHandler();
2989
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2990
2991
        $urlAlias = $handler->loadUrlAlias($id);
2992
2993
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
2994
        self::assertEquals(
2995
            new UrlAlias(
2996
                [
2997
                    'id' => $id,
2998
                    'type' => UrlAlias::RESOURCE,
2999
                    'destination' => $destination,
3000
                    'languageCodes' => $languageCodes,
3001
                    'pathData' => $pathData,
3002
                    'alwaysAvailable' => $alwaysAvailable,
3003
                    'isHistory' => false,
3004
                    'isCustom' => true,
3005
                    'forward' => $forward,
3006
                ]
3007
            ),
3008
            $urlAlias
3009
        );
3010
    }
3011
3012
    /**
3013
     * Test for the loadUrlAlias() method.
3014
     *
3015
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3016
     * @dataProvider providerForTestLookupVirtualUrlAlias
3017
     */
3018 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...
3019
    {
3020
        $handler = $this->getHandler();
3021
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
3022
3023
        $urlAlias = $handler->loadUrlAlias($id);
3024
3025
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
3026
    }
3027
3028
    protected function getHistoryAlias()
3029
    {
3030
        return new UrlAlias(
3031
            [
3032
                'id' => '3-5f46413bb0ba5998caef84ab1ea590e1',
3033
                'type' => UrlAlias::LOCATION,
3034
                'destination' => '316',
3035
                'pathData' => [
3036
                    [
3037
                        'always-available' => true,
3038
                        'translations' => ['cro-HR' => 'jedan'],
3039
                    ],
3040
                    [
3041
                        'always-available' => false,
3042
                        'translations' => [
3043
                            'cro-HR' => 'dva',
3044
                            'eng-GB' => 'two',
3045
                        ],
3046
                    ],
3047
                    [
3048
                        'always-available' => false,
3049
                        'translations' => [
3050
                            'cro-HR' => 'tri-history',
3051
                        ],
3052
                    ],
3053
                ],
3054
                'languageCodes' => ['cro-HR'],
3055
                'alwaysAvailable' => false,
3056
                'isHistory' => true,
3057
                'isCustom' => false,
3058
                'forward' => false,
3059
            ]
3060
        );
3061
    }
3062
3063
    /**
3064
     * Test for the loadUrlAlias() method.
3065
     *
3066
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3067
     */
3068
    public function testLoadHistoryUrlAlias()
3069
    {
3070
        $handler = $this->getHandler();
3071
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
3072
3073
        $historyAlias = $this->getHistoryAlias();
3074
        $urlAlias = $handler->loadUrlAlias($historyAlias->id);
3075
3076
        self::assertEquals(
3077
            $historyAlias,
3078
            $urlAlias
3079
        );
3080
    }
3081
3082
    /**
3083
     * Test for the loadUrlAlias() method.
3084
     *
3085
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3086
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3087
     */
3088
    public function testLoadUrlAliasThrowsNotFoundException()
3089
    {
3090
        $handler = $this->getHandler();
3091
3092
        $handler->loadUrlAlias('non-existent');
3093
    }
3094
3095
    public function providerForTestPublishUrlAliasForLocationSkipsReservedWord()
3096
    {
3097
        return [
3098
            [
3099
                'section',
3100
                'section2',
3101
            ],
3102
            [
3103
                'claß',
3104
                'class2',
3105
            ],
3106
        ];
3107
    }
3108
3109
    /**
3110
     * Test for the publishUrlAliasForLocation() method.
3111
     *
3112
     * @dataProvider providerForTestPublishUrlAliasForLocationSkipsReservedWord
3113
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
3114
     * @group publish
3115
     */
3116
    public function testPublishUrlAliasForLocationSkipsReservedWord($text, $alias)
3117
    {
3118
        $handler = $this->getHandler();
3119
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
3120
3121
        $handler->publishUrlAliasForLocation(314, 2, $text, 'kli-KR');
3122
3123
        $urlAlias = $handler->lookup($alias);
3124
3125
        $this->assertEquals(314, $urlAlias->destination);
3126
        $this->assertEquals(['kli-KR'], $urlAlias->languageCodes);
3127
    }
3128
3129
    /**
3130
     * Test for the locationSwapped() method.
3131
     *
3132
     * @group swap
3133
     */
3134
    public function testLocationSwappedSimple()
3135
    {
3136
        $handler = $this->getHandler();
3137
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple.php');
3138
3139
        $countBeforeReusing = $this->countRows();
3140
3141
        $handler->locationSwapped(316, 314, 317, 315);
3142
3143
        $this->assertEquals(
3144
            $countBeforeReusing,
3145
            $this->countRows()
3146
        );
3147
3148
        $urlAlias = $handler->lookup('jedan/swap');
3149
        $this->assertEquals(
3150
            new UrlAlias(
3151
                [
3152
                    'id' => '2-' . md5('swap'),
3153
                    'type' => UrlAlias::LOCATION,
3154
                    'destination' => 316,
3155
                    'languageCodes' => [
3156
                        'cro-HR',
3157
                    ],
3158
                    'pathData' => [
3159
                        [
3160
                            'always-available' => false,
3161
                            'translations' => [
3162
                                'cro-HR' => 'jedan',
3163
                            ],
3164
                        ],
3165
                        [
3166
                            'always-available' => false,
3167
                            'translations' => [
3168
                                'cro-HR' => 'swap',
3169
                            ],
3170
                        ],
3171
                    ],
3172
                    'alwaysAvailable' => false,
3173
                    'isHistory' => false,
3174
                    'isCustom' => false,
3175
                    'forward' => false,
3176
                ]
3177
            ),
3178
            $urlAlias
3179
        );
3180
3181
        $urlAlias = $handler->lookup('dva/swap');
3182
        $this->assertEquals(
3183
            new UrlAlias(
3184
                [
3185
                    'id' => '3-' . md5('swap'),
3186
                    'type' => UrlAlias::LOCATION,
3187
                    'destination' => 317,
3188
                    'languageCodes' => [
3189
                        'cro-HR',
3190
                    ],
3191
                    'pathData' => [
3192
                        [
3193
                            'always-available' => false,
3194
                            'translations' => [
3195
                                'cro-HR' => 'dva',
3196
                            ],
3197
                        ],
3198
                        [
3199
                            'always-available' => false,
3200
                            'translations' => [
3201
                                'cro-HR' => 'swap',
3202
                            ],
3203
                        ],
3204
                    ],
3205
                    'alwaysAvailable' => false,
3206
                    'isHistory' => false,
3207
                    'isCustom' => false,
3208
                    'forward' => false,
3209
                ]
3210
            ),
3211
            $urlAlias
3212
        );
3213
    }
3214
3215
    /**
3216
     * Test for the locationSwapped() method.
3217
     *
3218
     * @group swap
3219
     */
3220 View Code Duplication
    public function testLocationSwappedSimpleWithHistory()
3221
    {
3222
        $handler = $this->getHandler();
3223
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_history.php');
3224
3225
        $countBeforeReusing = $this->countRows();
3226
3227
        $handler->locationSwapped(316, 314, 317, 315);
3228
3229
        $this->assertEquals(
3230
            $countBeforeReusing,
3231
            $this->countRows()
3232
        );
3233
3234
        $urlAlias = $handler->lookup('jedan/swap');
3235
        $this->assertEquals(
3236
            new UrlAlias(
3237
                [
3238
                    'id' => '2-' . md5('swap'),
3239
                    'type' => UrlAlias::LOCATION,
3240
                    'destination' => 316,
3241
                    'languageCodes' => [
3242
                        'cro-HR',
3243
                    ],
3244
                    'pathData' => [
3245
                        [
3246
                            'always-available' => false,
3247
                            'translations' => [
3248
                                'cro-HR' => 'jedan',
3249
                            ],
3250
                        ],
3251
                        [
3252
                            'always-available' => false,
3253
                            'translations' => [
3254
                                'cro-HR' => 'swap',
3255
                            ],
3256
                        ],
3257
                    ],
3258
                    'alwaysAvailable' => false,
3259
                    'isHistory' => true,
3260
                    'isCustom' => false,
3261
                    'forward' => false,
3262
                ]
3263
            ),
3264
            $urlAlias
3265
        );
3266
3267
        $urlAlias = $handler->lookup('dva/swap');
3268
        $this->assertEquals(
3269
            new UrlAlias(
3270
                [
3271
                    'id' => '3-' . md5('swap'),
3272
                    'type' => UrlAlias::LOCATION,
3273
                    'destination' => 317,
3274
                    'languageCodes' => [
3275
                        'cro-HR',
3276
                    ],
3277
                    'pathData' => [
3278
                        [
3279
                            'always-available' => false,
3280
                            'translations' => [
3281
                                'cro-HR' => 'dva',
3282
                            ],
3283
                        ],
3284
                        [
3285
                            'always-available' => false,
3286
                            'translations' => [
3287
                                'cro-HR' => 'swap',
3288
                            ],
3289
                        ],
3290
                    ],
3291
                    'alwaysAvailable' => false,
3292
                    'isHistory' => true,
3293
                    'isCustom' => false,
3294
                    'forward' => false,
3295
                ]
3296
            ),
3297
            $urlAlias
3298
        );
3299
3300
        $urlAlias = $handler->lookup('jedan/swap-new');
3301
        $this->assertEquals(
3302
            new UrlAlias(
3303
                [
3304
                    'id' => '2-' . md5('swap-new'),
3305
                    'type' => UrlAlias::LOCATION,
3306
                    'destination' => 316,
3307
                    'languageCodes' => [
3308
                        'cro-HR',
3309
                    ],
3310
                    'pathData' => [
3311
                        [
3312
                            'always-available' => false,
3313
                            'translations' => [
3314
                                'cro-HR' => 'jedan',
3315
                            ],
3316
                        ],
3317
                        [
3318
                            'always-available' => false,
3319
                            'translations' => [
3320
                                'cro-HR' => 'swap-new',
3321
                            ],
3322
                        ],
3323
                    ],
3324
                    'alwaysAvailable' => false,
3325
                    'isHistory' => false,
3326
                    'isCustom' => false,
3327
                    'forward' => false,
3328
                ]
3329
            ),
3330
            $urlAlias
3331
        );
3332
3333
        $urlAlias = $handler->lookup('dva/swap-new');
3334
        $this->assertEquals(
3335
            new UrlAlias(
3336
                [
3337
                    'id' => '3-' . md5('swap-new'),
3338
                    'type' => UrlAlias::LOCATION,
3339
                    'destination' => 317,
3340
                    'languageCodes' => [
3341
                        'cro-HR',
3342
                    ],
3343
                    'pathData' => [
3344
                        [
3345
                            'always-available' => false,
3346
                            'translations' => [
3347
                                'cro-HR' => 'dva',
3348
                            ],
3349
                        ],
3350
                        [
3351
                            'always-available' => false,
3352
                            'translations' => [
3353
                                'cro-HR' => 'swap-new',
3354
                            ],
3355
                        ],
3356
                    ],
3357
                    'alwaysAvailable' => false,
3358
                    'isHistory' => false,
3359
                    'isCustom' => false,
3360
                    'forward' => false,
3361
                ]
3362
            ),
3363
            $urlAlias
3364
        );
3365
    }
3366
3367
    /**
3368
     * Test for the locationSwapped() method.
3369
     *
3370
     * @group swap
3371
     */
3372
    public function testLocationSwappedSimpleWithConflict()
3373
    {
3374
        $handler = $this->getHandler();
3375
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_conflict.php');
3376
3377
        $urlAlias1TakenExpected = $handler->lookup('jedan/swap-new-2');
3378
        $urlAlias2TakenExpected = $handler->lookup('dva/swap-new-1');
3379
3380
        $urlAlias1HistorizedExpected = $handler->lookup('jedan/swap-new-1');
3381
        $urlAlias1HistorizedExpected->isHistory = true;
3382
        $urlAlias2HistorizedExpected = $handler->lookup('dva/swap-new-2');
3383
        $urlAlias2HistorizedExpected->isHistory = true;
3384
3385
        $countBeforeReusing = $this->countRows();
3386
3387
        $handler->locationSwapped(316, 314, 317, 315);
3388
3389
        $this->assertEquals(
3390
            $countBeforeReusing + 2,
3391
            $this->countRows()
3392
        );
3393
3394
        $urlAlias1Taken = $handler->lookup('jedan/swap-new-2');
3395
        $urlAlias2Taken = $handler->lookup('dva/swap-new-1');
3396
3397
        $urlAlias1Historized = $handler->lookup('jedan/swap-new-1');
3398
        $urlAlias2Historized = $handler->lookup('dva/swap-new-2');
3399
3400
        $this->assertEquals($urlAlias1TakenExpected, $urlAlias1Taken);
3401
        $this->assertEquals($urlAlias2TakenExpected, $urlAlias2Taken);
3402
3403
        $this->assertEquals($urlAlias1HistorizedExpected, $urlAlias1Historized);
3404
        $this->assertEquals($urlAlias2HistorizedExpected, $urlAlias2Historized);
3405
3406
        $urlAlias1New = $handler->lookup('jedan/swap-new-22');
3407
        $this->assertEquals(
3408
            new UrlAlias(
3409
                [
3410
                    'id' => '2-' . md5('swap-new-22'),
3411
                    'type' => UrlAlias::LOCATION,
3412
                    'destination' => 316,
3413
                    'languageCodes' => [
3414
                        'cro-HR',
3415
                    ],
3416
                    'pathData' => [
3417
                        [
3418
                            'always-available' => false,
3419
                            'translations' => [
3420
                                'cro-HR' => 'jedan',
3421
                            ],
3422
                        ],
3423
                        [
3424
                            'always-available' => false,
3425
                            'translations' => [
3426
                                'cro-HR' => 'swap-new-22',
3427
                            ],
3428
                        ],
3429
                    ],
3430
                    'alwaysAvailable' => false,
3431
                    'isHistory' => false,
3432
                    'isCustom' => false,
3433
                    'forward' => false,
3434
                ]
3435
            ),
3436
            $urlAlias1New
3437
        );
3438
3439
        $urlAlias2New = $handler->lookup('dva/swap-new-12');
3440
        $this->assertEquals(
3441
            new UrlAlias(
3442
                [
3443
                    'id' => '3-' . md5('swap-new-12'),
3444
                    'type' => UrlAlias::LOCATION,
3445
                    'destination' => 317,
3446
                    'languageCodes' => [
3447
                        'cro-HR',
3448
                    ],
3449
                    'pathData' => [
3450
                        [
3451
                            'always-available' => false,
3452
                            'translations' => [
3453
                                'cro-HR' => 'dva',
3454
                            ],
3455
                        ],
3456
                        [
3457
                            'always-available' => false,
3458
                            'translations' => [
3459
                                'cro-HR' => 'swap-new-12',
3460
                            ],
3461
                        ],
3462
                    ],
3463
                    'alwaysAvailable' => false,
3464
                    'isHistory' => false,
3465
                    'isCustom' => false,
3466
                    'forward' => false,
3467
                ]
3468
            ),
3469
            $urlAlias2New
3470
        );
3471
    }
3472
3473
    /**
3474
     * Test for the locationSwapped() method.
3475
     *
3476
     * @group swap
3477
     */
3478 View Code Duplication
    public function testLocationSwappedSiblingsSimple()
3479
    {
3480
        $handler = $this->getHandler();
3481
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3482
3483
        $countBeforeReusing = $this->countRows();
3484
3485
        $handler->locationSwapped(314, 2, 315, 2);
3486
3487
        $this->assertEquals(
3488
            $countBeforeReusing,
3489
            $this->countRows()
3490
        );
3491
3492
        $urlAlias = $handler->lookup('jedan');
3493
        $this->assertEquals(
3494
            new UrlAlias(
3495
                [
3496
                    'id' => '0-' . md5('jedan'),
3497
                    'type' => UrlAlias::LOCATION,
3498
                    'destination' => 315,
3499
                    'languageCodes' => [
3500
                        'cro-HR',
3501
                    ],
3502
                    'pathData' => [
3503
                        [
3504
                            'always-available' => false,
3505
                            'translations' => [
3506
                                'cro-HR' => 'jedan',
3507
                            ],
3508
                        ],
3509
                    ],
3510
                    'alwaysAvailable' => false,
3511
                    'isHistory' => false,
3512
                    'isCustom' => false,
3513
                    'forward' => false,
3514
                ]
3515
            ),
3516
            $urlAlias
3517
        );
3518
3519
        $urlAlias = $handler->lookup('dva');
3520
        $this->assertEquals(
3521
            new UrlAlias(
3522
                [
3523
                    'id' => '0-' . md5('dva'),
3524
                    'type' => UrlAlias::LOCATION,
3525
                    'destination' => 314,
3526
                    'languageCodes' => [
3527
                        'cro-HR',
3528
                    ],
3529
                    'pathData' => [
3530
                        [
3531
                            'always-available' => false,
3532
                            'translations' => [
3533
                                'cro-HR' => 'dva',
3534
                            ],
3535
                        ],
3536
                    ],
3537
                    'alwaysAvailable' => false,
3538
                    'isHistory' => false,
3539
                    'isCustom' => false,
3540
                    'forward' => false,
3541
                ]
3542
            ),
3543
            $urlAlias
3544
        );
3545
    }
3546
3547
    /**
3548
     * Test for the locationSwapped() method.
3549
     *
3550
     * @group swap
3551
     */
3552 View Code Duplication
    public function testLocationSwappedSiblingsSimpleReverse()
3553
    {
3554
        $handler = $this->getHandler();
3555
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3556
3557
        $countBeforeReusing = $this->countRows();
3558
3559
        $handler->locationSwapped(315, 2, 314, 2);
3560
3561
        $this->assertEquals(
3562
            $countBeforeReusing,
3563
            $this->countRows()
3564
        );
3565
3566
        $urlAlias = $handler->lookup('jedan');
3567
        $this->assertEquals(
3568
            new UrlAlias(
3569
                [
3570
                    'id' => '0-' . md5('jedan'),
3571
                    'type' => UrlAlias::LOCATION,
3572
                    'destination' => 315,
3573
                    'languageCodes' => [
3574
                        'cro-HR',
3575
                    ],
3576
                    'pathData' => [
3577
                        [
3578
                            'always-available' => false,
3579
                            'translations' => [
3580
                                'cro-HR' => 'jedan',
3581
                            ],
3582
                        ],
3583
                    ],
3584
                    'alwaysAvailable' => false,
3585
                    'isHistory' => false,
3586
                    'isCustom' => false,
3587
                    'forward' => false,
3588
                ]
3589
            ),
3590
            $urlAlias
3591
        );
3592
3593
        $urlAlias = $handler->lookup('dva');
3594
        $this->assertEquals(
3595
            new UrlAlias(
3596
                [
3597
                    'id' => '0-' . md5('dva'),
3598
                    'type' => UrlAlias::LOCATION,
3599
                    'destination' => 314,
3600
                    'languageCodes' => [
3601
                        'cro-HR',
3602
                    ],
3603
                    'pathData' => [
3604
                        [
3605
                            'always-available' => false,
3606
                            'translations' => [
3607
                                'cro-HR' => 'dva',
3608
                            ],
3609
                        ],
3610
                    ],
3611
                    'alwaysAvailable' => false,
3612
                    'isHistory' => false,
3613
                    'isCustom' => false,
3614
                    'forward' => false,
3615
                ]
3616
            ),
3617
            $urlAlias
3618
        );
3619
    }
3620
3621
    /**
3622
     * Test for the locationSwapped() method.
3623
     *
3624
     * @group swap
3625
     */
3626 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistory()
3627
    {
3628
        $handler = $this->getHandler();
3629
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3630
3631
        $countBeforeReusing = $this->countRows();
3632
3633
        $handler->locationSwapped(314, 2, 315, 2);
3634
3635
        $this->assertEquals(
3636
            $countBeforeReusing,
3637
            $this->countRows()
3638
        );
3639
3640
        $urlAlias = $handler->lookup('jedan');
3641
        $this->assertEquals(
3642
            new UrlAlias(
3643
                [
3644
                    'id' => '0-' . md5('jedan'),
3645
                    'type' => UrlAlias::LOCATION,
3646
                    'destination' => 314,
3647
                    'languageCodes' => [
3648
                        'cro-HR',
3649
                    ],
3650
                    'pathData' => [
3651
                        [
3652
                            'always-available' => false,
3653
                            'translations' => [
3654
                                'cro-HR' => 'jedan',
3655
                            ],
3656
                        ],
3657
                    ],
3658
                    'alwaysAvailable' => false,
3659
                    'isHistory' => true,
3660
                    'isCustom' => false,
3661
                    'forward' => false,
3662
                ]
3663
            ),
3664
            $urlAlias
3665
        );
3666
3667
        $urlAlias = $handler->lookup('dva');
3668
        $this->assertEquals(
3669
            new UrlAlias(
3670
                [
3671
                    'id' => '0-' . md5('dva'),
3672
                    'type' => UrlAlias::LOCATION,
3673
                    'destination' => 315,
3674
                    'languageCodes' => [
3675
                        'cro-HR',
3676
                    ],
3677
                    'pathData' => [
3678
                        [
3679
                            'always-available' => false,
3680
                            'translations' => [
3681
                                'cro-HR' => 'dva',
3682
                            ],
3683
                        ],
3684
                    ],
3685
                    'alwaysAvailable' => false,
3686
                    'isHistory' => true,
3687
                    'isCustom' => false,
3688
                    'forward' => false,
3689
                ]
3690
            ),
3691
            $urlAlias
3692
        );
3693
3694
        $urlAlias = $handler->lookup('jedan-new');
3695
        $this->assertEquals(
3696
            new UrlAlias(
3697
                [
3698
                    'id' => '0-' . md5('jedan-new'),
3699
                    'type' => UrlAlias::LOCATION,
3700
                    'destination' => 315,
3701
                    'languageCodes' => [
3702
                        'cro-HR',
3703
                    ],
3704
                    'pathData' => [
3705
                        [
3706
                            'always-available' => false,
3707
                            'translations' => [
3708
                                'cro-HR' => 'jedan-new',
3709
                            ],
3710
                        ],
3711
                    ],
3712
                    'alwaysAvailable' => false,
3713
                    'isHistory' => false,
3714
                    'isCustom' => false,
3715
                    'forward' => false,
3716
                ]
3717
            ),
3718
            $urlAlias
3719
        );
3720
3721
        $urlAlias = $handler->lookup('dva-new');
3722
        $this->assertEquals(
3723
            new UrlAlias(
3724
                [
3725
                    'id' => '0-' . md5('dva-new'),
3726
                    'type' => UrlAlias::LOCATION,
3727
                    'destination' => 314,
3728
                    'languageCodes' => [
3729
                        'cro-HR',
3730
                    ],
3731
                    'pathData' => [
3732
                        [
3733
                            'always-available' => false,
3734
                            'translations' => [
3735
                                'cro-HR' => 'dva-new',
3736
                            ],
3737
                        ],
3738
                    ],
3739
                    'alwaysAvailable' => false,
3740
                    'isHistory' => false,
3741
                    'isCustom' => false,
3742
                    'forward' => false,
3743
                ]
3744
            ),
3745
            $urlAlias
3746
        );
3747
    }
3748
3749
    /**
3750
     * Test for the locationSwapped() method.
3751
     *
3752
     * @group swap
3753
     */
3754 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistoryReverse()
3755
    {
3756
        $handler = $this->getHandler();
3757
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3758
3759
        $countBeforeReusing = $this->countRows();
3760
3761
        $handler->locationSwapped(315, 2, 314, 2);
3762
3763
        $this->assertEquals(
3764
            $countBeforeReusing,
3765
            $this->countRows()
3766
        );
3767
3768
        $urlAlias = $handler->lookup('jedan');
3769
        $this->assertEquals(
3770
            new UrlAlias(
3771
                [
3772
                    'id' => '0-' . md5('jedan'),
3773
                    'type' => UrlAlias::LOCATION,
3774
                    'destination' => 314,
3775
                    'languageCodes' => [
3776
                        'cro-HR',
3777
                    ],
3778
                    'pathData' => [
3779
                        [
3780
                            'always-available' => false,
3781
                            'translations' => [
3782
                                'cro-HR' => 'jedan',
3783
                            ],
3784
                        ],
3785
                    ],
3786
                    'alwaysAvailable' => false,
3787
                    'isHistory' => true,
3788
                    'isCustom' => false,
3789
                    'forward' => false,
3790
                ]
3791
            ),
3792
            $urlAlias
3793
        );
3794
3795
        $urlAlias = $handler->lookup('dva');
3796
        $this->assertEquals(
3797
            new UrlAlias(
3798
                [
3799
                    'id' => '0-' . md5('dva'),
3800
                    'type' => UrlAlias::LOCATION,
3801
                    'destination' => 315,
3802
                    'languageCodes' => [
3803
                        'cro-HR',
3804
                    ],
3805
                    'pathData' => [
3806
                        [
3807
                            'always-available' => false,
3808
                            'translations' => [
3809
                                'cro-HR' => 'dva',
3810
                            ],
3811
                        ],
3812
                    ],
3813
                    'alwaysAvailable' => false,
3814
                    'isHistory' => true,
3815
                    'isCustom' => false,
3816
                    'forward' => false,
3817
                ]
3818
            ),
3819
            $urlAlias
3820
        );
3821
3822
        $urlAlias = $handler->lookup('jedan-new');
3823
        $this->assertEquals(
3824
            new UrlAlias(
3825
                [
3826
                    'id' => '0-' . md5('jedan-new'),
3827
                    'type' => UrlAlias::LOCATION,
3828
                    'destination' => 315,
3829
                    'languageCodes' => [
3830
                        'cro-HR',
3831
                    ],
3832
                    'pathData' => [
3833
                        [
3834
                            'always-available' => false,
3835
                            'translations' => [
3836
                                'cro-HR' => 'jedan-new',
3837
                            ],
3838
                        ],
3839
                    ],
3840
                    'alwaysAvailable' => false,
3841
                    'isHistory' => false,
3842
                    'isCustom' => false,
3843
                    'forward' => false,
3844
                ]
3845
            ),
3846
            $urlAlias
3847
        );
3848
3849
        $urlAlias = $handler->lookup('dva-new');
3850
        $this->assertEquals(
3851
            new UrlAlias(
3852
                [
3853
                    'id' => '0-' . md5('dva-new'),
3854
                    'type' => UrlAlias::LOCATION,
3855
                    'destination' => 314,
3856
                    'languageCodes' => [
3857
                        'cro-HR',
3858
                    ],
3859
                    'pathData' => [
3860
                        [
3861
                            'always-available' => false,
3862
                            'translations' => [
3863
                                'cro-HR' => 'dva-new',
3864
                            ],
3865
                        ],
3866
                    ],
3867
                    'alwaysAvailable' => false,
3868
                    'isHistory' => false,
3869
                    'isCustom' => false,
3870
                    'forward' => false,
3871
                ]
3872
            ),
3873
            $urlAlias
3874
        );
3875
    }
3876
3877
    /**
3878
     * Test for the locationSwapped() method.
3879
     *
3880
     * @group swap
3881
     */
3882 View Code Duplication
    public function testLocationSwappedSiblingsSameName()
3883
    {
3884
        $handler = $this->getHandler();
3885
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3886
3887
        $countBeforeReusing = $this->countRows();
3888
3889
        $handler->locationSwapped(314, 2, 315, 2);
3890
3891
        $this->assertEquals(
3892
            $countBeforeReusing,
3893
            $this->countRows()
3894
        );
3895
3896
        $urlAlias = $handler->lookup('swap');
3897
        $this->assertEquals(
3898
            new UrlAlias(
3899
                [
3900
                    'id' => '0-' . md5('swap'),
3901
                    'type' => UrlAlias::LOCATION,
3902
                    'destination' => 314,
3903
                    'languageCodes' => [
3904
                        'cro-HR',
3905
                    ],
3906
                    'pathData' => [
3907
                        [
3908
                            'always-available' => false,
3909
                            'translations' => [
3910
                                'cro-HR' => 'swap',
3911
                            ],
3912
                        ],
3913
                    ],
3914
                    'alwaysAvailable' => false,
3915
                    'isHistory' => false,
3916
                    'isCustom' => false,
3917
                    'forward' => false,
3918
                ]
3919
            ),
3920
            $urlAlias
3921
        );
3922
3923
        $urlAlias = $handler->lookup('swap2');
3924
        $this->assertEquals(
3925
            new UrlAlias(
3926
                [
3927
                    'id' => '0-' . md5('swap2'),
3928
                    'type' => UrlAlias::LOCATION,
3929
                    'destination' => 315,
3930
                    'languageCodes' => [
3931
                        'cro-HR',
3932
                    ],
3933
                    'pathData' => [
3934
                        [
3935
                            'always-available' => false,
3936
                            'translations' => [
3937
                                'cro-HR' => 'swap2',
3938
                            ],
3939
                        ],
3940
                    ],
3941
                    'alwaysAvailable' => false,
3942
                    'isHistory' => false,
3943
                    'isCustom' => false,
3944
                    'forward' => false,
3945
                ]
3946
            ),
3947
            $urlAlias
3948
        );
3949
    }
3950
3951
    /**
3952
     * Test for the locationSwapped() method.
3953
     *
3954
     * @group swap
3955
     */
3956 View Code Duplication
    public function testLocationSwappedSiblingsSameNameReverse()
3957
    {
3958
        $handler = $this->getHandler();
3959
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3960
3961
        $countBeforeReusing = $this->countRows();
3962
3963
        $handler->locationSwapped(315, 2, 314, 2);
3964
3965
        $this->assertEquals(
3966
            $countBeforeReusing,
3967
            $this->countRows()
3968
        );
3969
3970
        $urlAlias = $handler->lookup('swap');
3971
        $this->assertEquals(
3972
            new UrlAlias(
3973
                [
3974
                    'id' => '0-' . md5('swap'),
3975
                    'type' => UrlAlias::LOCATION,
3976
                    'destination' => 314,
3977
                    'languageCodes' => [
3978
                        'cro-HR',
3979
                    ],
3980
                    'pathData' => [
3981
                        [
3982
                            'always-available' => false,
3983
                            'translations' => [
3984
                                'cro-HR' => 'swap',
3985
                            ],
3986
                        ],
3987
                    ],
3988
                    'alwaysAvailable' => false,
3989
                    'isHistory' => false,
3990
                    'isCustom' => false,
3991
                    'forward' => false,
3992
                ]
3993
            ),
3994
            $urlAlias
3995
        );
3996
3997
        $urlAlias = $handler->lookup('swap2');
3998
        $this->assertEquals(
3999
            new UrlAlias(
4000
                [
4001
                    'id' => '0-' . md5('swap2'),
4002
                    'type' => UrlAlias::LOCATION,
4003
                    'destination' => 315,
4004
                    'languageCodes' => [
4005
                        'cro-HR',
4006
                    ],
4007
                    'pathData' => [
4008
                        [
4009
                            'always-available' => false,
4010
                            'translations' => [
4011
                                'cro-HR' => 'swap2',
4012
                            ],
4013
                        ],
4014
                    ],
4015
                    'alwaysAvailable' => false,
4016
                    'isHistory' => false,
4017
                    'isCustom' => false,
4018
                    'forward' => false,
4019
                ]
4020
            ),
4021
            $urlAlias
4022
        );
4023
    }
4024
4025
    /**
4026
     * Test for the locationSwapped() method.
4027
     *
4028
     * @group swap
4029
     */
4030
    public function testLocationSwappedSiblingsSameNameMultipleLanguages()
4031
    {
4032
        $handler = $this->getHandler();
4033
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name_multilang.php');
4034
4035
        $countBeforeReusing = $this->countRows();
4036
4037
        $handler->locationSwapped(314, 2, 315, 2);
4038
4039
        $this->assertEquals(
4040
            $countBeforeReusing,
4041
            $this->countRows()
4042
        );
4043
4044
        $urlAlias = $handler->lookup('swap-hr');
4045
        $this->assertEquals(
4046
            new UrlAlias(
4047
                [
4048
                    'id' => '0-' . md5('swap-hr'),
4049
                    'type' => UrlAlias::LOCATION,
4050
                    'destination' => 314,
4051
                    'languageCodes' => [
4052
                        'cro-HR',
4053
                    ],
4054
                    'pathData' => [
4055
                        [
4056
                            'always-available' => false,
4057
                            'translations' => [
4058
                                'cro-HR' => 'swap-hr',
4059
                                'eng-GB' => 'swap-en2',
4060
                            ],
4061
                        ],
4062
                    ],
4063
                    'alwaysAvailable' => false,
4064
                    'isHistory' => false,
4065
                    'isCustom' => false,
4066
                    'forward' => false,
4067
                ]
4068
            ),
4069
            $urlAlias
4070
        );
4071
4072
        $urlAlias = $handler->lookup('swap-hr2');
4073
        $this->assertEquals(
4074
            new UrlAlias(
4075
                [
4076
                    'id' => '0-' . md5('swap-hr2'),
4077
                    'type' => UrlAlias::LOCATION,
4078
                    'destination' => 315,
4079
                    'languageCodes' => [
4080
                        'cro-HR',
4081
                    ],
4082
                    'pathData' => [
4083
                        [
4084
                            'always-available' => false,
4085
                            'translations' => [
4086
                                'cro-HR' => 'swap-hr2',
4087
                                'eng-GB' => 'swap-en',
4088
                            ],
4089
                        ],
4090
                    ],
4091
                    'alwaysAvailable' => false,
4092
                    'isHistory' => false,
4093
                    'isCustom' => false,
4094
                    'forward' => false,
4095
                ]
4096
            ),
4097
            $urlAlias
4098
        );
4099
4100
        $urlAlias = $handler->lookup('swap-en');
4101
        $this->assertEquals(
4102
            new UrlAlias(
4103
                [
4104
                    'id' => '0-' . md5('swap-en'),
4105
                    'type' => UrlAlias::LOCATION,
4106
                    'destination' => 315,
4107
                    'languageCodes' => [
4108
                        'eng-GB',
4109
                    ],
4110
                    'pathData' => [
4111
                        [
4112
                            'always-available' => false,
4113
                            'translations' => [
4114
                                'cro-HR' => 'swap-hr2',
4115
                                'eng-GB' => 'swap-en',
4116
                            ],
4117
                        ],
4118
                    ],
4119
                    'alwaysAvailable' => false,
4120
                    'isHistory' => false,
4121
                    'isCustom' => false,
4122
                    'forward' => false,
4123
                ]
4124
            ),
4125
            $urlAlias
4126
        );
4127
4128
        $urlAlias = $handler->lookup('swap-en2');
4129
        $this->assertEquals(
4130
            new UrlAlias(
4131
                [
4132
                    'id' => '0-' . md5('swap-en2'),
4133
                    'type' => UrlAlias::LOCATION,
4134
                    'destination' => 314,
4135
                    'languageCodes' => [
4136
                        'eng-GB',
4137
                    ],
4138
                    'pathData' => [
4139
                        [
4140
                            'always-available' => false,
4141
                            'translations' => [
4142
                                'cro-HR' => 'swap-hr',
4143
                                'eng-GB' => 'swap-en2',
4144
                            ],
4145
                        ],
4146
                    ],
4147
                    'alwaysAvailable' => false,
4148
                    'isHistory' => false,
4149
                    'isCustom' => false,
4150
                    'forward' => false,
4151
                ]
4152
            ),
4153
            $urlAlias
4154
        );
4155
    }
4156
4157
    /**
4158
     * Test for the locationSwapped() method.
4159
     *
4160
     * @group swap
4161
     */
4162
    public function testLocationSwappedMultipleLanguagesSimple()
4163
    {
4164
        $handler = $this->getHandler();
4165
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_simple.php');
4166
4167
        $urlAlias1HRExpected = $handler->lookup('jedan/swap-hr');
4168
        $urlAlias1ENExpected = $handler->lookup('jedan/swap-en');
4169
        $urlAlias2HRExpected = $handler->lookup('dva/swap-hr');
4170
        $urlAlias2ENExpected = $handler->lookup('dva/swap-en');
4171
4172
        $countBeforeReusing = $this->countRows();
4173
4174
        $handler->locationSwapped(316, 314, 317, 315);
4175
4176
        $this->assertEquals(
4177
            $countBeforeReusing,
4178
            $this->countRows()
4179
        );
4180
4181
        $urlAlias1HR = $handler->lookup('jedan/swap-hr');
4182
        $urlAlias1EN = $handler->lookup('jedan/swap-en');
4183
        $urlAlias2HR = $handler->lookup('dva/swap-hr');
4184
        $urlAlias2EN = $handler->lookup('dva/swap-en');
4185
4186
        $this->assertEquals($urlAlias1HRExpected, $urlAlias1HR);
4187
        $this->assertEquals($urlAlias1ENExpected, $urlAlias1EN);
4188
        $this->assertEquals($urlAlias2HRExpected, $urlAlias2HR);
4189
        $this->assertEquals($urlAlias2ENExpected, $urlAlias2EN);
4190
    }
4191
4192
    /**
4193
     * Test for the locationSwapped() method.
4194
     *
4195
     * @group swap
4196
     */
4197
    public function testLocationSwappedMultipleLanguagesDifferentLanguagesSimple()
4198
    {
4199
        $handler = $this->getHandler();
4200
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff_simple.php');
4201
4202
        $countBeforeReusing = $this->countRows();
4203
4204
        $handler->locationSwapped(316, 314, 317, 315);
4205
4206
        $this->assertEquals(
4207
            $countBeforeReusing + 2,
4208
            $this->countRows()
4209
        );
4210
4211
        $urlAlias = $handler->lookup('jedan/swap-hr');
4212
        $this->assertEquals(
4213
            new UrlAlias(
4214
                [
4215
                    'id' => '2-' . md5('swap-hr'),
4216
                    'type' => UrlAlias::LOCATION,
4217
                    'destination' => 316,
4218
                    'languageCodes' => [
4219
                        'cro-HR',
4220
                    ],
4221
                    'pathData' => [
4222
                        [
4223
                            'always-available' => false,
4224
                            'translations' => [
4225
                                'cro-HR' => 'jedan',
4226
                            ],
4227
                        ],
4228
                        [
4229
                            'always-available' => false,
4230
                            'translations' => [
4231
                                'cro-HR' => 'swap-hr',
4232
                                'ger-DE' => 'swap-de',
4233
                            ],
4234
                        ],
4235
                    ],
4236
                    'alwaysAvailable' => false,
4237
                    'isHistory' => false,
4238
                    'isCustom' => false,
4239
                    'forward' => false,
4240
                ]
4241
            ),
4242
            $urlAlias
4243
        );
4244
4245
        $urlAlias = $handler->lookup('jedan/swap-de');
4246
        $this->assertEquals(
4247
            new UrlAlias(
4248
                [
4249
                    'id' => '2-' . md5('swap-de'),
4250
                    'type' => UrlAlias::LOCATION,
4251
                    'destination' => 316,
4252
                    'languageCodes' => [
4253
                        'ger-DE',
4254
                    ],
4255
                    'pathData' => [
4256
                        [
4257
                            'always-available' => false,
4258
                            'translations' => [
4259
                                'cro-HR' => 'jedan',
4260
                            ],
4261
                        ],
4262
                        [
4263
                            'always-available' => false,
4264
                            'translations' => [
4265
                                'cro-HR' => 'swap-hr',
4266
                                'ger-DE' => 'swap-de',
4267
                            ],
4268
                        ],
4269
                    ],
4270
                    'alwaysAvailable' => false,
4271
                    'isHistory' => false,
4272
                    'isCustom' => false,
4273
                    'forward' => false,
4274
                ]
4275
            ),
4276
            $urlAlias
4277
        );
4278
4279
        $urlAlias = $handler->lookup('jedan/swap-en');
4280
        $this->assertEquals(
4281
            new UrlAlias(
4282
                [
4283
                    'id' => '2-' . md5('swap-en'),
4284
                    'type' => UrlAlias::LOCATION,
4285
                    'destination' => 316,
4286
                    'languageCodes' => [
4287
                        'eng-GB',
4288
                    ],
4289
                    'pathData' => [
4290
                        [
4291
                            'always-available' => false,
4292
                            'translations' => [
4293
                                'cro-HR' => 'jedan',
4294
                            ],
4295
                        ],
4296
                        [
4297
                            'always-available' => false,
4298
                            'translations' => [
4299
                                'eng-GB' => 'swap-en',
4300
                            ],
4301
                        ],
4302
                    ],
4303
                    'alwaysAvailable' => false,
4304
                    'isHistory' => true,
4305
                    'isCustom' => false,
4306
                    'forward' => false,
4307
                ]
4308
            ),
4309
            $urlAlias
4310
        );
4311
4312
        $urlAlias = $handler->lookup('dva/swap-hr');
4313
        $this->assertEquals(
4314
            new UrlAlias(
4315
                [
4316
                    'id' => '3-' . md5('swap-hr'),
4317
                    'type' => UrlAlias::LOCATION,
4318
                    'destination' => 317,
4319
                    'languageCodes' => [
4320
                        'cro-HR',
4321
                    ],
4322
                    'pathData' => [
4323
                        [
4324
                            'always-available' => false,
4325
                            'translations' => [
4326
                                'cro-HR' => 'dva',
4327
                            ],
4328
                        ],
4329
                        [
4330
                            'always-available' => false,
4331
                            'translations' => [
4332
                                'eng-GB' => 'swap-en',
4333
                                'cro-HR' => 'swap-hr',
4334
                            ],
4335
                        ],
4336
                    ],
4337
                    'alwaysAvailable' => false,
4338
                    'isHistory' => false,
4339
                    'isCustom' => false,
4340
                    'forward' => false,
4341
                ]
4342
            ),
4343
            $urlAlias
4344
        );
4345
4346
        $urlAlias = $handler->lookup('dva/swap-en');
4347
        $this->assertEquals(
4348
            new UrlAlias(
4349
                [
4350
                    'id' => '3-' . md5('swap-en'),
4351
                    'type' => UrlAlias::LOCATION,
4352
                    'destination' => 317,
4353
                    'languageCodes' => [
4354
                        'eng-GB',
4355
                    ],
4356
                    'pathData' => [
4357
                        [
4358
                            'always-available' => false,
4359
                            'translations' => [
4360
                                'cro-HR' => 'dva',
4361
                            ],
4362
                        ],
4363
                        [
4364
                            'always-available' => false,
4365
                            'translations' => [
4366
                                'eng-GB' => 'swap-en',
4367
                                'cro-HR' => 'swap-hr',
4368
                            ],
4369
                        ],
4370
                    ],
4371
                    'alwaysAvailable' => false,
4372
                    'isHistory' => false,
4373
                    'isCustom' => false,
4374
                    'forward' => false,
4375
                ]
4376
            ),
4377
            $urlAlias
4378
        );
4379
4380
        $urlAlias = $handler->lookup('dva/swap-de');
4381
        $this->assertEquals(
4382
            new UrlAlias(
4383
                [
4384
                    'id' => '3-' . md5('swap-de'),
4385
                    'type' => UrlAlias::LOCATION,
4386
                    'destination' => 317,
4387
                    'languageCodes' => [
4388
                        'ger-DE',
4389
                    ],
4390
                    'pathData' => [
4391
                        [
4392
                            'always-available' => false,
4393
                            'translations' => [
4394
                                'cro-HR' => 'dva',
4395
                            ],
4396
                        ],
4397
                        [
4398
                            'always-available' => false,
4399
                            'translations' => [
4400
                                'ger-DE' => 'swap-de',
4401
                            ],
4402
                        ],
4403
                    ],
4404
                    'alwaysAvailable' => false,
4405
                    'isHistory' => true,
4406
                    'isCustom' => false,
4407
                    'forward' => false,
4408
                ]
4409
            ),
4410
            $urlAlias
4411
        );
4412
    }
4413
4414
    /**
4415
     * Test for the locationSwapped() method.
4416
     *
4417
     * @group swap
4418
     */
4419
    public function testLocationSwappedMultipleLanguagesDifferentLanguages()
4420
    {
4421
        $handler = $this->getHandler();
4422
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff.php');
4423
4424
        $countBeforeReusing = $this->countRows();
4425
4426
        $handler->locationSwapped(317, 315, 316, 314);
4427
4428
        $this->assertEquals(
4429
            $countBeforeReusing + 2,
4430
            $this->countRows()
4431
        );
4432
4433
        $urlAlias = $handler->lookup('jedan/swap-this');
4434
        $this->assertEquals(
4435
            new UrlAlias(
4436
                [
4437
                    'id' => '2-' . md5('swap-this'),
4438
                    'type' => UrlAlias::LOCATION,
4439
                    'destination' => 316,
4440
                    'languageCodes' => [
4441
                        'ger-DE',
4442
                        'nor-NO',
4443
                    ],
4444
                    'pathData' => [
4445
                        [
4446
                            'always-available' => false,
4447
                            'translations' => [
4448
                                'cro-HR' => 'jedan',
4449
                            ],
4450
                        ],
4451
                        [
4452
                            'always-available' => false,
4453
                            'translations' => [
4454
                                'cro-HR' => 'swap-hr',
4455
                                'ger-DE' => 'swap-this',
4456
                                'nor-NO' => 'swap-this',
4457
                            ],
4458
                        ],
4459
                    ],
4460
                    'alwaysAvailable' => false,
4461
                    'isHistory' => false,
4462
                    'isCustom' => false,
4463
                    'forward' => false,
4464
                ]
4465
            ),
4466
            $urlAlias
4467
        );
4468
4469
        $urlAlias = $handler->lookup('jedan/swap-en');
4470
        $this->assertEquals(
4471
            new UrlAlias(
4472
                [
4473
                    'id' => '2-' . md5('swap-en'),
4474
                    'type' => UrlAlias::LOCATION,
4475
                    'destination' => 316,
4476
                    'languageCodes' => [
4477
                        'eng-GB',
4478
                    ],
4479
                    'pathData' => [
4480
                        [
4481
                            'always-available' => false,
4482
                            'translations' => [
4483
                                'cro-HR' => 'jedan',
4484
                            ],
4485
                        ],
4486
                        [
4487
                            'always-available' => false,
4488
                            'translations' => [
4489
                                'eng-GB' => 'swap-en',
4490
                            ],
4491
                        ],
4492
                    ],
4493
                    'alwaysAvailable' => false,
4494
                    'isHistory' => true,
4495
                    'isCustom' => false,
4496
                    'forward' => false,
4497
                ]
4498
            ),
4499
            $urlAlias
4500
        );
4501
4502
        $urlAlias = $handler->lookup('dva/swap-hr');
4503
        $this->assertEquals(
4504
            new UrlAlias(
4505
                [
4506
                    'id' => '3-' . md5('swap-hr'),
4507
                    'type' => UrlAlias::LOCATION,
4508
                    'destination' => 317,
4509
                    'languageCodes' => [
4510
                        'cro-HR',
4511
                    ],
4512
                    'pathData' => [
4513
                        [
4514
                            'always-available' => false,
4515
                            'translations' => [
4516
                                'cro-HR' => 'dva',
4517
                            ],
4518
                        ],
4519
                        [
4520
                            'always-available' => false,
4521
                            'translations' => [
4522
                                'cro-HR' => 'swap-hr',
4523
                            ],
4524
                        ],
4525
                    ],
4526
                    'alwaysAvailable' => false,
4527
                    'isHistory' => true,
4528
                    'isCustom' => false,
4529
                    'forward' => false,
4530
                ]
4531
            ),
4532
            $urlAlias
4533
        );
4534
4535
        $urlAlias = $handler->lookup('dva/swap-this');
4536
        $this->assertEquals(
4537
            new UrlAlias(
4538
                [
4539
                    'id' => '3-' . md5('swap-this'),
4540
                    'type' => UrlAlias::LOCATION,
4541
                    'destination' => 317,
4542
                    'languageCodes' => [
4543
                        'cro-HR',
4544
                        'ger-DE',
4545
                    ],
4546
                    'pathData' => [
4547
                        [
4548
                            'always-available' => false,
4549
                            'translations' => [
4550
                                'cro-HR' => 'dva',
4551
                            ],
4552
                        ],
4553
                        [
4554
                            'always-available' => false,
4555
                            'translations' => [
4556
                                'cro-HR' => 'swap-this',
4557
                                'ger-DE' => 'swap-this',
4558
                                'eng-GB' => 'swap-en',
4559
                            ],
4560
                        ],
4561
                    ],
4562
                    'alwaysAvailable' => false,
4563
                    'isHistory' => false,
4564
                    'isCustom' => false,
4565
                    'forward' => false,
4566
                ]
4567
            ),
4568
            $urlAlias
4569
        );
4570
    }
4571
4572
    /**
4573
     * Test for the locationSwapped() method.
4574
     *
4575
     * @group swap
4576
     */
4577
    public function testLocationSwappedMultipleLanguagesWithCompositeHistory()
4578
    {
4579
        $handler = $this->getHandler();
4580
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_cleanup_composite.php');
4581
4582
        $countBeforeReusing = $this->countRows();
4583
4584
        $handler->locationSwapped(317, 315, 316, 314);
4585
4586
        $this->assertEquals(
4587
            $countBeforeReusing + 4,
4588
            $this->countRows()
4589
        );
4590
4591
        $urlAlias = $handler->lookup('jedan/swap-this');
4592
        $this->assertEquals(
4593
            new UrlAlias(
4594
                [
4595
                    'id' => '2-' . md5('swap-this'),
4596
                    'type' => UrlAlias::LOCATION,
4597
                    'destination' => 316,
4598
                    'languageCodes' => [
4599
                        'cro-HR',
4600
                    ],
4601
                    'pathData' => [
4602
                        [
4603
                            'always-available' => false,
4604
                            'translations' => [
4605
                                'cro-HR' => 'jedan',
4606
                            ],
4607
                        ],
4608
                        [
4609
                            'always-available' => false,
4610
                            'translations' => [
4611
                                'cro-HR' => 'swap-this',
4612
                            ],
4613
                        ],
4614
                    ],
4615
                    'alwaysAvailable' => false,
4616
                    'isHistory' => true,
4617
                    'isCustom' => false,
4618
                    'forward' => false,
4619
                ]
4620
            ),
4621
            $urlAlias
4622
        );
4623
4624
        $urlAlias = $handler->lookup('jedan/swap-en');
4625
        $this->assertEquals(
4626
            new UrlAlias(
4627
                [
4628
                    'id' => '2-' . md5('swap-en'),
4629
                    'type' => UrlAlias::LOCATION,
4630
                    'destination' => 316,
4631
                    'languageCodes' => [
4632
                        'eng-GB',
4633
                    ],
4634
                    'pathData' => [
4635
                        [
4636
                            'always-available' => false,
4637
                            'translations' => [
4638
                                'cro-HR' => 'jedan',
4639
                            ],
4640
                        ],
4641
                        [
4642
                            'always-available' => false,
4643
                            'translations' => [
4644
                                'eng-GB' => 'swap-en',
4645
                            ],
4646
                        ],
4647
                    ],
4648
                    'alwaysAvailable' => false,
4649
                    'isHistory' => true,
4650
                    'isCustom' => false,
4651
                    'forward' => false,
4652
                ]
4653
            ),
4654
            $urlAlias
4655
        );
4656
4657
        $urlAlias = $handler->lookup('jedan/swap-hr');
4658
        $this->assertEquals(
4659
            new UrlAlias(
4660
                [
4661
                    'id' => '2-' . md5('swap-hr'),
4662
                    'type' => UrlAlias::LOCATION,
4663
                    'destination' => 316,
4664
                    'languageCodes' => [
4665
                        'cro-HR',
4666
                    ],
4667
                    'pathData' => [
4668
                        [
4669
                            'always-available' => false,
4670
                            'translations' => [
4671
                                'cro-HR' => 'jedan',
4672
                            ],
4673
                        ],
4674
                        [
4675
                            'always-available' => false,
4676
                            'translations' => [
4677
                                'cro-HR' => 'swap-hr',
4678
                                'ger-DE' => 'swap-that',
4679
                                'nor-NO' => 'swap-that',
4680
                            ],
4681
                        ],
4682
                    ],
4683
                    'alwaysAvailable' => false,
4684
                    'isHistory' => false,
4685
                    'isCustom' => false,
4686
                    'forward' => false,
4687
                ]
4688
            ),
4689
            $urlAlias
4690
        );
4691
4692
        $urlAlias = $handler->lookup('jedan/swap-that');
4693
        $this->assertEquals(
4694
            new UrlAlias(
4695
                [
4696
                    'id' => '2-' . md5('swap-that'),
4697
                    'type' => UrlAlias::LOCATION,
4698
                    'destination' => 316,
4699
                    'languageCodes' => [
4700
                        'ger-DE',
4701
                        'nor-NO',
4702
                    ],
4703
                    'pathData' => [
4704
                        [
4705
                            'always-available' => false,
4706
                            'translations' => [
4707
                                'cro-HR' => 'jedan',
4708
                            ],
4709
                        ],
4710
                        [
4711
                            'always-available' => false,
4712
                            'translations' => [
4713
                                'cro-HR' => 'swap-hr',
4714
                                'ger-DE' => 'swap-that',
4715
                                'nor-NO' => 'swap-that',
4716
                            ],
4717
                        ],
4718
                    ],
4719
                    'alwaysAvailable' => false,
4720
                    'isHistory' => false,
4721
                    'isCustom' => false,
4722
                    'forward' => false,
4723
                ]
4724
            ),
4725
            $urlAlias
4726
        );
4727
4728
        $urlAlias = $handler->lookup('dva/swap-hr');
4729
        $this->assertEquals(
4730
            new UrlAlias(
4731
                [
4732
                    'id' => '3-' . md5('swap-hr'),
4733
                    'type' => UrlAlias::LOCATION,
4734
                    'destination' => 317,
4735
                    'languageCodes' => [
4736
                        'cro-HR',
4737
                    ],
4738
                    'pathData' => [
4739
                        [
4740
                            'always-available' => false,
4741
                            'translations' => [
4742
                                'cro-HR' => 'dva',
4743
                            ],
4744
                        ],
4745
                        [
4746
                            'always-available' => false,
4747
                            'translations' => [
4748
                                'cro-HR' => 'swap-hr',
4749
                            ],
4750
                        ],
4751
                    ],
4752
                    'alwaysAvailable' => false,
4753
                    'isHistory' => true,
4754
                    'isCustom' => false,
4755
                    'forward' => false,
4756
                ]
4757
            ),
4758
            $urlAlias
4759
        );
4760
4761
        $urlAlias = $handler->lookup('dva/swap-that');
4762
        $this->assertEquals(
4763
            new UrlAlias(
4764
                [
4765
                    'id' => '3-' . md5('swap-that'),
4766
                    'type' => UrlAlias::LOCATION,
4767
                    'destination' => 317,
4768
                    'languageCodes' => [
4769
                        'ger-DE',
4770
                        'nor-NO',
4771
                    ],
4772
                    'pathData' => [
4773
                        [
4774
                            'always-available' => false,
4775
                            'translations' => [
4776
                                'cro-HR' => 'dva',
4777
                            ],
4778
                        ],
4779
                        [
4780
                            'always-available' => false,
4781
                            'translations' => [
4782
                                'ger-DE' => 'swap-that',
4783
                                'nor-NO' => 'swap-that',
4784
                            ],
4785
                        ],
4786
                    ],
4787
                    'alwaysAvailable' => false,
4788
                    'isHistory' => true,
4789
                    'isCustom' => false,
4790
                    'forward' => false,
4791
                ]
4792
            ),
4793
            $urlAlias
4794
        );
4795
4796
        $urlAlias = $handler->lookup('dva/swap-this');
4797
        $this->assertEquals(
4798
            new UrlAlias(
4799
                [
4800
                    'id' => '3-' . md5('swap-this'),
4801
                    'type' => UrlAlias::LOCATION,
4802
                    'destination' => 317,
4803
                    'languageCodes' => [
4804
                        'cro-HR',
4805
                    ],
4806
                    'pathData' => [
4807
                        [
4808
                            'always-available' => false,
4809
                            'translations' => [
4810
                                'cro-HR' => 'dva',
4811
                            ],
4812
                        ],
4813
                        [
4814
                            'always-available' => false,
4815
                            'translations' => [
4816
                                'cro-HR' => 'swap-this',
4817
                                'eng-GB' => 'swap-en',
4818
                            ],
4819
                        ],
4820
                    ],
4821
                    'alwaysAvailable' => false,
4822
                    'isHistory' => false,
4823
                    'isCustom' => false,
4824
                    'forward' => false,
4825
                ]
4826
            ),
4827
            $urlAlias
4828
        );
4829
4830
        $urlAlias = $handler->lookup('dva/swap-en');
4831
        $this->assertEquals(
4832
            new UrlAlias(
4833
                [
4834
                    'id' => '3-' . md5('swap-en'),
4835
                    'type' => UrlAlias::LOCATION,
4836
                    'destination' => 317,
4837
                    'languageCodes' => [
4838
                        'eng-GB',
4839
                    ],
4840
                    'pathData' => [
4841
                        [
4842
                            'always-available' => false,
4843
                            'translations' => [
4844
                                'cro-HR' => 'dva',
4845
                            ],
4846
                        ],
4847
                        [
4848
                            'always-available' => false,
4849
                            'translations' => [
4850
                                'cro-HR' => 'swap-this',
4851
                                'eng-GB' => 'swap-en',
4852
                            ],
4853
                        ],
4854
                    ],
4855
                    'alwaysAvailable' => false,
4856
                    'isHistory' => false,
4857
                    'isCustom' => false,
4858
                    'forward' => false,
4859
                ]
4860
            ),
4861
            $urlAlias
4862
        );
4863
    }
4864
4865
    /**
4866
     * Test for the locationSwapped() method.
4867
     *
4868
     * @group swap
4869
     */
4870 View Code Duplication
    public function testLocationSwappedWithReusingExternalHistory()
4871
    {
4872
        $handler = $this->getHandler();
4873
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_external_history.php');
4874
4875
        $countBeforeReusing = $this->countRows();
4876
4877
        $handler->locationSwapped(318, 314, 319, 315);
4878
4879
        $this->assertEquals(
4880
            $countBeforeReusing,
4881
            $this->countRows()
4882
        );
4883
4884
        $urlAlias = $handler->lookup('jedan/swap-that');
4885
        $this->assertEquals(
4886
            new UrlAlias(
4887
                [
4888
                    'id' => '2-' . md5('swap-that'),
4889
                    'type' => UrlAlias::LOCATION,
4890
                    'destination' => 318,
4891
                    'languageCodes' => [
4892
                        'cro-HR',
4893
                    ],
4894
                    'pathData' => [
4895
                        [
4896
                            'always-available' => false,
4897
                            'translations' => [
4898
                                'cro-HR' => 'jedan',
4899
                            ],
4900
                        ],
4901
                        [
4902
                            'always-available' => false,
4903
                            'translations' => [
4904
                                'cro-HR' => 'swap-that',
4905
                            ],
4906
                        ],
4907
                    ],
4908
                    'alwaysAvailable' => false,
4909
                    'isHistory' => false,
4910
                    'isCustom' => false,
4911
                    'forward' => false,
4912
                ]
4913
            ),
4914
            $urlAlias
4915
        );
4916
4917
        $urlAlias = $handler->lookup('dva/swap-this');
4918
        $this->assertEquals(
4919
            new UrlAlias(
4920
                [
4921
                    'id' => '3-' . md5('swap-this'),
4922
                    'type' => UrlAlias::LOCATION,
4923
                    'destination' => 319,
4924
                    'languageCodes' => [
4925
                        'cro-HR',
4926
                    ],
4927
                    'pathData' => [
4928
                        [
4929
                            'always-available' => false,
4930
                            'translations' => [
4931
                                'cro-HR' => 'dva',
4932
                            ],
4933
                        ],
4934
                        [
4935
                            'always-available' => false,
4936
                            'translations' => [
4937
                                'cro-HR' => 'swap-this',
4938
                            ],
4939
                        ],
4940
                    ],
4941
                    'alwaysAvailable' => false,
4942
                    'isHistory' => false,
4943
                    'isCustom' => false,
4944
                    'forward' => false,
4945
                ]
4946
            ),
4947
            $urlAlias
4948
        );
4949
4950
        $urlAlias = $handler->lookup('dva/swap-that');
4951
        $this->assertEquals(
4952
            new UrlAlias(
4953
                [
4954
                    'id' => '3-' . md5('swap-that'),
4955
                    'type' => UrlAlias::LOCATION,
4956
                    'destination' => 319,
4957
                    'languageCodes' => [
4958
                        'cro-HR',
4959
                    ],
4960
                    'pathData' => [
4961
                        [
4962
                            'always-available' => false,
4963
                            'translations' => [
4964
                                'cro-HR' => 'dva',
4965
                            ],
4966
                        ],
4967
                        [
4968
                            'always-available' => false,
4969
                            'translations' => [
4970
                                'cro-HR' => 'swap-that',
4971
                            ],
4972
                        ],
4973
                    ],
4974
                    'alwaysAvailable' => false,
4975
                    'isHistory' => true,
4976
                    'isCustom' => false,
4977
                    'forward' => false,
4978
                ]
4979
            ),
4980
            $urlAlias
4981
        );
4982
4983
        $urlAlias = $handler->lookup('jedan/swap-this');
4984
        $this->assertEquals(
4985
            new UrlAlias(
4986
                [
4987
                    'id' => '2-' . md5('swap-this'),
4988
                    'type' => UrlAlias::LOCATION,
4989
                    'destination' => 318,
4990
                    'languageCodes' => [
4991
                        'cro-HR',
4992
                    ],
4993
                    'pathData' => [
4994
                        [
4995
                            'always-available' => false,
4996
                            'translations' => [
4997
                                'cro-HR' => 'jedan',
4998
                            ],
4999
                        ],
5000
                        [
5001
                            'always-available' => false,
5002
                            'translations' => [
5003
                                'cro-HR' => 'swap-this',
5004
                            ],
5005
                        ],
5006
                    ],
5007
                    'alwaysAvailable' => false,
5008
                    'isHistory' => true,
5009
                    'isCustom' => false,
5010
                    'forward' => false,
5011
                ]
5012
            ),
5013
            $urlAlias
5014
        );
5015
    }
5016
5017
    /**
5018
     * Test for the locationSwapped() method.
5019
     *
5020
     * @group swap
5021
     */
5022 View Code Duplication
    public function testLocationSwappedWithReusingNopEntry()
5023
    {
5024
        $handler = $this->getHandler();
5025
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5026
5027
        $countBeforeReusing = $this->countRows();
5028
5029
        $handler->locationSwapped(316, 314, 317, 315);
5030
5031
        $this->assertEquals(
5032
            $countBeforeReusing + 1,
5033
            $this->countRows()
5034
        );
5035
5036
        $urlAlias = $handler->lookup('jedan/swap-that');
5037
        $this->assertEquals(
5038
            new UrlAlias(
5039
                [
5040
                    'id' => '2-' . md5('swap-that'),
5041
                    'type' => UrlAlias::LOCATION,
5042
                    'destination' => 316,
5043
                    'languageCodes' => [
5044
                        'cro-HR',
5045
                    ],
5046
                    'pathData' => [
5047
                        [
5048
                            'always-available' => false,
5049
                            'translations' => [
5050
                                'cro-HR' => 'jedan',
5051
                            ],
5052
                        ],
5053
                        [
5054
                            'always-available' => false,
5055
                            'translations' => [
5056
                                'cro-HR' => 'swap-that',
5057
                            ],
5058
                        ],
5059
                    ],
5060
                    'alwaysAvailable' => false,
5061
                    'isHistory' => false,
5062
                    'isCustom' => false,
5063
                    'forward' => false,
5064
                ]
5065
            ),
5066
            $urlAlias
5067
        );
5068
5069
        $urlAlias = $handler->lookup('dva/swap-this');
5070
        $this->assertEquals(
5071
            new UrlAlias(
5072
                [
5073
                    'id' => '3-' . md5('swap-this'),
5074
                    'type' => UrlAlias::LOCATION,
5075
                    'destination' => 317,
5076
                    'languageCodes' => [
5077
                        'cro-HR',
5078
                    ],
5079
                    'pathData' => [
5080
                        [
5081
                            'always-available' => false,
5082
                            'translations' => [
5083
                                'cro-HR' => 'dva',
5084
                            ],
5085
                        ],
5086
                        [
5087
                            'always-available' => false,
5088
                            'translations' => [
5089
                                'cro-HR' => 'swap-this',
5090
                            ],
5091
                        ],
5092
                    ],
5093
                    'alwaysAvailable' => false,
5094
                    'isHistory' => false,
5095
                    'isCustom' => false,
5096
                    'forward' => false,
5097
                ]
5098
            ),
5099
            $urlAlias
5100
        );
5101
5102
        $urlAlias = $handler->lookup('dva/swap-that');
5103
        $this->assertEquals(
5104
            new UrlAlias(
5105
                [
5106
                    'id' => '3-' . md5('swap-that'),
5107
                    'type' => UrlAlias::LOCATION,
5108
                    'destination' => 317,
5109
                    'languageCodes' => [
5110
                        'cro-HR',
5111
                    ],
5112
                    'pathData' => [
5113
                        [
5114
                            'always-available' => false,
5115
                            'translations' => [
5116
                                'cro-HR' => 'dva',
5117
                            ],
5118
                        ],
5119
                        [
5120
                            'always-available' => false,
5121
                            'translations' => [
5122
                                'cro-HR' => 'swap-that',
5123
                            ],
5124
                        ],
5125
                    ],
5126
                    'alwaysAvailable' => false,
5127
                    'isHistory' => true,
5128
                    'isCustom' => false,
5129
                    'forward' => false,
5130
                ]
5131
            ),
5132
            $urlAlias
5133
        );
5134
5135
        $urlAlias = $handler->lookup('jedan/swap-this');
5136
        $this->assertEquals(
5137
            new UrlAlias(
5138
                [
5139
                    'id' => '2-' . md5('swap-this'),
5140
                    'type' => UrlAlias::LOCATION,
5141
                    'destination' => 316,
5142
                    'languageCodes' => [
5143
                        'cro-HR',
5144
                    ],
5145
                    'pathData' => [
5146
                        [
5147
                            'always-available' => false,
5148
                            'translations' => [
5149
                                'cro-HR' => 'jedan',
5150
                            ],
5151
                        ],
5152
                        [
5153
                            'always-available' => false,
5154
                            'translations' => [
5155
                                'cro-HR' => 'swap-this',
5156
                            ],
5157
                        ],
5158
                    ],
5159
                    'alwaysAvailable' => false,
5160
                    'isHistory' => true,
5161
                    'isCustom' => false,
5162
                    'forward' => false,
5163
                ]
5164
            ),
5165
            $urlAlias
5166
        );
5167
    }
5168
5169
    /**
5170
     * Test for the locationSwapped() method.
5171
     *
5172
     * @depends testLocationSwappedWithReusingNopEntry
5173
     * @group swap
5174
     */
5175 View Code Duplication
    public function testLocationSwappedWithReusingNopEntryCustomAliasIsDestroyed()
5176
    {
5177
        $handler = $this->getHandler();
5178
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5179
5180
        $handler->lookup('jedan/swap-that/search');
5181
        $handler->locationSwapped(316, 314, 317, 315);
5182
5183
        try {
5184
            $handler->lookup('jedan/swap-that/search');
5185
            $this->fail('Custom alias is not destroyed');
5186
        } catch (NotFoundException $e) {
5187
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
5188
            // on the same level (that means link and ID are updated to the existing alias ID,
5189
            // so custom alias children entries are no longer properly linked (parent-link))
5190
        }
5191
    }
5192
5193
    /**
5194
     * Test for the locationSwapped() method.
5195
     *
5196
     * @group swap
5197
     *
5198
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5199
     */
5200 View Code Duplication
    public function testLocationSwappedUpdatesLocationPathIdentificationString()
5201
    {
5202
        $handler = $this->getHandler();
5203
        $locationGateway = $this->getLocationGateway();
5204
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_path_identification_string.php');
5205
5206
        $countBeforeReusing = $this->countRows();
5207
5208
        $handler->locationSwapped(314, 2, 315, 2);
5209
5210
        $this->assertEquals(
5211
            $countBeforeReusing,
5212
            $this->countRows()
5213
        );
5214
5215
        $locationData = $locationGateway->getBasicNodeData(314);
5216
        self::assertEquals('dva', $locationData['path_identification_string']);
5217
5218
        $locationData = $locationGateway->getBasicNodeData(315);
5219
        self::assertEquals('jedan', $locationData['path_identification_string']);
5220
    }
5221
5222
    /**
5223
     * Test for the locationSwapped() method.
5224
     *
5225
     * @group swap
5226
     *
5227
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5228
     */
5229 View Code Duplication
    public function testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString()
5230
    {
5231
        $handler = $this->getHandler();
5232
        $locationGateway = $this->getLocationGateway();
5233
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_path_identification_string.php');
5234
5235
        $countBeforeReusing = $this->countRows();
5236
5237
        $handler->locationSwapped(314, 2, 315, 2);
5238
5239
        $this->assertEquals(
5240
            $countBeforeReusing,
5241
            $this->countRows()
5242
        );
5243
5244
        $locationData = $locationGateway->getBasicNodeData(314);
5245
        self::assertEquals('zwei', $locationData['path_identification_string']);
5246
5247
        $locationData = $locationGateway->getBasicNodeData(315);
5248
        self::assertEquals('jedan', $locationData['path_identification_string']);
5249
    }
5250
5251
    /**
5252
     * @return int
5253
     */
5254
    protected function countRows()
5255
    {
5256
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5257
        $query = $this->getDatabaseHandler()->createSelectQuery();
5258
        $query->select(
5259
            $query->expr->count('*')
5260
        )->from(
5261
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5262
        );
5263
5264
        $statement = $query->prepare();
5265
        $statement->execute();
5266
5267
        return (int)$statement->fetchColumn();
5268
    }
5269
5270
    protected function dump()
5271
    {
5272
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5273
        $query = $this->getDatabaseHandler()->createSelectQuery();
5274
        $query->select(
5275
            '*'
5276
        )->from(
5277
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5278
        );
5279
5280
        $statement = $query->prepare();
5281
        $statement->execute();
5282
5283
        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...
5284
    }
5285
5286
    /**
5287
     * @var \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler
5288
     * @deprecated Start to use DBAL $connection instead.
5289
     */
5290
    protected $dbHandler;
5291
5292
    /**
5293
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5294
     */
5295
    protected $locationGateway;
5296
5297
    /**
5298
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5299
     */
5300
    protected $languageHandler;
5301
5302
    /**
5303
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5304
     */
5305
    protected $languageMaskGenerator;
5306
5307
    /**
5308
     * @param array $methods
5309
     *
5310
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler|\PHPUnit_Framework_MockObject_MockObject
5311
     */
5312
    protected function getPartlyMockedHandler(array $methods)
5313
    {
5314
        return $this->getMockBuilder(Handler::class)
5315
            ->setConstructorArgs(
5316
                [
5317
                    $this->createMock(UrlAliasGateway::class),
5318
                    $this->createMock(Mapper::class),
5319
                    $this->createMock(LocationGateway::class),
5320
                    $this->createMock(LanguageHandler::class),
5321
                    $this->createMock(SlugConverter::class),
5322
                    $this->createMock(Gateway::class),
5323
                    $this->createMock(LanguageMaskGenerator::class),
5324
                    $this->createMock(TransactionHandler::class),
5325
                ]
5326
            )
5327
            ->setMethods($methods)
5328
            ->getMock();
5329
    }
5330
5331
    /**
5332
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5333
     */
5334
    protected function getHandler()
5335
    {
5336
        $languageHandler = $this->getLanguageHandler();
5337
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5338
        $databaseHandler = $this->getDatabaseHandler();
5339
        $gateway = new DoctrineDatabase(
5340
            $databaseHandler,
5341
            $languageMaskGenerator
5342
        );
5343
        $mapper = new Mapper($languageMaskGenerator);
5344
        $slugConverter = new SlugConverter($this->getProcessor());
5345
        $contentGateway = new ContentGateway(
5346
            $this->getDatabaseHandler(),
5347
            $this->getDatabaseConnection(),
5348
            new ContentGateway\QueryBuilder($this->getDatabaseHandler()),
5349
            $languageHandler,
5350
            $languageMaskGenerator
5351
        );
5352
5353
        return new Handler(
5354
            $gateway,
5355
            $mapper,
5356
            $this->getLocationGateway(),
5357
            $languageHandler,
5358
            $slugConverter,
5359
            $contentGateway,
5360
            $languageMaskGenerator,
5361
            $this->createMock(TransactionHandler::class)
5362
        );
5363
    }
5364
5365
    /**
5366
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5367
     */
5368
    protected function getLanguageHandler()
5369
    {
5370
        if (!isset($this->languageHandler)) {
5371
            $this->languageHandler = new LanguageHandler(
5372
                new LanguageGateway(
5373
                    $this->getDatabaseHandler()
5374
                ),
5375
                new LanguageMapper()
5376
            );
5377
        }
5378
5379
        return $this->languageHandler;
5380
    }
5381
5382
    /**
5383
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5384
     */
5385
    protected function getLanguageMaskGenerator()
5386
    {
5387
        if (!isset($this->languageMaskGenerator)) {
5388
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5389
                $this->getLanguageHandler()
5390
            );
5391
        }
5392
5393
        return $this->languageMaskGenerator;
5394
    }
5395
5396
    /**
5397
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5398
     */
5399
    protected function getLocationGateway()
5400
    {
5401
        if (!isset($this->locationGateway)) {
5402
            $this->locationGateway = new DoctrineDatabaseLocation(
5403
                $this->getDatabaseHandler()
5404
            );
5405
        }
5406
5407
        return $this->locationGateway;
5408
    }
5409
5410
    /**
5411
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5412
     */
5413
    public function getProcessor()
5414
    {
5415
        return new DefinitionBased(
5416
            new Parser(),
5417
            new PcreCompiler(new Utf8Converter()),
5418
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5419
        );
5420
    }
5421
5422
    /**
5423
     * Data provider for tests of archiveUrlAliasesForDeletedTranslations.
5424
     *
5425
     * @see testArchiveUrlAliasesForDeletedTranslations for the description of parameters
5426
     *
5427
     * @return array
5428
     */
5429
    public function providerForArchiveUrlAliasesForDeletedTranslations()
5430
    {
5431
        return [
5432
            [2, ['eng-GB', 'pol-PL'], 'pol-PL'],
5433
            [3, ['eng-GB', 'pol-PL', 'nor-NO'], 'pol-PL'],
5434
        ];
5435
    }
5436
5437
    /**
5438
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::archiveUrlAliasesForDeletedTranslations()
5439
     *
5440
     * @dataProvider providerForArchiveUrlAliasesForDeletedTranslations
5441
     *
5442
     * @param int $locationId
5443
     * @param string[] $expectedLanguages expected language codes before deleting
5444
     * @param string $removeLanguage language code to be deleted
5445
     */
5446
    public function testArchiveUrlAliasesForDeletedTranslations(
5447
        $locationId,
5448
        array $expectedLanguages,
5449
        $removeLanguage
5450
    ) {
5451
        $handler = $this->getHandler();
5452
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_multilingual.php');
5453
5454
        // collect data persisted from fixtures
5455
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5456
        $collectedLanguages = [];
5457
        $collectedUrls = [];
5458
        foreach ($urlAliases as $urlAlias) {
5459
            // collect languages of all URL aliases
5460
            $collectedLanguages = array_merge($collectedLanguages, $urlAlias->languageCodes);
5461
            $isComposite = count($urlAlias->languageCodes) > 1;
5462
            foreach ($urlAlias->pathData as $pathData) {
5463
                // collect also actual unique URLs to be removed to check them after removal
5464
                if (!empty($pathData['translations'][$removeLanguage])) {
5465
                    $url = $pathData['translations'][$removeLanguage];
5466
                    $collectedUrls[$url] = $isComposite;
5467
                }
5468
            }
5469
        }
5470
        // sanity check
5471
        self::assertEquals($expectedLanguages, $collectedLanguages);
5472
5473
        // remove language
5474
        $publishedLanguages = array_values(array_diff($collectedLanguages, [$removeLanguage]));
5475
        $handler->archiveUrlAliasesForDeletedTranslations($locationId, 1, $publishedLanguages);
5476
5477
        // check reloaded structures
5478
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5479 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...
5480
            self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5481
            foreach ($urlAlias->pathData as $pathData) {
5482
                self::assertNotContains($removeLanguage, $pathData['translations']);
5483
                foreach ($pathData['translations'] as $url) {
5484
                    $lookupUrlAlias = $handler->lookup($url);
5485
                    self::assertNotContains($removeLanguage, $lookupUrlAlias->languageCodes);
5486
                }
5487
            }
5488
        }
5489
5490
        // lookup removed URLs to check they're not found
5491 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...
5492
            $urlAlias = $handler->lookup($url);
5493
            if ($isComposite) {
5494
                // check if alias no longer refers to removed Translation
5495
                self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5496
                foreach ($urlAlias->pathData as $pathData) {
5497
                    self::assertNotContains($removeLanguage, $pathData['translations']);
5498
                }
5499
            } else {
5500
                // check if non composite alias for removed translation is historized
5501
                self::assertTrue($urlAlias->isHistory);
5502
            }
5503
        }
5504
    }
5505
}
5506