Completed
Push — master ( a6387c...f7252d )
by André
23:52 queued 09:38
created

UrlAliasHandlerTest::getLanguageHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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