Completed
Push — test-EZP-26707-issearchable-fu... ( 0d4c60 )
by
unknown
30:03 queued 14:08
created

testLocationSwappedMultipleLanguagesSimple()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

Loading history...
1569
            if ($propertyName === 'pathData') {
1570
                self::assertEquals(
1571
                    array(
1572
                        array(
1573
                            'always-available' => false,
1574
                            'translations' => array('eng-GB' => 'nop-element'),
1575
                        ),
1576
                        array(
1577
                            'always-available' => false,
1578
                            'translations' => array('eng-GB' => 'search'),
1579
                        ),
1580
                    ),
1581
                    $virtualUrlAliasReloaded->pathData
1582
                );
1583
            } else {
1584
                self::assertEquals(
1585
                    $virtualUrlAlias->$propertyName,
1586
                    $virtualUrlAliasReloaded->$propertyName
1587
                );
1588
            }
1589
        }
1590
    }
1591
1592
    /**
1593
     * Test for the publishUrlAliasForLocation() method.
1594
     *
1595
     * @todo document
1596
     *
1597
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1598
     * @depends testPublishUrlAliasForLocation
1599
     * @depends testPublishUrlAliasForLocationReusingNopElement
1600
     */
1601
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPath()
1602
    {
1603
        $handler = $this->getHandler();
1604
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1605
1606
        $countBeforeReusing = $this->countRows();
1607
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1608
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1609
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1610
        $virtualUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1611
1612
        self::assertEquals(
1613
            $countBeforeReusing + 1,
1614
            $this->countRows()
1615
        );
1616
1617 View Code Duplication
        foreach ($virtualUrlAliasChanged as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $virtualUrlAliasChanged of type object<eZ\Publish\SPI\Pe...tence\Content\UrlAlias> is not traversable.
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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