Completed
Push — ezp29751_wrong_first_urlalias_... ( 6b47f4...f333c9 )
by
unknown
30:24
created

testLocationSwappedSiblingsSameNameMultipleLanguages()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 126

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 126
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5381
            'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Handler',
5382
            $methods,
5383
            array(
5384
                self::getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Gateway'),
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5385
                self::getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5386
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Mapper',
5387
                    array(),
5388
                    array(),
5389
                    '',
5390
                    false
5391
                ),
5392
                self::getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway'),
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5393
                self::getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5394
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Language\\Handler',
5395
                    array(),
5396
                    array(),
5397
                    '',
5398
                    false
5399
                ),
5400
                self::getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5401
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\SlugConverter',
5402
                    array(),
5403
                    array(),
5404
                    '',
5405
                    false
5406
                ),
5407
                $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5408
                    Gateway::class,
5409
                    [],
5410
                    [],
5411
                    '',
5412
                    false
5413
                ),
5414
                $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5415
                    LanguageMaskGenerator::class,
5416
                    [],
5417
                    [],
5418
                    '',
5419
                    false
5420
                ),
5421
                $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
5422
                    'eZ\\Publish\\SPI\\Persistence\\TransactionHandler',
5423
                    [],
5424
                    [],
5425
                    '',
5426
                    false
5427
                ),
5428
            )
5429
        );
5430
5431
        return $mock;
5432
    }
5433
5434
    /**
5435
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5436
     */
5437
    protected function getHandler()
5438
    {
5439
        $languageHandler = $this->getLanguageHandler();
5440
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5441
        $databaseHandler = $this->getDatabaseHandler();
5442
        $gateway = new DoctrineDatabase(
5443
            $databaseHandler,
5444
            $languageMaskGenerator
5445
        );
5446
        $mapper = new Mapper($languageMaskGenerator);
5447
        $slugConverter = new SlugConverter($this->getProcessor());
5448
        $contentGateway = new ContentGateway(
5449
            $this->getDatabaseHandler(),
5450
            $this->getDatabaseConnection(),
5451
            new ContentGateway\QueryBuilder($this->getDatabaseHandler()),
5452
            $languageHandler,
5453
            $languageMaskGenerator
5454
        );
5455
5456
        return new Handler(
5457
            $gateway,
5458
            $mapper,
5459
            $this->getLocationGateway(),
5460
            $languageHandler,
5461
            $slugConverter,
5462
            $contentGateway,
5463
            $languageMaskGenerator,
5464
            $this->createMock('eZ\\Publish\\SPI\\Persistence\\TransactionHandler')
5465
        );
5466
    }
5467
5468
    /**
5469
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5470
     */
5471
    protected function getLanguageHandler()
5472
    {
5473
        if (!isset($this->languageHandler)) {
5474
            $this->languageHandler = new LanguageHandler(
5475
                new LanguageGateway(
5476
                    $this->getDatabaseHandler()
5477
                ),
5478
                new LanguageMapper()
5479
            );
5480
        }
5481
5482
        return $this->languageHandler;
5483
    }
5484
5485
    /**
5486
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5487
     */
5488
    protected function getLanguageMaskGenerator()
5489
    {
5490
        if (!isset($this->languageMaskGenerator)) {
5491
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5492
                $this->getLanguageHandler()
5493
            );
5494
        }
5495
5496
        return $this->languageMaskGenerator;
5497
    }
5498
5499
    /**
5500
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5501
     */
5502
    protected function getLocationGateway()
5503
    {
5504
        if (!isset($this->locationGateway)) {
5505
            $this->locationGateway = new DoctrineDatabaseLocation(
5506
                $this->getDatabaseHandler()
5507
            );
5508
        }
5509
5510
        return $this->locationGateway;
5511
    }
5512
5513
    /**
5514
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5515
     */
5516
    public function getProcessor()
5517
    {
5518
        return new DefinitionBased(
5519
            new Parser(),
5520
            new PcreCompiler(new Utf8Converter()),
5521
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5522
        );
5523
    }
5524
}
5525