Completed
Push — EZP-26146-location-swap-urlali... ( 0a40f5...ae2933 )
by
unknown
23:52
created

UrlAliasHandlerTest::getHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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