Completed
Push — EZP-26146-location-swap-urlali... ( 8d4853...59ced7 )
by
unknown
80:01 queued 54:00
created

testPublishUrlAliasForLocationSkipsReservedWord()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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