Completed
Push — EZP-29891 ( 916cf6...0402ff )
by
unknown
16:53
created

UrlAliasHandlerTest::testArchiveUrlAliasesForDeletedTranslations()   B

Complexity

Conditions 10
Paths 48

Size

Total Lines 59

Duplication

Lines 23
Ratio 38.98 %

Importance

Changes 0
Metric Value
cc 10
nc 48
nop 3
dl 23
loc 59
rs 7.0278
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
    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
    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
     * @return array
1175
     */
1176
    public function providerForTestPublishUrlAliasForLocationComplex()
1177
    {
1178
        return $this->providerForTestLookupLocationUrlAlias();
1179
    }
1180
1181
    /**
1182
     * Test for the publishUrlAliasForLocation() method.
1183
     *
1184
     * @todo document
1185
     *
1186
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1187
     * @dataProvider providerForTestPublishUrlAliasForLocationComplex
1188
     * @depends testPublishUrlAliasForLocation
1189
     * @group publish
1190
     */
1191
    public function testPublishUrlAliasForLocationComplex(
1192
        $url,
1193
        $pathData,
1194
        array $languageCodes,
1195
        $alwaysAvailable,
1196
        $locationId,
1197
        $id
1198
    ) {
1199
        $handler = $this->getHandler();
1200
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1201
1202
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', true);
1203
        $handler->publishUrlAliasForLocation(315, 314, 'dva', 'cro-HR', false);
1204
        $handler->publishUrlAliasForLocation(315, 314, 'two', 'eng-GB', false);
1205
        $handler->publishUrlAliasForLocation(316, 315, 'tri', 'cro-HR', false);
1206
        $handler->publishUrlAliasForLocation(316, 315, 'three', 'eng-GB', false);
1207
        $handler->publishUrlAliasForLocation(316, 315, 'drei', 'ger-DE', false);
1208
1209
        $urlAlias = $handler->lookup($url);
1210
1211
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias', $urlAlias);
1212
        self::assertEquals(
1213
            new UrlAlias(
1214
                array(
1215
                    'id' => $id,
1216
                    'type' => UrlAlias::LOCATION,
1217
                    'destination' => $locationId,
1218
                    'languageCodes' => $languageCodes,
1219
                    'pathData' => $pathData,
1220
                    'alwaysAvailable' => $alwaysAvailable,
1221
                    'isHistory' => false,
1222
                    'isCustom' => false,
1223
                    'forward' => false,
1224
                )
1225
            ),
1226
            $urlAlias
1227
        );
1228
    }
1229
1230
    /**
1231
     * Test for the publishUrlAliasForLocation() method.
1232
     *
1233
     * @todo document
1234
     *
1235
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1236
     * @depends testPublishUrlAliasForLocation
1237
     * @group publish
1238
     */
1239
    public function testPublishUrlAliasForLocationSameAliasForMultipleLanguages()
1240
    {
1241
        $handler = $this->getHandler();
1242
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1243
1244
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1245
        $urlAlias1 = $handler->lookup('jedan');
1246
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB', false);
1247
        $urlAlias2 = $handler->lookup('jedan');
1248
1249
        self::assertEquals(4, $this->countRows());
1250
1251
        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...
1252
            if ($propertyName === 'languageCodes') {
1253
                self::assertEquals(
1254
                    array('cro-HR', 'eng-GB'),
1255
                    $urlAlias2->languageCodes
1256
                );
1257
            } elseif ($propertyName === 'pathData') {
1258
                self::assertEquals(
1259
                    array(
1260
                        array(
1261
                            'always-available' => false,
1262
                            'translations' => array(
1263
                                'cro-HR' => 'jedan',
1264
                                'eng-GB' => 'jedan',
1265
                            ),
1266
                        ),
1267
                    ),
1268
                    $urlAlias2->pathData
1269
                );
1270
            } else {
1271
                self::assertEquals(
1272
                    $urlAlias1->$propertyName,
1273
                    $urlAlias2->$propertyName
1274
                );
1275
            }
1276
        }
1277
    }
1278
1279
    /**
1280
     * Test for the publishUrlAliasForLocation() method.
1281
     *
1282
     * @todo document
1283
     *
1284
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1285
     * @depends testPublishUrlAliasForLocation
1286
     * @group publish
1287
     */
1288
    public function testPublishUrlAliasForLocationDowngradesOldEntryToHistory()
1289
    {
1290
        $handler = $this->getHandler();
1291
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1292
1293
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR', false);
1294
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', true);
1295
1296
        self::assertEquals(5, $this->countRows());
1297
1298
        $newUrlAlias = $handler->lookup('dva');
1299
1300
        self::assertEquals(
1301
            new UrlAlias(
1302
                array(
1303
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1304
                    'type' => 0,
1305
                    'destination' => 314,
1306
                    'languageCodes' => array('cro-HR'),
1307
                    'pathData' => array(
1308
                        array(
1309
                            'always-available' => true,
1310
                            'translations' => array(
1311
                                'cro-HR' => 'dva',
1312
                            ),
1313
                        ),
1314
                    ),
1315
                    'alwaysAvailable' => true,
1316
                    'isHistory' => false,
1317
                    'isCustom' => false,
1318
                    'forward' => false,
1319
                )
1320
            ),
1321
            $newUrlAlias
1322
        );
1323
1324
        $historyUrlAlias = $handler->lookup('jedan');
1325
1326
        self::assertEquals(
1327
            new UrlAlias(
1328
                array(
1329
                    'id' => '0-6896260129051a949051c3847c34466f',
1330
                    'type' => 0,
1331
                    'destination' => 314,
1332
                    'languageCodes' => array('cro-HR'),
1333
                    'pathData' => array(
1334
                        array(
1335
                            'always-available' => false,
1336
                            'translations' => array(
1337
                                'cro-HR' => 'jedan',
1338
                            ),
1339
                        ),
1340
                    ),
1341
                    'alwaysAvailable' => false,
1342
                    'isHistory' => true,
1343
                    'isCustom' => false,
1344
                    'forward' => false,
1345
                )
1346
            ),
1347
            $historyUrlAlias
1348
        );
1349
    }
1350
1351
    /**
1352
     * Test for the publishUrlAliasForLocation() method.
1353
     *
1354
     * @todo document
1355
     *
1356
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1357
     * @depends testPublishUrlAliasForLocation
1358
     * @depends testPublishUrlAliasForLocationSameAliasForMultipleLanguages
1359
     * @group publish
1360
     * @group downgrade
1361
     */
1362
    public function testPublishUrlAliasForLocationDowngradesOldEntryRemovesLanguage()
1363
    {
1364
        $handler = $this->getHandler();
1365
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1366
1367
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1368
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'eng-GB');
1369
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'eng-GB');
1370
1371
        self::assertEquals(5, $this->countRows());
1372
1373
        $urlAlias = $handler->lookup('dva');
1374
        self::assertEquals(
1375
            new UrlAlias(
1376
                array(
1377
                    'id' => '0-c67ed9a09ab136fae610b6a087d82e21',
1378
                    'type' => UrlAlias::LOCATION,
1379
                    'destination' => 314,
1380
                    'languageCodes' => array('eng-GB'),
1381
                    'pathData' => array(
1382
                        array(
1383
                            'always-available' => false,
1384
                            'translations' => array(
1385
                                'cro-HR' => 'jedan',
1386
                                'eng-GB' => 'dva',
1387
                            ),
1388
                        ),
1389
                    ),
1390
                    'alwaysAvailable' => false,
1391
                    'isHistory' => false,
1392
                    'isCustom' => false,
1393
                    'forward' => false,
1394
                )
1395
            ),
1396
            $urlAlias
1397
        );
1398
1399
        $downgradedUrlAlias = $handler->lookup('jedan');
1400
        self::assertEquals(
1401
            new UrlAlias(
1402
                array(
1403
                    'id' => '0-6896260129051a949051c3847c34466f',
1404
                    'type' => UrlAlias::LOCATION,
1405
                    'destination' => 314,
1406
                    'languageCodes' => array('cro-HR'),
1407
                    'pathData' => array(
1408
                        array(
1409
                            'always-available' => false,
1410
                            'translations' => array(
1411
                                'cro-HR' => 'jedan',
1412
                                'eng-GB' => 'dva',
1413
                            ),
1414
                        ),
1415
                    ),
1416
                    'alwaysAvailable' => false,
1417
                    'isHistory' => false,
1418
                    'isCustom' => false,
1419
                    'forward' => false,
1420
                )
1421
            ),
1422
            $downgradedUrlAlias
1423
        );
1424
    }
1425
1426
    /**
1427
     * Test for the publishUrlAliasForLocation() method.
1428
     *
1429
     * @todo document
1430
     *
1431
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1432
     * @depends testPublishUrlAliasForLocation
1433
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1434
     * @group publish
1435
     */
1436
    public function testPublishUrlAliasForLocationReusesHistory()
1437
    {
1438
        $handler = $this->getHandler();
1439
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1440
1441
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1442
        $urlAlias = $handler->lookup('jedan');
1443
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR');
1444
        $countBeforeReusing = $this->countRows();
1445
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1446
        $urlAliasReusesHistory = $handler->lookup('jedan');
1447
1448
        self::assertEquals(
1449
            $countBeforeReusing,
1450
            $this->countRows()
1451
        );
1452
1453
        self::assertEquals(
1454
            $urlAlias,
1455
            $urlAliasReusesHistory
1456
        );
1457
    }
1458
1459
    /**
1460
     * Test for the publishUrlAliasForLocation() method.
1461
     *
1462
     * @todo document
1463
     *
1464
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1465
     * @depends testPublishUrlAliasForLocation
1466
     * @depends testPublishUrlAliasForLocationDowngradesOldEntryToHistory
1467
     * @group publish
1468
     */
1469
    public function testPublishUrlAliasForLocationReusesHistoryOfDifferentLanguage()
1470
    {
1471
        $handler = $this->getHandler();
1472
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1473
1474
        $handler->publishUrlAliasForLocation(314, 2, 'jedan', 'cro-HR');
1475
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'eng-GB');
1476
        $handler->publishUrlAliasForLocation(314, 2, 'one-new', 'eng-GB');
1477
        $countBeforeReusing = $this->countRows();
1478
        $handler->publishUrlAliasForLocation(314, 2, 'one-history', 'cro-HR');
1479
        $urlAliasReusesHistory = $handler->lookup('one-history');
1480
1481
        self::assertEquals(
1482
            $countBeforeReusing,
1483
            $this->countRows()
1484
        );
1485
1486
        self::assertEquals(
1487
            new UrlAlias(
1488
                array(
1489
                    'id' => '0-' . md5('one-history'),
1490
                    'type' => UrlAlias::LOCATION,
1491
                    'destination' => 314,
1492
                    'languageCodes' => array('cro-HR'),
1493
                    'pathData' => array(
1494
                        array(
1495
                            'always-available' => false,
1496
                            'translations' => array(
1497
                                'cro-HR' => 'one-history',
1498
                                'eng-GB' => 'one-new',
1499
                            ),
1500
                        ),
1501
                    ),
1502
                    'alwaysAvailable' => false,
1503
                    'isHistory' => false,
1504
                    'isCustom' => false,
1505
                    'forward' => false,
1506
                )
1507
            ),
1508
            $urlAliasReusesHistory
1509
        );
1510
    }
1511
1512
    /**
1513
     * Test for the publishUrlAliasForLocation() method.
1514
     *
1515
     * @todo document
1516
     *
1517
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1518
     * @depends testPublishUrlAliasForLocation
1519
     * @group publish
1520
     */
1521 View Code Duplication
    public function testPublishUrlAliasForLocationReusesCustomAlias()
1522
    {
1523
        $handler = $this->getHandler();
1524
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1525
1526
        $countBeforeReusing = $this->countRows();
1527
        $handler->publishUrlAliasForLocation(314, 2, 'custom-hello', 'eng-GB', false);
1528
        $urlAlias = $handler->lookup('custom-hello');
1529
1530
        self::assertEquals(
1531
            $countBeforeReusing,
1532
            $this->countRows()
1533
        );
1534
        self::assertFalse($urlAlias->isCustom);
1535
    }
1536
1537
    /**
1538
     * Test for the publishUrlAliasForLocation() method.
1539
     *
1540
     * @todo document
1541
     *
1542
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1543
     * @depends testPublishUrlAliasForLocation
1544
     */
1545
    public function testPublishUrlAliasForLocationReusingNopElement()
1546
    {
1547
        $handler = $this->getHandler();
1548
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1549
1550
        $countBeforeReusing = $this->countRows();
1551
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1552
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1553
        $publishedLocationUrlAlias = $handler->lookup('nop-element');
1554
1555
        self::assertEquals(
1556
            $countBeforeReusing,
1557
            $this->countRows()
1558
        );
1559
1560
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias', $publishedLocationUrlAlias);
1561
        self::assertEquals(
1562
            new UrlAlias(
1563
                array(
1564
                    'id' => '0-de55c2fff721217cc4cb67b58dc35f85',
1565
                    'type' => UrlAlias::LOCATION,
1566
                    'destination' => 315,
1567
                    'languageCodes' => array('eng-GB'),
1568
                    'pathData' => array(
1569
                        array(
1570
                            'always-available' => false,
1571
                            'translations' => array('eng-GB' => 'nop-element'),
1572
                        ),
1573
                    ),
1574
                    'alwaysAvailable' => false,
1575
                    'isHistory' => false,
1576
                    'isCustom' => false,
1577
                    'forward' => false,
1578
                )
1579
            ),
1580
            $publishedLocationUrlAlias
1581
        );
1582
1583
        $virtualUrlAliasReloaded = $handler->lookup('nop-element/search');
1584 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...
1585
            if ($propertyName === 'pathData') {
1586
                self::assertEquals(
1587
                    array(
1588
                        array(
1589
                            'always-available' => false,
1590
                            'translations' => array('eng-GB' => 'nop-element'),
1591
                        ),
1592
                        array(
1593
                            'always-available' => false,
1594
                            'translations' => array('eng-GB' => 'search'),
1595
                        ),
1596
                    ),
1597
                    $virtualUrlAliasReloaded->pathData
1598
                );
1599
            } else {
1600
                self::assertEquals(
1601
                    $virtualUrlAlias->$propertyName,
1602
                    $virtualUrlAliasReloaded->$propertyName
1603
                );
1604
            }
1605
        }
1606
    }
1607
1608
    /**
1609
     * Test for the publishUrlAliasForLocation() method.
1610
     *
1611
     * @todo document
1612
     *
1613
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1614
     * @depends testPublishUrlAliasForLocation
1615
     * @depends testPublishUrlAliasForLocationReusingNopElement
1616
     */
1617
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPath()
1618
    {
1619
        $handler = $this->getHandler();
1620
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1621
1622
        $countBeforeReusing = $this->countRows();
1623
        $virtualUrlAlias = $handler->lookup('nop-element/search');
1624
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1625
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1626
        $virtualUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1627
1628
        self::assertEquals(
1629
            $countBeforeReusing + 1,
1630
            $this->countRows()
1631
        );
1632
1633 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...
1634
            if ($propertyName === 'pathData') {
1635
                self::assertEquals(
1636
                    array(
1637
                        array(
1638
                            'always-available' => false,
1639
                            'translations' => array('eng-GB' => 'nop-element-renamed'),
1640
                        ),
1641
                        array(
1642
                            'always-available' => false,
1643
                            'translations' => array('eng-GB' => 'search'),
1644
                        ),
1645
                    ),
1646
                    $virtualUrlAliasChanged->pathData
1647
                );
1648
            } else {
1649
                self::assertEquals(
1650
                    $virtualUrlAlias->$propertyName,
1651
                    $virtualUrlAliasChanged->$propertyName
1652
                );
1653
            }
1654
        }
1655
    }
1656
1657
    /**
1658
     * Test for the publishUrlAliasForLocation() method.
1659
     *
1660
     * @todo document
1661
     *
1662
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1663
     * @depends testPublishUrlAliasForLocation
1664
     * @depends testPublishUrlAliasForLocationReusingNopElementChangesCustomPath
1665
     */
1666
    public function testPublishUrlAliasForLocationReusingNopElementChangesCustomPathAndCreatesHistory()
1667
    {
1668
        $handler = $this->getHandler();
1669
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
1670
1671
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element', 'eng-GB', false);
1672
        $handler->publishUrlAliasForLocation(315, 2, 'nop-element-renamed', 'eng-GB', false);
1673
1674
        $customUrlAliasChanged = $handler->lookup('nop-element-renamed/search');
1675
        $customUrlAliasHistory = $handler->lookup('nop-element/search');
1676
1677
        self::assertTrue($customUrlAliasHistory->isHistory);
1678
        $customUrlAliasHistory->isHistory = false;
1679
        self::assertEquals(
1680
            $customUrlAliasChanged,
1681
            $customUrlAliasHistory
1682
        );
1683
    }
1684
1685
    /**
1686
     * Test for the publishUrlAliasForLocation() method.
1687
     *
1688
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1689
     */
1690
    public function testPublishUrlAliasForLocationUpdatesLocationPathIdentificationString()
1691
    {
1692
        $handler = $this->getHandler();
1693
        $locationGateway = $this->getLocationGateway();
1694
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1695
1696
        // Publishes the alias indicating that language is main, triggering updating of path_identification_string
1697
        $handler->publishUrlAliasForLocation(316, 315, 'TEST TEST TEST', 'eng-GB', false, true);
1698
1699
        $locationData = $locationGateway->getBasicNodeData(316);
1700
1701
        self::assertEquals('path314/path315/test_test_test', $locationData['path_identification_string']);
1702
    }
1703
1704
    /**
1705
     * Test for the publishUrlAliasForLocation() method.
1706
     *
1707
     * @group cleanup
1708
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1709
     */
1710
    public function testPublishUrlAliasReuseNopCleanupCustomAliasIsDestroyed()
1711
    {
1712
        $handler = $this->getHandler();
1713
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_nop.php');
1714
1715
        $handler->lookup('nop-element/search');
1716
        $handler->publishUrlAliasForLocation(314, 2, 'nop-element', 'cro-HR', false);
1717
1718
        $urlAlias = $handler->lookup('jedan');
1719
        $this->assertEquals(
1720
            new UrlAlias(
1721
                array(
1722
                    'id' => '0-' . md5('jedan'),
1723
                    'type' => UrlAlias::LOCATION,
1724
                    'destination' => 314,
1725
                    'pathData' => array(
1726
                        array(
1727
                            'always-available' => false,
1728
                            'translations' => array('cro-HR' => 'jedan'),
1729
                        ),
1730
                    ),
1731
                    'languageCodes' => array('cro-HR'),
1732
                    'alwaysAvailable' => false,
1733
                    'isHistory' => true,
1734
                    'isCustom' => false,
1735
                    'forward' => false,
1736
                )
1737
            ),
1738
            $urlAlias
1739
        );
1740
1741
        $urlAlias = $handler->lookup('nop-element');
1742
        $this->assertEquals(
1743
            new UrlAlias(
1744
                array(
1745
                    'id' => '0-' . md5('nop-element'),
1746
                    'type' => UrlAlias::LOCATION,
1747
                    'destination' => 314,
1748
                    'pathData' => array(
1749
                        array(
1750
                            'always-available' => false,
1751
                            'translations' => array(
1752
                                'cro-HR' => 'nop-element',
1753
                                'eng-GB' => 'dva',
1754
                            ),
1755
                        ),
1756
                    ),
1757
                    'languageCodes' => array(
1758
                        'cro-HR',
1759
                    ),
1760
                    'alwaysAvailable' => false,
1761
                    'isHistory' => false,
1762
                    'isCustom' => false,
1763
                    'forward' => false,
1764
                )
1765
            ),
1766
            $urlAlias
1767
        );
1768
1769
        try {
1770
            $handler->lookup('nop-element/search');
1771
            $this->fail('Custom alias is not destroyed');
1772
        } catch (NotFoundException $e) {
1773
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
1774
            // on the same level (that means link and ID are updated to the existing alias ID,
1775
            // so custom alias children entries are no longer properly linked (parent-link))
1776
        }
1777
    }
1778
1779
    /**
1780
     * Test for the publishUrlAliasForLocation() method.
1781
     *
1782
     * @group cleanup
1783
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1784
     */
1785 View Code Duplication
    public function testPublishUrlAliasReuseHistoryCleanup()
1786
    {
1787
        $handler = $this->getHandler();
1788
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_history.php');
1789
1790
        $handler->publishUrlAliasForLocation(314, 2, 'tri', 'cro-HR', false);
1791
1792
        $urlAlias = $handler->lookup('jedan');
1793
        $this->assertEquals(
1794
            new UrlAlias(
1795
                array(
1796
                    'id' => '0-' . md5('jedan'),
1797
                    'type' => UrlAlias::LOCATION,
1798
                    'destination' => 314,
1799
                    'pathData' => array(
1800
                        array(
1801
                            'always-available' => false,
1802
                            'translations' => array('cro-HR' => 'jedan'),
1803
                        ),
1804
                    ),
1805
                    'languageCodes' => array('cro-HR'),
1806
                    'alwaysAvailable' => false,
1807
                    'isHistory' => true,
1808
                    'isCustom' => false,
1809
                    'forward' => false,
1810
                )
1811
            ),
1812
            $urlAlias
1813
        );
1814
1815
        $urlAlias = $handler->lookup('tri');
1816
        $this->assertEquals(
1817
            new UrlAlias(
1818
                array(
1819
                    'id' => '0-' . md5('tri'),
1820
                    'type' => UrlAlias::LOCATION,
1821
                    'destination' => 314,
1822
                    'pathData' => array(
1823
                        array(
1824
                            'always-available' => false,
1825
                            'translations' => array(
1826
                                'cro-HR' => 'tri',
1827
                                'eng-GB' => 'dva',
1828
                            ),
1829
                        ),
1830
                    ),
1831
                    'languageCodes' => array(
1832
                        'cro-HR',
1833
                    ),
1834
                    'alwaysAvailable' => false,
1835
                    'isHistory' => false,
1836
                    'isCustom' => false,
1837
                    'forward' => false,
1838
                )
1839
            ),
1840
            $urlAlias
1841
        );
1842
    }
1843
1844
    /**
1845
     * Test for the publishUrlAliasForLocation() method.
1846
     *
1847
     * @group cleanup
1848
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
1849
     */
1850 View Code Duplication
    public function testPublishUrlAliasReuseAutogeneratedCleanup()
1851
    {
1852
        $handler = $this->getHandler();
1853
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_cleanup_reusing.php');
1854
1855
        $handler->publishUrlAliasForLocation(314, 2, 'dva', 'cro-HR', false);
1856
1857
        $urlAlias = $handler->lookup('jedan');
1858
        $this->assertEquals(
1859
            new UrlAlias(
1860
                array(
1861
                    'id' => '0-' . md5('jedan'),
1862
                    'type' => UrlAlias::LOCATION,
1863
                    'destination' => 314,
1864
                    'pathData' => array(
1865
                        array(
1866
                            'always-available' => false,
1867
                            'translations' => array('cro-HR' => 'jedan'),
1868
                        ),
1869
                    ),
1870
                    'languageCodes' => array('cro-HR'),
1871
                    'alwaysAvailable' => false,
1872
                    'isHistory' => true,
1873
                    'isCustom' => false,
1874
                    'forward' => false,
1875
                )
1876
            ),
1877
            $urlAlias
1878
        );
1879
1880
        $urlAlias = $handler->lookup('dva');
1881
        $this->assertEquals(
1882
            new UrlAlias(
1883
                array(
1884
                    'id' => '0-' . md5('dva'),
1885
                    'type' => UrlAlias::LOCATION,
1886
                    'destination' => 314,
1887
                    'pathData' => array(
1888
                        array(
1889
                            'always-available' => false,
1890
                            'translations' => array(
1891
                                'cro-HR' => 'dva',
1892
                                'eng-GB' => 'dva',
1893
                            ),
1894
                        ),
1895
                    ),
1896
                    'languageCodes' => array(
1897
                        'cro-HR',
1898
                        'eng-GB',
1899
                    ),
1900
                    'alwaysAvailable' => false,
1901
                    'isHistory' => false,
1902
                    'isCustom' => false,
1903
                    'forward' => false,
1904
                )
1905
            ),
1906
            $urlAlias
1907
        );
1908
    }
1909
1910
    /**
1911
     * Test for the createCustomUrlAlias() method.
1912
     *
1913
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createCustomUrlAlias
1914
     * @group create
1915
     * @group custom
1916
     */
1917 View Code Duplication
    public function testCreateCustomUrlAliasBehaviour()
1918
    {
1919
        $handlerMock = $this->getPartlyMockedHandler(array('createUrlAlias'));
1920
1921
        $handlerMock->expects(
1922
            $this->once()
1923
        )->method(
1924
            'createUrlAlias'
1925
        )->with(
1926
            $this->equalTo('eznode:1'),
1927
            $this->equalTo('path'),
1928
            $this->equalTo(false),
1929
            $this->equalTo(null),
1930
            $this->equalTo(false)
1931
        )->will(
1932
            $this->returnValue(
1933
                new UrlAlias()
1934
            )
1935
        );
1936
1937
        $this->assertInstanceOf(
1938
            'eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias',
1939
            $handlerMock->createCustomUrlAlias(1, 'path')
1940
        );
1941
    }
1942
1943
    /**
1944
     * Test for the createGlobalUrlAlias() method.
1945
     *
1946
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createGlobalUrlAlias
1947
     * @group create
1948
     * @group global
1949
     */
1950 View Code Duplication
    public function testCreateGlobalUrlAliasBehaviour()
1951
    {
1952
        $handlerMock = $this->getPartlyMockedHandler(array('createUrlAlias'));
1953
1954
        $handlerMock->expects(
1955
            $this->once()
1956
        )->method(
1957
            'createUrlAlias'
1958
        )->with(
1959
            $this->equalTo('module/module'),
1960
            $this->equalTo('path'),
1961
            $this->equalTo(false),
1962
            $this->equalTo(null),
1963
            $this->equalTo(false)
1964
        )->will(
1965
            $this->returnValue(
1966
                new UrlAlias()
1967
            )
1968
        );
1969
1970
        $this->assertInstanceOf(
1971
            'eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias',
1972
            $handlerMock->createGlobalUrlAlias('module/module', 'path')
1973
        );
1974
    }
1975
1976
    /**
1977
     * Test for the createUrlAlias() method.
1978
     *
1979
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
1980
     * @group create
1981
     * @group custom
1982
     */
1983
    public function testCreateCustomUrlAlias()
1984
    {
1985
        $handler = $this->getHandler();
1986
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
1987
1988
        $path = 'custom-location-alias';
1989
        $customUrlAlias = $handler->createCustomUrlAlias(
1990
            314,
1991
            $path,
1992
            false,
1993
            'cro-HR',
1994
            false
1995
        );
1996
1997
        self::assertEquals(4, $this->countRows());
1998
        self::assertEquals(
1999
            new UrlAlias(
2000
                array(
2001
                    'id' => '0-' . md5($path),
2002
                    'type' => UrlAlias::LOCATION,
2003
                    'destination' => 314,
2004
                    'pathData' => array(
2005
                        array(
2006
                            'always-available' => false,
2007
                            'translations' => array(
2008
                                'cro-HR' => 'custom-location-alias',
2009
                            ),
2010
                        ),
2011
                    ),
2012
                    'languageCodes' => array('cro-HR'),
2013
                    'alwaysAvailable' => false,
2014
                    'isHistory' => false,
2015
                    'isCustom' => true,
2016
                    'forward' => false,
2017
                )
2018
            ),
2019
            $customUrlAlias
2020
        );
2021
    }
2022
2023
    /**
2024
     * Test for the createUrlAlias() method.
2025
     *
2026
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2027
     * @group create
2028
     * @group custom
2029
     */
2030
    public function testCreateCustomUrlAliasWithNonameParts()
2031
    {
2032
        $handler = $this->getHandler();
2033
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2034
2035
        $path = 'there-is-a//custom-location-alias//here';
2036
        $customUrlAlias = $handler->createCustomUrlAlias(
2037
            314,
2038
            $path,
2039
            false,
2040
            'cro-HR',
2041
            false
2042
        );
2043
2044
        self::assertEquals(8, $this->countRows());
2045
2046
        self::assertEquals(
2047
            new UrlAlias(
2048
                array(
2049
                    'id' => '7-' . md5('here'),
2050
                    'type' => UrlAlias::LOCATION,
2051
                    'destination' => 314,
2052
                    'pathData' => array(
2053
                        array(
2054
                            'always-available' => true,
2055
                            'translations' => array(
2056
                                'always-available' => 'there-is-a',
2057
                            ),
2058
                        ),
2059
                        array(
2060
                            'always-available' => true,
2061
                            'translations' => array(
2062
                                'always-available' => 'noname2',
2063
                            ),
2064
                        ),
2065
                        array(
2066
                            'always-available' => true,
2067
                            'translations' => array(
2068
                                'always-available' => 'custom-location-alias',
2069
                            ),
2070
                        ),
2071
                        array(
2072
                            'always-available' => true,
2073
                            'translations' => array(
2074
                                'always-available' => 'noname4',
2075
                            ),
2076
                        ),
2077
                        array(
2078
                            'always-available' => false,
2079
                            'translations' => array(
2080
                                'cro-HR' => 'here',
2081
                            ),
2082
                        ),
2083
                    ),
2084
                    'languageCodes' => array('cro-HR'),
2085
                    'alwaysAvailable' => false,
2086
                    'isHistory' => false,
2087
                    'isCustom' => true,
2088
                    'forward' => false,
2089
                )
2090
            ),
2091
            $customUrlAlias
2092
        );
2093
    }
2094
2095
    /**
2096
     * Test for the createUrlAlias() method.
2097
     *
2098
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2099
     * @group create
2100
     * @group custom
2101
     *
2102
     * @todo pathData
2103
     */
2104
    public function testCreatedCustomUrlAliasIsLoadable()
2105
    {
2106
        $handler = $this->getHandler();
2107
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2108
2109
        $path = 'custom-location-alias';
2110
        $customUrlAlias = $handler->createCustomUrlAlias(
2111
            314,
2112
            $path,
2113
            false,
2114
            'cro-HR',
2115
            false
2116
        );
2117
        $loadedCustomUrlAlias = $handler->lookup($path);
2118
2119
        self::assertEquals(4, $this->countRows());
2120
2121
        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...
2122
            if ($propertyName === 'pathData') {
2123
                self::assertEquals(
2124
                    array(
2125
                        array(
2126
                            'always-available' => false,
2127
                            'translations' => array('cro-HR' => $path),
2128
                        ),
2129
                    ),
2130
                    $loadedCustomUrlAlias->$propertyName
2131
                );
2132
            } else {
2133
                self::assertEquals(
2134
                    $customUrlAlias->$propertyName,
2135
                    $loadedCustomUrlAlias->$propertyName
2136
                );
2137
            }
2138
        }
2139
    }
2140
2141
    /**
2142
     * Test for the createUrlAlias() method.
2143
     *
2144
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2145
     * @group create
2146
     * @group custom
2147
     */
2148
    public function testCreateCustomUrlAliasWithNopElement()
2149
    {
2150
        $handler = $this->getHandler();
2151
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
2152
2153
        $path = 'ribar/palunko';
2154
        $customUrlAlias = $handler->createCustomUrlAlias(
2155
            314,
2156
            $path,
2157
            false,
2158
            'cro-HR',
2159
            true
2160
        );
2161
2162
        self::assertEquals(5, $this->countRows());
2163
        self::assertEquals(
2164
            new UrlAlias(
2165
                array(
2166
                    'id' => '4-' . md5('palunko'),
2167
                    'type' => UrlAlias::LOCATION,
2168
                    'destination' => 314,
2169
                    'pathData' => array(
2170
                        array(
2171
                            'always-available' => true,
2172
                            'translations' => array(
2173
                                'always-available' => 'ribar',
2174
                            ),
2175
                        ),
2176
                        array(
2177
                            'always-available' => true,
2178
                            'translations' => array(
2179
                                'cro-HR' => 'palunko',
2180
                            ),
2181
                        ),
2182
                    ),
2183
                    'languageCodes' => array('cro-HR'),
2184
                    'alwaysAvailable' => true,
2185
                    'isHistory' => false,
2186
                    'isCustom' => true,
2187
                    'forward' => false,
2188
                )
2189
            ),
2190
            $customUrlAlias
2191
        );
2192
2193
        return $handler;
2194
    }
2195
2196
    /**
2197
     * Test for the createUrlAlias() method.
2198
     *
2199
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2200
     * @depends testCreateCustomUrlAliasWithNopElement
2201
     * @group create
2202
     * @group custom
2203
     */
2204
    public function testCreateUrlAliasWithNopElementCreatesValidNopElement(Handler $handler)
2205
    {
2206
        $url = 'ribar';
2207
        $urlAlias = $handler->lookup($url);
2208
2209
        $this->assertVirtualUrlAliasValid(
2210
            $urlAlias,
2211
            '0-' . md5($url)
2212
        );
2213
    }
2214
2215
    /**
2216
     * Test for the createUrlAlias() method.
2217
     *
2218
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2219
     * @group create
2220
     * @group custom
2221
     */
2222 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistory()
2223
    {
2224
        $handler = $this->getHandler();
2225
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2226
2227
        $countBeforeReusing = $this->countRows();
2228
        $handler->createCustomUrlAlias(
2229
            314,
2230
            'history-hello',
2231
            true,
2232
            'eng-GB',
2233
            true
2234
        );
2235
2236
        self::assertEquals(
2237
            $countBeforeReusing,
2238
            $this->countRows()
2239
        );
2240
        self::assertEquals(
2241
            new UrlAlias(
2242
                array(
2243
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2244
                    'type' => UrlAlias::LOCATION,
2245
                    'destination' => 314,
2246
                    'languageCodes' => array('eng-GB'),
2247
                    'pathData' => array(
2248
                        array(
2249
                            'always-available' => true,
2250
                            'translations' => array('eng-GB' => 'history-hello'),
2251
                        ),
2252
                    ),
2253
                    'alwaysAvailable' => true,
2254
                    'isHistory' => false,
2255
                    'isCustom' => true,
2256
                    'forward' => true,
2257
                )
2258
            ),
2259
            $handler->lookup('history-hello')
2260
        );
2261
    }
2262
2263
    /**
2264
     * Test for the createUrlAlias() method.
2265
     *
2266
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2267
     * @group create
2268
     * @group custom
2269
     */
2270 View Code Duplication
    public function testCreateCustomUrlAliasReusesHistoryOfDifferentLanguage()
2271
    {
2272
        $handler = $this->getHandler();
2273
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2274
2275
        $countBeforeReusing = $this->countRows();
2276
        $handler->createCustomUrlAlias(
2277
            314,
2278
            'history-hello',
2279
            true,
2280
            'cro-HR',
2281
            true
2282
        );
2283
2284
        self::assertEquals(
2285
            $countBeforeReusing,
2286
            $this->countRows()
2287
        );
2288
        self::assertEquals(
2289
            new UrlAlias(
2290
                array(
2291
                    'id' => '0-da94285592c46d4396d3ca6904a4aa8f',
2292
                    'type' => UrlAlias::LOCATION,
2293
                    'destination' => 314,
2294
                    'languageCodes' => array('cro-HR'),
2295
                    'pathData' => array(
2296
                        array(
2297
                            'always-available' => true,
2298
                            'translations' => array('cro-HR' => 'history-hello'),
2299
                        ),
2300
                    ),
2301
                    'alwaysAvailable' => true,
2302
                    'isHistory' => false,
2303
                    'isCustom' => true,
2304
                    'forward' => true,
2305
                )
2306
            ),
2307
            $handler->lookup('history-hello')
2308
        );
2309
    }
2310
2311
    /**
2312
     * Test for the createUrlAlias() method.
2313
     *
2314
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2315
     * @group create
2316
     * @group custom
2317
     */
2318
    public function testCreateCustomUrlAliasReusesNopElement()
2319
    {
2320
        $handler = $this->getHandler();
2321
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2322
2323
        $countBeforeReusing = $this->countRows();
2324
        $handler->createCustomUrlAlias(
2325
            314,
2326
            'nop-element',
2327
            true,
2328
            'cro-HR',
2329
            true
2330
        );
2331
2332
        self::assertEquals(
2333
            $countBeforeReusing,
2334
            $this->countRows()
2335
        );
2336
2337
        // Check that custom alias whose nop element was reused still works as expected
2338
        self::assertEquals(
2339
            new UrlAlias(
2340
                array(
2341
                    'id' => '2-06a943c59f33a34bb5924aaf72cd2995',
2342
                    'type' => UrlAlias::RESOURCE,
2343
                    'destination' => 'content/search',
2344
                    'languageCodes' => array('eng-GB'),
2345
                    'pathData' => array(
2346
                        array(
2347
                            'always-available' => true,
2348
                            'translations' => array('cro-HR' => 'nop-element'),
2349
                        ),
2350
                        array(
2351
                            'always-available' => false,
2352
                            'translations' => array('eng-GB' => 'search'),
2353
                        ),
2354
                    ),
2355
                    'alwaysAvailable' => false,
2356
                    'isHistory' => false,
2357
                    'isCustom' => true,
2358
                    'forward' => false,
2359
                )
2360
            ),
2361
            $handler->lookup('nop-element/search')
2362
        );
2363
    }
2364
2365
    /**
2366
     * Test for the createUrlAlias() method.
2367
     *
2368
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::createUrlAlias
2369
     * @group create
2370
     * @group custom
2371
     */
2372 View Code Duplication
    public function testCreateCustomUrlAliasReusesLocationElement()
2373
    {
2374
        $handler = $this->getHandler();
2375
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_reusing.php');
2376
2377
        $countBeforeReusing = $this->countRows();
2378
        $locationUrlAlias = $handler->lookup('autogenerated-hello');
2379
        $handler->createCustomUrlAlias(
2380
            315,
2381
            'autogenerated-hello/custom-location-alias-for-315',
2382
            true,
2383
            'cro-HR',
2384
            true
2385
        );
2386
2387
        self::assertEquals(
2388
            $countBeforeReusing + 1,
2389
            $this->countRows()
2390
        );
2391
2392
        // Check that location alias still works as expected
2393
        self::assertEquals(
2394
            $locationUrlAlias,
2395
            $handler->lookup('autogenerated-hello')
2396
        );
2397
    }
2398
2399
    /**
2400
     * Test for the listGlobalURLAliases() method.
2401
     *
2402
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2403
     * @depends testLookupResourceUrlAlias
2404
     */
2405
    public function testListGlobalURLAliases()
2406
    {
2407
        $handler = $this->getHandler();
2408
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2409
2410
        $globalAliasList = $handler->listGlobalURLAliases();
2411
2412
        self::assertEquals(
2413
            array(
2414
                $handler->lookup('is-alive'),
2415
                $handler->lookup('is-alive/then/search'),
2416
                $handler->lookup('nop-element/search'),
2417
            ),
2418
            $globalAliasList
2419
        );
2420
    }
2421
2422
    /**
2423
     * Test for the listGlobalURLAliases() method.
2424
     *
2425
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2426
     * @depends testLookupResourceUrlAlias
2427
     */
2428 View Code Duplication
    public function testListGlobalURLAliasesWithLanguageCode()
2429
    {
2430
        $handler = $this->getHandler();
2431
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2432
2433
        $globalAliasList = $handler->listGlobalURLAliases('eng-GB');
2434
2435
        self::assertEquals(
2436
            array(
2437
                $handler->lookup('is-alive'),
2438
                $handler->lookup('nop-element/search'),
2439
            ),
2440
            $globalAliasList
2441
        );
2442
    }
2443
2444
    /**
2445
     * Test for the listGlobalURLAliases() method.
2446
     *
2447
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2448
     * @depends testLookupResourceUrlAlias
2449
     */
2450
    public function testListGlobalURLAliasesWithOffset()
2451
    {
2452
        $handler = $this->getHandler();
2453
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2454
2455
        $globalAliasList = $handler->listGlobalURLAliases(null, 2);
2456
2457
        self::assertEquals(
2458
            array(
2459
                $handler->lookup('nop-element/search'),
2460
            ),
2461
            $globalAliasList
2462
        );
2463
    }
2464
2465
    /**
2466
     * Test for the listGlobalURLAliases() method.
2467
     *
2468
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::listGlobalURLAliases
2469
     * @depends testLookupResourceUrlAlias
2470
     */
2471
    public function testListGlobalURLAliasesWithOffsetAndLimit()
2472
    {
2473
        $handler = $this->getHandler();
2474
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2475
2476
        $globalAliasList = $handler->listGlobalURLAliases(null, 1, 1);
2477
2478
        self::assertEquals(
2479
            array(
2480
                $handler->lookup('is-alive/then/search'),
2481
            ),
2482
            $globalAliasList
2483
        );
2484
    }
2485
2486
    /**
2487
     * Test for the locationDeleted() method.
2488
     *
2489
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationDeleted
2490
     */
2491
    public function testLocationDeleted()
2492
    {
2493
        $handler = $this->getHandler();
2494
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_delete.php');
2495
2496
        $countBeforeDeleting = $this->countRows();
2497
2498
        $handler->locationDeleted(5);
2499
2500
        self::assertEquals(
2501
            $countBeforeDeleting - 5,
2502
            $this->countRows()
2503
        );
2504
2505
        self::assertEmpty(
2506
            $handler->listURLAliasesForLocation(5)
2507
        );
2508
2509
        $removedAliases = array(
2510
            'moved-original-parent/moved-history',
2511
            'moved-original-parent/sub',
2512
            'moved-original-parent',
2513
            'moved-original-parent-history',
2514
            'custom-below/moved-original-parent-custom',
2515
        );
2516
        foreach ($removedAliases as $path) {
2517
            try {
2518
                $handler->lookup($path);
2519
                $this->fail("Alias '$path' not removed!");
2520
            } catch (NotFoundException $e) {
2521
                // Do nothing
2522
            }
2523
        }
2524
    }
2525
2526
    /**
2527
     * Test for the locationMoved() method.
2528
     *
2529
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2530
     */
2531 View Code Duplication
    public function testLocationMovedHistorize()
2532
    {
2533
        $handler = $this->getHandler();
2534
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2535
2536
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2537
        $handler->locationMoved(4, 2, 3);
2538
2539
        $urlAlias = $handler->lookup('move-this');
2540
        self::assertEquals(
2541
            new UrlAlias(
2542
                array(
2543
                    'id' => '0-' . md5('move-this'),
2544
                    'type' => UrlAlias::LOCATION,
2545
                    'destination' => '4',
2546
                    'languageCodes' => array('eng-GB'),
2547
                    'pathData' => array(
2548
                        array(
2549
                            'always-available' => false,
2550
                            'translations' => array('eng-GB' => 'move-this'),
2551
                        ),
2552
                    ),
2553
                    'alwaysAvailable' => false,
2554
                    'isHistory' => true,
2555
                    'isCustom' => false,
2556
                    'forward' => false,
2557
                )
2558
            ),
2559
            $urlAlias
2560
        );
2561
    }
2562
2563
    /**
2564
     * Test for the locationMoved() method.
2565
     *
2566
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2567
     */
2568 View Code Duplication
    public function testLocationMovedHistory()
2569
    {
2570
        $handler = $this->getHandler();
2571
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2572
2573
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2574
        $handler->locationMoved(4, 2, 3);
2575
2576
        $urlAlias = $handler->lookup('move-this-history');
2577
        self::assertEquals(
2578
            new UrlAlias(
2579
                array(
2580
                    'id' => '0-' . md5('move-this-history'),
2581
                    'type' => UrlAlias::LOCATION,
2582
                    'destination' => '4',
2583
                    'languageCodes' => array('eng-GB'),
2584
                    'pathData' => array(
2585
                        array(
2586
                            'always-available' => false,
2587
                            'translations' => array('eng-GB' => 'move-this-history'),
2588
                        ),
2589
                    ),
2590
                    'alwaysAvailable' => false,
2591
                    'isHistory' => true,
2592
                    'isCustom' => false,
2593
                    'forward' => false,
2594
                )
2595
            ),
2596
            $urlAlias
2597
        );
2598
    }
2599
2600
    /**
2601
     * Test for the locationMoved() method.
2602
     *
2603
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2604
     */
2605 View Code Duplication
    public function testLocationMovedHistorySubtree()
2606
    {
2607
        $handler = $this->getHandler();
2608
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2609
2610
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2611
        $handler->locationMoved(4, 2, 3);
2612
2613
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2614
        self::assertEquals(
2615
            new UrlAlias(
2616
                array(
2617
                    'id' => '5-' . md5('sub2'),
2618
                    'type' => UrlAlias::LOCATION,
2619
                    'destination' => '6',
2620
                    'languageCodes' => array('eng-GB'),
2621
                    'pathData' => array(
2622
                        array(
2623
                            'always-available' => false,
2624
                            'translations' => array('eng-GB' => 'move-this'),
2625
                        ),
2626
                        array(
2627
                            'always-available' => false,
2628
                            'translations' => array('eng-GB' => 'sub1'),
2629
                        ),
2630
                        array(
2631
                            'always-available' => false,
2632
                            'translations' => array('eng-GB' => 'sub2'),
2633
                        ),
2634
                    ),
2635
                    'alwaysAvailable' => false,
2636
                    'isHistory' => true,
2637
                    'isCustom' => false,
2638
                    'forward' => false,
2639
                )
2640
            ),
2641
            $urlAlias
2642
        );
2643
    }
2644
2645
    /**
2646
     * Test for the locationMoved() method.
2647
     *
2648
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2649
     */
2650 View Code Duplication
    public function testLocationMovedReparent()
2651
    {
2652
        $handler = $this->getHandler();
2653
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2654
2655
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2656
        $handler->locationMoved(4, 2, 3);
2657
2658
        $urlAlias = $handler->lookup('move-here/move-this/sub1');
2659
        self::assertEquals(
2660
            new UrlAlias(
2661
                array(
2662
                    'id' => '9-' . md5('sub1'),
2663
                    'type' => UrlAlias::LOCATION,
2664
                    'destination' => '5',
2665
                    'languageCodes' => array('eng-GB'),
2666
                    'pathData' => array(
2667
                        array(
2668
                            'always-available' => false,
2669
                            'translations' => array('eng-GB' => 'move-here'),
2670
                        ),
2671
                        array(
2672
                            'always-available' => false,
2673
                            'translations' => array('eng-GB' => 'move-this'),
2674
                        ),
2675
                        array(
2676
                            'always-available' => false,
2677
                            'translations' => array('eng-GB' => 'sub1'),
2678
                        ),
2679
                    ),
2680
                    'alwaysAvailable' => false,
2681
                    'isHistory' => false,
2682
                    'isCustom' => false,
2683
                    'forward' => false,
2684
                )
2685
            ),
2686
            $urlAlias
2687
        );
2688
    }
2689
2690
    /**
2691
     * Test for the locationMoved() method.
2692
     *
2693
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2694
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2695
     */
2696 View Code Duplication
    public function testLocationMovedReparentHistory()
2697
    {
2698
        $handler = $this->getHandler();
2699
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2700
2701
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2702
        $handler->locationMoved(4, 2, 3);
2703
2704
        $handler->lookup('move-here/move-this-history');
2705
    }
2706
2707
    /**
2708
     * Test for the locationMoved() method.
2709
     *
2710
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2711
     */
2712 View Code Duplication
    public function testLocationMovedReparentSubtree()
2713
    {
2714
        $handler = $this->getHandler();
2715
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2716
2717
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2718
        $handler->locationMoved(4, 2, 3);
2719
2720
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2721
        self::assertEquals(
2722
            new UrlAlias(
2723
                array(
2724
                    'id' => '5-' . md5('sub2'),
2725
                    'type' => UrlAlias::LOCATION,
2726
                    'destination' => '6',
2727
                    'languageCodes' => array('eng-GB'),
2728
                    'pathData' => array(
2729
                        array(
2730
                            'always-available' => false,
2731
                            'translations' => array('eng-GB' => 'move-here'),
2732
                        ),
2733
                        array(
2734
                            'always-available' => false,
2735
                            'translations' => array('eng-GB' => 'move-this'),
2736
                        ),
2737
                        array(
2738
                            'always-available' => false,
2739
                            'translations' => array('eng-GB' => 'sub1'),
2740
                        ),
2741
                        array(
2742
                            'always-available' => false,
2743
                            'translations' => array('eng-GB' => 'sub2'),
2744
                        ),
2745
                    ),
2746
                    'alwaysAvailable' => false,
2747
                    'isHistory' => false,
2748
                    'isCustom' => false,
2749
                    'forward' => false,
2750
                )
2751
            ),
2752
            $urlAlias
2753
        );
2754
    }
2755
2756
    /**
2757
     * Test for the locationMoved() method.
2758
     *
2759
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationMoved
2760
     */
2761 View Code Duplication
    public function testLocationMovedReparentSubtreeHistory()
2762
    {
2763
        $handler = $this->getHandler();
2764
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_move.php');
2765
2766
        $handler->publishUrlAliasForLocation(4, 3, 'move-this', 'eng-GB', false);
2767
        $handler->locationMoved(4, 2, 3);
2768
2769
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2-history');
2770
        self::assertEquals(
2771
            new UrlAlias(
2772
                array(
2773
                    'id' => '5-' . md5('sub2-history'),
2774
                    'type' => UrlAlias::LOCATION,
2775
                    'destination' => '6',
2776
                    'languageCodes' => array('eng-GB'),
2777
                    'pathData' => array(
2778
                        array(
2779
                            'always-available' => false,
2780
                            'translations' => array('eng-GB' => 'move-here'),
2781
                        ),
2782
                        array(
2783
                            'always-available' => false,
2784
                            'translations' => array('eng-GB' => 'move-this'),
2785
                        ),
2786
                        array(
2787
                            'always-available' => false,
2788
                            'translations' => array('eng-GB' => 'sub1'),
2789
                        ),
2790
                        array(
2791
                            'always-available' => false,
2792
                            'translations' => array('eng-GB' => 'sub2-history'),
2793
                        ),
2794
                    ),
2795
                    'alwaysAvailable' => false,
2796
                    'isHistory' => true,
2797
                    'isCustom' => false,
2798
                    'forward' => false,
2799
                )
2800
            ),
2801
            $urlAlias
2802
        );
2803
    }
2804
2805
    /**
2806
     * Test for the locationCopied() method.
2807
     *
2808
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2809
     */
2810 View Code Duplication
    public function testLocationCopiedCopiedLocationAliasIsValid()
2811
    {
2812
        $handler = $this->getHandler();
2813
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2814
2815
        $urlAlias = $handler->lookup('move-this');
2816
2817
        $handler->locationCopied(4, 400, 3);
2818
2819
        self::assertEquals(
2820
            $urlAlias,
2821
            $handler->lookup('move-this')
2822
        );
2823
    }
2824
2825
    /**
2826
     * Test for the locationCopied() method.
2827
     *
2828
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2829
     */
2830 View Code Duplication
    public function testLocationCopiedCopiedSubtreeIsValid()
2831
    {
2832
        $handler = $this->getHandler();
2833
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2834
2835
        $urlAlias = $handler->lookup('move-this/sub1/sub2');
2836
2837
        $handler->locationCopied(4, 400, 3);
2838
2839
        self::assertEquals(
2840
            $urlAlias,
2841
            $handler->lookup('move-this/sub1/sub2')
2842
        );
2843
    }
2844
2845
    /**
2846
     * Test for the locationCopied() method.
2847
     *
2848
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2849
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2850
     */
2851 View Code Duplication
    public function testLocationCopiedHistoryNotCopied()
2852
    {
2853
        $handler = $this->getHandler();
2854
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2855
2856
        $handler->locationCopied(4, 400, 3);
2857
2858
        $handler->lookup('move-here/move-this-history');
2859
    }
2860
2861
    /**
2862
     * Test for the locationCopied() method.
2863
     *
2864
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2865
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2866
     */
2867 View Code Duplication
    public function testLocationCopiedSubtreeHistoryNotCopied()
2868
    {
2869
        $handler = $this->getHandler();
2870
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2871
2872
        $handler->locationCopied(4, 400, 3);
2873
2874
        $handler->lookup('move-here/move-this/sub1/sub2-history');
2875
    }
2876
2877
    /**
2878
     * Test for the locationCopied() method.
2879
     *
2880
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationCopied
2881
     */
2882
    public function testLocationCopiedSubtree()
2883
    {
2884
        $handler = $this->getHandler();
2885
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_copy.php');
2886
2887
        $countBeforeCopying = $this->countRows();
2888
2889
        $handler->locationCopied(4, 400, 3);
2890
2891
        self::assertEquals(
2892
            $countBeforeCopying + 2,
2893
            $this->countRows()
2894
        );
2895
2896
        $urlAlias = $handler->lookup('move-here/move-this/sub1/sub2');
2897
        self::assertEquals(
2898
            new UrlAlias(
2899
                array(
2900
                    'id' => '10-' . md5('sub2'),
2901
                    'type' => UrlAlias::LOCATION,
2902
                    'destination' => 600,
2903
                    'languageCodes' => array('eng-GB'),
2904
                    'pathData' => array(
2905
                        array(
2906
                            'always-available' => false,
2907
                            'translations' => array('eng-GB' => 'move-here'),
2908
                        ),
2909
                        array(
2910
                            'always-available' => false,
2911
                            'translations' => array('eng-GB' => 'move-this'),
2912
                        ),
2913
                        array(
2914
                            'always-available' => false,
2915
                            'translations' => array('eng-GB' => 'sub1'),
2916
                        ),
2917
                        array(
2918
                            'always-available' => false,
2919
                            'translations' => array('eng-GB' => 'sub2'),
2920
                        ),
2921
                    ),
2922
                    'alwaysAvailable' => false,
2923
                    'isHistory' => false,
2924
                    'isCustom' => false,
2925
                    'forward' => false,
2926
                )
2927
            ),
2928
            $urlAlias
2929
        );
2930
    }
2931
2932
    /**
2933
     * Test for the loadUrlAlias() method.
2934
     *
2935
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2936
     * @dataProvider providerForTestLookupLocationMultipleLanguages
2937
     */
2938 View Code Duplication
    public function testLoadAutogeneratedUrlAlias(
2939
        $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...
2940
        array $pathData,
2941
        array $languageCodes,
2942
        $alwaysAvailable,
2943
        $locationId,
2944
        $id
2945
    ) {
2946
        $handler = $this->getHandler();
2947
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
2948
2949
        $urlAlias = $handler->loadUrlAlias($id);
2950
2951
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias', $urlAlias);
2952
        self::assertEquals(
2953
            new UrlAlias(
2954
                array(
2955
                    'id' => $id,
2956
                    'type' => UrlAlias::LOCATION,
2957
                    'destination' => $locationId,
2958
                    'languageCodes' => $languageCodes,
2959
                    'pathData' => $pathData,
2960
                    'alwaysAvailable' => $alwaysAvailable,
2961
                    'isHistory' => false,
2962
                    'isCustom' => false,
2963
                    'forward' => false,
2964
                )
2965
            ),
2966
            $urlAlias
2967
        );
2968
    }
2969
2970
    /**
2971
     * Test for the loadUrlAlias() method.
2972
     *
2973
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2974
     * @dataProvider providerForTestLookupResourceUrlAlias
2975
     */
2976 View Code Duplication
    public function testLoadResourceUrlAlias(
2977
        $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...
2978
        $pathData,
2979
        array $languageCodes,
2980
        $forward,
2981
        $alwaysAvailable,
2982
        $destination,
2983
        $id
2984
    ) {
2985
        $handler = $this->getHandler();
2986
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
2987
2988
        $urlAlias = $handler->loadUrlAlias($id);
2989
2990
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias', $urlAlias);
2991
        self::assertEquals(
2992
            new UrlAlias(
2993
                array(
2994
                    'id' => $id,
2995
                    'type' => UrlAlias::RESOURCE,
2996
                    'destination' => $destination,
2997
                    'languageCodes' => $languageCodes,
2998
                    'pathData' => $pathData,
2999
                    'alwaysAvailable' => $alwaysAvailable,
3000
                    'isHistory' => false,
3001
                    'isCustom' => true,
3002
                    'forward' => $forward,
3003
                )
3004
            ),
3005
            $urlAlias
3006
        );
3007
    }
3008
3009
    /**
3010
     * Test for the loadUrlAlias() method.
3011
     *
3012
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3013
     * @dataProvider providerForTestLookupVirtualUrlAlias
3014
     */
3015 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...
3016
    {
3017
        $handler = $this->getHandler();
3018
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
3019
3020
        $urlAlias = $handler->loadUrlAlias($id);
3021
3022
        $this->assertVirtualUrlAliasValid($urlAlias, $id);
3023
    }
3024
3025
    protected function getHistoryAlias()
3026
    {
3027
        return new UrlAlias(
3028
            array(
3029
                'id' => '3-5f46413bb0ba5998caef84ab1ea590e1',
3030
                'type' => UrlAlias::LOCATION,
3031
                'destination' => '316',
3032
                'pathData' => array(
3033
                    array(
3034
                        'always-available' => true,
3035
                        'translations' => array('cro-HR' => 'jedan'),
3036
                    ),
3037
                    array(
3038
                        'always-available' => false,
3039
                        'translations' => array(
3040
                            'cro-HR' => 'dva',
3041
                            'eng-GB' => 'two',
3042
                        ),
3043
                    ),
3044
                    array(
3045
                        'always-available' => false,
3046
                        'translations' => array(
3047
                            'cro-HR' => 'tri-history',
3048
                        ),
3049
                    ),
3050
                ),
3051
                'languageCodes' => array('cro-HR'),
3052
                'alwaysAvailable' => false,
3053
                'isHistory' => true,
3054
                'isCustom' => false,
3055
                'forward' => false,
3056
            )
3057
        );
3058
    }
3059
3060
    /**
3061
     * Test for the loadUrlAlias() method.
3062
     *
3063
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3064
     */
3065
    public function testLoadHistoryUrlAlias()
3066
    {
3067
        $handler = $this->getHandler();
3068
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
3069
3070
        $historyAlias = $this->getHistoryAlias();
3071
        $urlAlias = $handler->loadUrlAlias($historyAlias->id);
3072
3073
        self::assertEquals(
3074
            $historyAlias,
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
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3084
     */
3085
    public function testLoadUrlAliasThrowsNotFoundException()
3086
    {
3087
        $handler = $this->getHandler();
3088
3089
        $handler->loadUrlAlias('non-existent');
3090
    }
3091
3092
    public function providerForTestPublishUrlAliasForLocationSkipsReservedWord()
3093
    {
3094
        return [
3095
            [
3096
                'section',
3097
                'section2',
3098
            ],
3099
            [
3100
                'claß',
3101
                'class2',
3102
            ],
3103
        ];
3104
    }
3105
3106
    /**
3107
     * Test for the publishUrlAliasForLocation() method.
3108
     *
3109
     * @dataProvider providerForTestPublishUrlAliasForLocationSkipsReservedWord
3110
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::publishUrlAliasForLocation
3111
     * @group publish
3112
     */
3113
    public function testPublishUrlAliasForLocationSkipsReservedWord($text, $alias)
3114
    {
3115
        $handler = $this->getHandler();
3116
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_base.php');
3117
3118
        $handler->publishUrlAliasForLocation(314, 2, $text, 'kli-KR');
3119
3120
        $urlAlias = $handler->lookup($alias);
3121
3122
        $this->assertEquals(314, $urlAlias->destination);
3123
        $this->assertEquals(['kli-KR'], $urlAlias->languageCodes);
3124
    }
3125
3126
    /**
3127
     * Test for the locationSwapped() method.
3128
     *
3129
     * @group swap
3130
     */
3131
    public function testLocationSwappedSimple()
3132
    {
3133
        $handler = $this->getHandler();
3134
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple.php');
3135
3136
        $countBeforeReusing = $this->countRows();
3137
3138
        $handler->locationSwapped(316, 314, 317, 315);
3139
3140
        $this->assertEquals(
3141
            $countBeforeReusing,
3142
            $this->countRows()
3143
        );
3144
3145
        $urlAlias = $handler->lookup('jedan/swap');
3146
        $this->assertEquals(
3147
            new UrlAlias(
3148
                array(
3149
                    'id' => '2-' . md5('swap'),
3150
                    'type' => UrlAlias::LOCATION,
3151
                    'destination' => 316,
3152
                    'languageCodes' => array(
3153
                        'cro-HR',
3154
                    ),
3155
                    'pathData' => array(
3156
                        array(
3157
                            'always-available' => false,
3158
                            'translations' => array(
3159
                                'cro-HR' => 'jedan',
3160
                            ),
3161
                        ),
3162
                        array(
3163
                            'always-available' => false,
3164
                            'translations' => array(
3165
                                'cro-HR' => 'swap',
3166
                            ),
3167
                        ),
3168
                    ),
3169
                    'alwaysAvailable' => false,
3170
                    'isHistory' => false,
3171
                    'isCustom' => false,
3172
                    'forward' => false,
3173
                )
3174
            ),
3175
            $urlAlias
3176
        );
3177
3178
        $urlAlias = $handler->lookup('dva/swap');
3179
        $this->assertEquals(
3180
            new UrlAlias(
3181
                array(
3182
                    'id' => '3-' . md5('swap'),
3183
                    'type' => UrlAlias::LOCATION,
3184
                    'destination' => 317,
3185
                    'languageCodes' => array(
3186
                        'cro-HR',
3187
                    ),
3188
                    'pathData' => array(
3189
                        array(
3190
                            'always-available' => false,
3191
                            'translations' => array(
3192
                                'cro-HR' => 'dva',
3193
                            ),
3194
                        ),
3195
                        array(
3196
                            'always-available' => false,
3197
                            'translations' => array(
3198
                                'cro-HR' => 'swap',
3199
                            ),
3200
                        ),
3201
                    ),
3202
                    'alwaysAvailable' => false,
3203
                    'isHistory' => false,
3204
                    'isCustom' => false,
3205
                    'forward' => false,
3206
                )
3207
            ),
3208
            $urlAlias
3209
        );
3210
    }
3211
3212
    /**
3213
     * Test for the locationSwapped() method.
3214
     *
3215
     * @group swap
3216
     */
3217 View Code Duplication
    public function testLocationSwappedSimpleWithHistory()
3218
    {
3219
        $handler = $this->getHandler();
3220
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_history.php');
3221
3222
        $countBeforeReusing = $this->countRows();
3223
3224
        $handler->locationSwapped(316, 314, 317, 315);
3225
3226
        $this->assertEquals(
3227
            $countBeforeReusing,
3228
            $this->countRows()
3229
        );
3230
3231
        $urlAlias = $handler->lookup('jedan/swap');
3232
        $this->assertEquals(
3233
            new UrlAlias(
3234
                array(
3235
                    'id' => '2-' . md5('swap'),
3236
                    'type' => UrlAlias::LOCATION,
3237
                    'destination' => 316,
3238
                    'languageCodes' => array(
3239
                        'cro-HR',
3240
                    ),
3241
                    'pathData' => array(
3242
                        array(
3243
                            'always-available' => false,
3244
                            'translations' => array(
3245
                                'cro-HR' => 'jedan',
3246
                            ),
3247
                        ),
3248
                        array(
3249
                            'always-available' => false,
3250
                            'translations' => array(
3251
                                'cro-HR' => 'swap',
3252
                            ),
3253
                        ),
3254
                    ),
3255
                    'alwaysAvailable' => false,
3256
                    'isHistory' => true,
3257
                    'isCustom' => false,
3258
                    'forward' => false,
3259
                )
3260
            ),
3261
            $urlAlias
3262
        );
3263
3264
        $urlAlias = $handler->lookup('dva/swap');
3265
        $this->assertEquals(
3266
            new UrlAlias(
3267
                array(
3268
                    'id' => '3-' . md5('swap'),
3269
                    'type' => UrlAlias::LOCATION,
3270
                    'destination' => 317,
3271
                    'languageCodes' => array(
3272
                        'cro-HR',
3273
                    ),
3274
                    'pathData' => array(
3275
                        array(
3276
                            'always-available' => false,
3277
                            'translations' => array(
3278
                                'cro-HR' => 'dva',
3279
                            ),
3280
                        ),
3281
                        array(
3282
                            'always-available' => false,
3283
                            'translations' => array(
3284
                                'cro-HR' => 'swap',
3285
                            ),
3286
                        ),
3287
                    ),
3288
                    'alwaysAvailable' => false,
3289
                    'isHistory' => true,
3290
                    'isCustom' => false,
3291
                    'forward' => false,
3292
                )
3293
            ),
3294
            $urlAlias
3295
        );
3296
3297
        $urlAlias = $handler->lookup('jedan/swap-new');
3298
        $this->assertEquals(
3299
            new UrlAlias(
3300
                array(
3301
                    'id' => '2-' . md5('swap-new'),
3302
                    'type' => UrlAlias::LOCATION,
3303
                    'destination' => 316,
3304
                    'languageCodes' => array(
3305
                        'cro-HR',
3306
                    ),
3307
                    'pathData' => array(
3308
                        array(
3309
                            'always-available' => false,
3310
                            'translations' => array(
3311
                                'cro-HR' => 'jedan',
3312
                            ),
3313
                        ),
3314
                        array(
3315
                            'always-available' => false,
3316
                            'translations' => array(
3317
                                'cro-HR' => 'swap-new',
3318
                            ),
3319
                        ),
3320
                    ),
3321
                    'alwaysAvailable' => false,
3322
                    'isHistory' => false,
3323
                    'isCustom' => false,
3324
                    'forward' => false,
3325
                )
3326
            ),
3327
            $urlAlias
3328
        );
3329
3330
        $urlAlias = $handler->lookup('dva/swap-new');
3331
        $this->assertEquals(
3332
            new UrlAlias(
3333
                array(
3334
                    'id' => '3-' . md5('swap-new'),
3335
                    'type' => UrlAlias::LOCATION,
3336
                    'destination' => 317,
3337
                    'languageCodes' => array(
3338
                        'cro-HR',
3339
                    ),
3340
                    'pathData' => array(
3341
                        array(
3342
                            'always-available' => false,
3343
                            'translations' => array(
3344
                                'cro-HR' => 'dva',
3345
                            ),
3346
                        ),
3347
                        array(
3348
                            'always-available' => false,
3349
                            'translations' => array(
3350
                                'cro-HR' => 'swap-new',
3351
                            ),
3352
                        ),
3353
                    ),
3354
                    'alwaysAvailable' => false,
3355
                    'isHistory' => false,
3356
                    'isCustom' => false,
3357
                    'forward' => false,
3358
                )
3359
            ),
3360
            $urlAlias
3361
        );
3362
    }
3363
3364
    /**
3365
     * Test for the locationSwapped() method.
3366
     *
3367
     * @group swap
3368
     */
3369
    public function testLocationSwappedSimpleWithConflict()
3370
    {
3371
        $handler = $this->getHandler();
3372
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_simple_conflict.php');
3373
3374
        $urlAlias1TakenExpected = $handler->lookup('jedan/swap-new-2');
3375
        $urlAlias2TakenExpected = $handler->lookup('dva/swap-new-1');
3376
3377
        $urlAlias1HistorizedExpected = $handler->lookup('jedan/swap-new-1');
3378
        $urlAlias1HistorizedExpected->isHistory = true;
3379
        $urlAlias2HistorizedExpected = $handler->lookup('dva/swap-new-2');
3380
        $urlAlias2HistorizedExpected->isHistory = true;
3381
3382
        $countBeforeReusing = $this->countRows();
3383
3384
        $handler->locationSwapped(316, 314, 317, 315);
3385
3386
        $this->assertEquals(
3387
            $countBeforeReusing + 2,
3388
            $this->countRows()
3389
        );
3390
3391
        $urlAlias1Taken = $handler->lookup('jedan/swap-new-2');
3392
        $urlAlias2Taken = $handler->lookup('dva/swap-new-1');
3393
3394
        $urlAlias1Historized = $handler->lookup('jedan/swap-new-1');
3395
        $urlAlias2Historized = $handler->lookup('dva/swap-new-2');
3396
3397
        $this->assertEquals($urlAlias1TakenExpected, $urlAlias1Taken);
3398
        $this->assertEquals($urlAlias2TakenExpected, $urlAlias2Taken);
3399
3400
        $this->assertEquals($urlAlias1HistorizedExpected, $urlAlias1Historized);
3401
        $this->assertEquals($urlAlias2HistorizedExpected, $urlAlias2Historized);
3402
3403
        $urlAlias1New = $handler->lookup('jedan/swap-new-22');
3404
        $this->assertEquals(
3405
            new UrlAlias(
3406
                array(
3407
                    'id' => '2-' . md5('swap-new-22'),
3408
                    'type' => UrlAlias::LOCATION,
3409
                    'destination' => 316,
3410
                    'languageCodes' => array(
3411
                        'cro-HR',
3412
                    ),
3413
                    'pathData' => array(
3414
                        array(
3415
                            'always-available' => false,
3416
                            'translations' => array(
3417
                                'cro-HR' => 'jedan',
3418
                            ),
3419
                        ),
3420
                        array(
3421
                            'always-available' => false,
3422
                            'translations' => array(
3423
                                'cro-HR' => 'swap-new-22',
3424
                            ),
3425
                        ),
3426
                    ),
3427
                    'alwaysAvailable' => false,
3428
                    'isHistory' => false,
3429
                    'isCustom' => false,
3430
                    'forward' => false,
3431
                )
3432
            ),
3433
            $urlAlias1New
3434
        );
3435
3436
        $urlAlias2New = $handler->lookup('dva/swap-new-12');
3437
        $this->assertEquals(
3438
            new UrlAlias(
3439
                array(
3440
                    'id' => '3-' . md5('swap-new-12'),
3441
                    'type' => UrlAlias::LOCATION,
3442
                    'destination' => 317,
3443
                    'languageCodes' => array(
3444
                        'cro-HR',
3445
                    ),
3446
                    'pathData' => array(
3447
                        array(
3448
                            'always-available' => false,
3449
                            'translations' => array(
3450
                                'cro-HR' => 'dva',
3451
                            ),
3452
                        ),
3453
                        array(
3454
                            'always-available' => false,
3455
                            'translations' => array(
3456
                                'cro-HR' => 'swap-new-12',
3457
                            ),
3458
                        ),
3459
                    ),
3460
                    'alwaysAvailable' => false,
3461
                    'isHistory' => false,
3462
                    'isCustom' => false,
3463
                    'forward' => false,
3464
                )
3465
            ),
3466
            $urlAlias2New
3467
        );
3468
    }
3469
3470
    /**
3471
     * Test for the locationSwapped() method.
3472
     *
3473
     * @group swap
3474
     */
3475 View Code Duplication
    public function testLocationSwappedSiblingsSimple()
3476
    {
3477
        $handler = $this->getHandler();
3478
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3479
3480
        $countBeforeReusing = $this->countRows();
3481
3482
        $handler->locationSwapped(314, 2, 315, 2);
3483
3484
        $this->assertEquals(
3485
            $countBeforeReusing,
3486
            $this->countRows()
3487
        );
3488
3489
        $urlAlias = $handler->lookup('jedan');
3490
        $this->assertEquals(
3491
            new UrlAlias(
3492
                array(
3493
                    'id' => '0-' . md5('jedan'),
3494
                    'type' => UrlAlias::LOCATION,
3495
                    'destination' => 315,
3496
                    'languageCodes' => array(
3497
                        'cro-HR',
3498
                    ),
3499
                    'pathData' => array(
3500
                        array(
3501
                            'always-available' => false,
3502
                            'translations' => array(
3503
                                'cro-HR' => 'jedan',
3504
                            ),
3505
                        ),
3506
                    ),
3507
                    'alwaysAvailable' => false,
3508
                    'isHistory' => false,
3509
                    'isCustom' => false,
3510
                    'forward' => false,
3511
                )
3512
            ),
3513
            $urlAlias
3514
        );
3515
3516
        $urlAlias = $handler->lookup('dva');
3517
        $this->assertEquals(
3518
            new UrlAlias(
3519
                array(
3520
                    'id' => '0-' . md5('dva'),
3521
                    'type' => UrlAlias::LOCATION,
3522
                    'destination' => 314,
3523
                    'languageCodes' => array(
3524
                        'cro-HR',
3525
                    ),
3526
                    'pathData' => array(
3527
                        array(
3528
                            'always-available' => false,
3529
                            'translations' => array(
3530
                                'cro-HR' => 'dva',
3531
                            ),
3532
                        ),
3533
                    ),
3534
                    'alwaysAvailable' => false,
3535
                    'isHistory' => false,
3536
                    'isCustom' => false,
3537
                    'forward' => false,
3538
                )
3539
            ),
3540
            $urlAlias
3541
        );
3542
    }
3543
3544
    /**
3545
     * Test for the locationSwapped() method.
3546
     *
3547
     * @group swap
3548
     */
3549 View Code Duplication
    public function testLocationSwappedSiblingsSimpleReverse()
3550
    {
3551
        $handler = $this->getHandler();
3552
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple.php');
3553
3554
        $countBeforeReusing = $this->countRows();
3555
3556
        $handler->locationSwapped(315, 2, 314, 2);
3557
3558
        $this->assertEquals(
3559
            $countBeforeReusing,
3560
            $this->countRows()
3561
        );
3562
3563
        $urlAlias = $handler->lookup('jedan');
3564
        $this->assertEquals(
3565
            new UrlAlias(
3566
                array(
3567
                    'id' => '0-' . md5('jedan'),
3568
                    'type' => UrlAlias::LOCATION,
3569
                    'destination' => 315,
3570
                    'languageCodes' => array(
3571
                        'cro-HR',
3572
                    ),
3573
                    'pathData' => array(
3574
                        array(
3575
                            'always-available' => false,
3576
                            'translations' => array(
3577
                                'cro-HR' => 'jedan',
3578
                            ),
3579
                        ),
3580
                    ),
3581
                    'alwaysAvailable' => false,
3582
                    'isHistory' => false,
3583
                    'isCustom' => false,
3584
                    'forward' => false,
3585
                )
3586
            ),
3587
            $urlAlias
3588
        );
3589
3590
        $urlAlias = $handler->lookup('dva');
3591
        $this->assertEquals(
3592
            new UrlAlias(
3593
                array(
3594
                    'id' => '0-' . md5('dva'),
3595
                    'type' => UrlAlias::LOCATION,
3596
                    'destination' => 314,
3597
                    'languageCodes' => array(
3598
                        'cro-HR',
3599
                    ),
3600
                    'pathData' => array(
3601
                        array(
3602
                            'always-available' => false,
3603
                            'translations' => array(
3604
                                'cro-HR' => 'dva',
3605
                            ),
3606
                        ),
3607
                    ),
3608
                    'alwaysAvailable' => false,
3609
                    'isHistory' => false,
3610
                    'isCustom' => false,
3611
                    'forward' => false,
3612
                )
3613
            ),
3614
            $urlAlias
3615
        );
3616
    }
3617
3618
    /**
3619
     * Test for the locationSwapped() method.
3620
     *
3621
     * @group swap
3622
     */
3623 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistory()
3624
    {
3625
        $handler = $this->getHandler();
3626
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3627
3628
        $countBeforeReusing = $this->countRows();
3629
3630
        $handler->locationSwapped(314, 2, 315, 2);
3631
3632
        $this->assertEquals(
3633
            $countBeforeReusing,
3634
            $this->countRows()
3635
        );
3636
3637
        $urlAlias = $handler->lookup('jedan');
3638
        $this->assertEquals(
3639
            new UrlAlias(
3640
                array(
3641
                    'id' => '0-' . md5('jedan'),
3642
                    'type' => UrlAlias::LOCATION,
3643
                    'destination' => 314,
3644
                    'languageCodes' => array(
3645
                        'cro-HR',
3646
                    ),
3647
                    'pathData' => array(
3648
                        array(
3649
                            'always-available' => false,
3650
                            'translations' => array(
3651
                                'cro-HR' => 'jedan',
3652
                            ),
3653
                        ),
3654
                    ),
3655
                    'alwaysAvailable' => false,
3656
                    'isHistory' => true,
3657
                    'isCustom' => false,
3658
                    'forward' => false,
3659
                )
3660
            ),
3661
            $urlAlias
3662
        );
3663
3664
        $urlAlias = $handler->lookup('dva');
3665
        $this->assertEquals(
3666
            new UrlAlias(
3667
                array(
3668
                    'id' => '0-' . md5('dva'),
3669
                    'type' => UrlAlias::LOCATION,
3670
                    'destination' => 315,
3671
                    'languageCodes' => array(
3672
                        'cro-HR',
3673
                    ),
3674
                    'pathData' => array(
3675
                        array(
3676
                            'always-available' => false,
3677
                            'translations' => array(
3678
                                'cro-HR' => 'dva',
3679
                            ),
3680
                        ),
3681
                    ),
3682
                    'alwaysAvailable' => false,
3683
                    'isHistory' => true,
3684
                    'isCustom' => false,
3685
                    'forward' => false,
3686
                )
3687
            ),
3688
            $urlAlias
3689
        );
3690
3691
        $urlAlias = $handler->lookup('jedan-new');
3692
        $this->assertEquals(
3693
            new UrlAlias(
3694
                array(
3695
                    'id' => '0-' . md5('jedan-new'),
3696
                    'type' => UrlAlias::LOCATION,
3697
                    'destination' => 315,
3698
                    'languageCodes' => array(
3699
                        'cro-HR',
3700
                    ),
3701
                    'pathData' => array(
3702
                        array(
3703
                            'always-available' => false,
3704
                            'translations' => array(
3705
                                'cro-HR' => 'jedan-new',
3706
                            ),
3707
                        ),
3708
                    ),
3709
                    'alwaysAvailable' => false,
3710
                    'isHistory' => false,
3711
                    'isCustom' => false,
3712
                    'forward' => false,
3713
                )
3714
            ),
3715
            $urlAlias
3716
        );
3717
3718
        $urlAlias = $handler->lookup('dva-new');
3719
        $this->assertEquals(
3720
            new UrlAlias(
3721
                array(
3722
                    'id' => '0-' . md5('dva-new'),
3723
                    'type' => UrlAlias::LOCATION,
3724
                    'destination' => 314,
3725
                    'languageCodes' => array(
3726
                        'cro-HR',
3727
                    ),
3728
                    'pathData' => array(
3729
                        array(
3730
                            'always-available' => false,
3731
                            'translations' => array(
3732
                                'cro-HR' => 'dva-new',
3733
                            ),
3734
                        ),
3735
                    ),
3736
                    'alwaysAvailable' => false,
3737
                    'isHistory' => false,
3738
                    'isCustom' => false,
3739
                    'forward' => false,
3740
                )
3741
            ),
3742
            $urlAlias
3743
        );
3744
    }
3745
3746
    /**
3747
     * Test for the locationSwapped() method.
3748
     *
3749
     * @group swap
3750
     */
3751 View Code Duplication
    public function testLocationSwappedSiblingsSimpleWithHistoryReverse()
3752
    {
3753
        $handler = $this->getHandler();
3754
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_simple_history.php');
3755
3756
        $countBeforeReusing = $this->countRows();
3757
3758
        $handler->locationSwapped(315, 2, 314, 2);
3759
3760
        $this->assertEquals(
3761
            $countBeforeReusing,
3762
            $this->countRows()
3763
        );
3764
3765
        $urlAlias = $handler->lookup('jedan');
3766
        $this->assertEquals(
3767
            new UrlAlias(
3768
                array(
3769
                    'id' => '0-' . md5('jedan'),
3770
                    'type' => UrlAlias::LOCATION,
3771
                    'destination' => 314,
3772
                    'languageCodes' => array(
3773
                        'cro-HR',
3774
                    ),
3775
                    'pathData' => array(
3776
                        array(
3777
                            'always-available' => false,
3778
                            'translations' => array(
3779
                                'cro-HR' => 'jedan',
3780
                            ),
3781
                        ),
3782
                    ),
3783
                    'alwaysAvailable' => false,
3784
                    'isHistory' => true,
3785
                    'isCustom' => false,
3786
                    'forward' => false,
3787
                )
3788
            ),
3789
            $urlAlias
3790
        );
3791
3792
        $urlAlias = $handler->lookup('dva');
3793
        $this->assertEquals(
3794
            new UrlAlias(
3795
                array(
3796
                    'id' => '0-' . md5('dva'),
3797
                    'type' => UrlAlias::LOCATION,
3798
                    'destination' => 315,
3799
                    'languageCodes' => array(
3800
                        'cro-HR',
3801
                    ),
3802
                    'pathData' => array(
3803
                        array(
3804
                            'always-available' => false,
3805
                            'translations' => array(
3806
                                'cro-HR' => 'dva',
3807
                            ),
3808
                        ),
3809
                    ),
3810
                    'alwaysAvailable' => false,
3811
                    'isHistory' => true,
3812
                    'isCustom' => false,
3813
                    'forward' => false,
3814
                )
3815
            ),
3816
            $urlAlias
3817
        );
3818
3819
        $urlAlias = $handler->lookup('jedan-new');
3820
        $this->assertEquals(
3821
            new UrlAlias(
3822
                array(
3823
                    'id' => '0-' . md5('jedan-new'),
3824
                    'type' => UrlAlias::LOCATION,
3825
                    'destination' => 315,
3826
                    'languageCodes' => array(
3827
                        'cro-HR',
3828
                    ),
3829
                    'pathData' => array(
3830
                        array(
3831
                            'always-available' => false,
3832
                            'translations' => array(
3833
                                'cro-HR' => 'jedan-new',
3834
                            ),
3835
                        ),
3836
                    ),
3837
                    'alwaysAvailable' => false,
3838
                    'isHistory' => false,
3839
                    'isCustom' => false,
3840
                    'forward' => false,
3841
                )
3842
            ),
3843
            $urlAlias
3844
        );
3845
3846
        $urlAlias = $handler->lookup('dva-new');
3847
        $this->assertEquals(
3848
            new UrlAlias(
3849
                array(
3850
                    'id' => '0-' . md5('dva-new'),
3851
                    'type' => UrlAlias::LOCATION,
3852
                    'destination' => 314,
3853
                    'languageCodes' => array(
3854
                        'cro-HR',
3855
                    ),
3856
                    'pathData' => array(
3857
                        array(
3858
                            'always-available' => false,
3859
                            'translations' => array(
3860
                                'cro-HR' => 'dva-new',
3861
                            ),
3862
                        ),
3863
                    ),
3864
                    'alwaysAvailable' => false,
3865
                    'isHistory' => false,
3866
                    'isCustom' => false,
3867
                    'forward' => false,
3868
                )
3869
            ),
3870
            $urlAlias
3871
        );
3872
    }
3873
3874
    /**
3875
     * Test for the locationSwapped() method.
3876
     *
3877
     * @group swap
3878
     */
3879 View Code Duplication
    public function testLocationSwappedSiblingsSameName()
3880
    {
3881
        $handler = $this->getHandler();
3882
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3883
3884
        $countBeforeReusing = $this->countRows();
3885
3886
        $handler->locationSwapped(314, 2, 315, 2);
3887
3888
        $this->assertEquals(
3889
            $countBeforeReusing,
3890
            $this->countRows()
3891
        );
3892
3893
        $urlAlias = $handler->lookup('swap');
3894
        $this->assertEquals(
3895
            new UrlAlias(
3896
                [
3897
                    'id' => '0-' . md5('swap'),
3898
                    'type' => UrlAlias::LOCATION,
3899
                    'destination' => 314,
3900
                    'languageCodes' => [
3901
                        'cro-HR',
3902
                    ],
3903
                    'pathData' => [
3904
                        [
3905
                            'always-available' => false,
3906
                            'translations' => [
3907
                                'cro-HR' => 'swap',
3908
                            ],
3909
                        ],
3910
                    ],
3911
                    'alwaysAvailable' => false,
3912
                    'isHistory' => false,
3913
                    'isCustom' => false,
3914
                    'forward' => false,
3915
                ]
3916
            ),
3917
            $urlAlias
3918
        );
3919
3920
        $urlAlias = $handler->lookup('swap2');
3921
        $this->assertEquals(
3922
            new UrlAlias(
3923
                [
3924
                    'id' => '0-' . md5('swap2'),
3925
                    'type' => UrlAlias::LOCATION,
3926
                    'destination' => 315,
3927
                    'languageCodes' => [
3928
                        'cro-HR',
3929
                    ],
3930
                    'pathData' => [
3931
                        [
3932
                            'always-available' => false,
3933
                            'translations' => [
3934
                                'cro-HR' => 'swap2',
3935
                            ],
3936
                        ],
3937
                    ],
3938
                    'alwaysAvailable' => false,
3939
                    'isHistory' => false,
3940
                    'isCustom' => false,
3941
                    'forward' => false,
3942
                ]
3943
            ),
3944
            $urlAlias
3945
        );
3946
    }
3947
3948
    /**
3949
     * Test for the locationSwapped() method.
3950
     *
3951
     * @group swap
3952
     */
3953 View Code Duplication
    public function testLocationSwappedSiblingsSameNameReverse()
3954
    {
3955
        $handler = $this->getHandler();
3956
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name.php');
3957
3958
        $countBeforeReusing = $this->countRows();
3959
3960
        $handler->locationSwapped(315, 2, 314, 2);
3961
3962
        $this->assertEquals(
3963
            $countBeforeReusing,
3964
            $this->countRows()
3965
        );
3966
3967
        $urlAlias = $handler->lookup('swap');
3968
        $this->assertEquals(
3969
            new UrlAlias(
3970
                [
3971
                    'id' => '0-' . md5('swap'),
3972
                    'type' => UrlAlias::LOCATION,
3973
                    'destination' => 314,
3974
                    'languageCodes' => [
3975
                        'cro-HR',
3976
                    ],
3977
                    'pathData' => [
3978
                        [
3979
                            'always-available' => false,
3980
                            'translations' => [
3981
                                'cro-HR' => 'swap',
3982
                            ],
3983
                        ],
3984
                    ],
3985
                    'alwaysAvailable' => false,
3986
                    'isHistory' => false,
3987
                    'isCustom' => false,
3988
                    'forward' => false,
3989
                ]
3990
            ),
3991
            $urlAlias
3992
        );
3993
3994
        $urlAlias = $handler->lookup('swap2');
3995
        $this->assertEquals(
3996
            new UrlAlias(
3997
                [
3998
                    'id' => '0-' . md5('swap2'),
3999
                    'type' => UrlAlias::LOCATION,
4000
                    'destination' => 315,
4001
                    'languageCodes' => [
4002
                        'cro-HR',
4003
                    ],
4004
                    'pathData' => [
4005
                        [
4006
                            'always-available' => false,
4007
                            'translations' => [
4008
                                'cro-HR' => 'swap2',
4009
                            ],
4010
                        ],
4011
                    ],
4012
                    'alwaysAvailable' => false,
4013
                    'isHistory' => false,
4014
                    'isCustom' => false,
4015
                    'forward' => false,
4016
                ]
4017
            ),
4018
            $urlAlias
4019
        );
4020
    }
4021
4022
    /**
4023
     * Test for the locationSwapped() method.
4024
     *
4025
     * @group swap
4026
     */
4027
    public function testLocationSwappedSiblingsSameNameMultipleLanguages()
4028
    {
4029
        $handler = $this->getHandler();
4030
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_siblings_same_name_multilang.php');
4031
4032
        $countBeforeReusing = $this->countRows();
4033
4034
        $handler->locationSwapped(314, 2, 315, 2);
4035
4036
        $this->assertEquals(
4037
            $countBeforeReusing,
4038
            $this->countRows()
4039
        );
4040
4041
        $urlAlias = $handler->lookup('swap-hr');
4042
        $this->assertEquals(
4043
            new UrlAlias(
4044
                [
4045
                    'id' => '0-' . md5('swap-hr'),
4046
                    'type' => UrlAlias::LOCATION,
4047
                    'destination' => 314,
4048
                    'languageCodes' => [
4049
                        'cro-HR',
4050
                    ],
4051
                    'pathData' => [
4052
                        [
4053
                            'always-available' => false,
4054
                            'translations' => [
4055
                                'cro-HR' => 'swap-hr',
4056
                                'eng-GB' => 'swap-en2',
4057
                            ],
4058
                        ],
4059
                    ],
4060
                    'alwaysAvailable' => false,
4061
                    'isHistory' => false,
4062
                    'isCustom' => false,
4063
                    'forward' => false,
4064
                ]
4065
            ),
4066
            $urlAlias
4067
        );
4068
4069
        $urlAlias = $handler->lookup('swap-hr2');
4070
        $this->assertEquals(
4071
            new UrlAlias(
4072
                [
4073
                    'id' => '0-' . md5('swap-hr2'),
4074
                    'type' => UrlAlias::LOCATION,
4075
                    'destination' => 315,
4076
                    'languageCodes' => [
4077
                        'cro-HR',
4078
                    ],
4079
                    'pathData' => [
4080
                        [
4081
                            'always-available' => false,
4082
                            'translations' => [
4083
                                'cro-HR' => 'swap-hr2',
4084
                                'eng-GB' => 'swap-en',
4085
                            ],
4086
                        ],
4087
                    ],
4088
                    'alwaysAvailable' => false,
4089
                    'isHistory' => false,
4090
                    'isCustom' => false,
4091
                    'forward' => false,
4092
                ]
4093
            ),
4094
            $urlAlias
4095
        );
4096
4097
        $urlAlias = $handler->lookup('swap-en');
4098
        $this->assertEquals(
4099
            new UrlAlias(
4100
                [
4101
                    'id' => '0-' . md5('swap-en'),
4102
                    'type' => UrlAlias::LOCATION,
4103
                    'destination' => 315,
4104
                    'languageCodes' => [
4105
                        'eng-GB',
4106
                    ],
4107
                    'pathData' => [
4108
                        [
4109
                            'always-available' => false,
4110
                            'translations' => [
4111
                                'cro-HR' => 'swap-hr2',
4112
                                'eng-GB' => 'swap-en',
4113
                            ],
4114
                        ],
4115
                    ],
4116
                    'alwaysAvailable' => false,
4117
                    'isHistory' => false,
4118
                    'isCustom' => false,
4119
                    'forward' => false,
4120
                ]
4121
            ),
4122
            $urlAlias
4123
        );
4124
4125
        $urlAlias = $handler->lookup('swap-en2');
4126
        $this->assertEquals(
4127
            new UrlAlias(
4128
                [
4129
                    'id' => '0-' . md5('swap-en2'),
4130
                    'type' => UrlAlias::LOCATION,
4131
                    'destination' => 314,
4132
                    'languageCodes' => [
4133
                        'eng-GB',
4134
                    ],
4135
                    'pathData' => [
4136
                        [
4137
                            'always-available' => false,
4138
                            'translations' => [
4139
                                'cro-HR' => 'swap-hr',
4140
                                'eng-GB' => 'swap-en2',
4141
                            ],
4142
                        ],
4143
                    ],
4144
                    'alwaysAvailable' => false,
4145
                    'isHistory' => false,
4146
                    'isCustom' => false,
4147
                    'forward' => false,
4148
                ]
4149
            ),
4150
            $urlAlias
4151
        );
4152
    }
4153
4154
    /**
4155
     * Test for the locationSwapped() method.
4156
     *
4157
     * @group swap
4158
     */
4159
    public function testLocationSwappedMultipleLanguagesSimple()
4160
    {
4161
        $handler = $this->getHandler();
4162
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_simple.php');
4163
4164
        $urlAlias1HRExpected = $handler->lookup('jedan/swap-hr');
4165
        $urlAlias1ENExpected = $handler->lookup('jedan/swap-en');
4166
        $urlAlias2HRExpected = $handler->lookup('dva/swap-hr');
4167
        $urlAlias2ENExpected = $handler->lookup('dva/swap-en');
4168
4169
        $countBeforeReusing = $this->countRows();
4170
4171
        $handler->locationSwapped(316, 314, 317, 315);
4172
4173
        $this->assertEquals(
4174
            $countBeforeReusing,
4175
            $this->countRows()
4176
        );
4177
4178
        $urlAlias1HR = $handler->lookup('jedan/swap-hr');
4179
        $urlAlias1EN = $handler->lookup('jedan/swap-en');
4180
        $urlAlias2HR = $handler->lookup('dva/swap-hr');
4181
        $urlAlias2EN = $handler->lookup('dva/swap-en');
4182
4183
        $this->assertEquals($urlAlias1HRExpected, $urlAlias1HR);
4184
        $this->assertEquals($urlAlias1ENExpected, $urlAlias1EN);
4185
        $this->assertEquals($urlAlias2HRExpected, $urlAlias2HR);
4186
        $this->assertEquals($urlAlias2ENExpected, $urlAlias2EN);
4187
    }
4188
4189
    /**
4190
     * Test for the locationSwapped() method.
4191
     *
4192
     * @group swap
4193
     */
4194
    public function testLocationSwappedMultipleLanguagesDifferentLanguagesSimple()
4195
    {
4196
        $handler = $this->getHandler();
4197
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff_simple.php');
4198
4199
        $countBeforeReusing = $this->countRows();
4200
4201
        $handler->locationSwapped(316, 314, 317, 315);
4202
4203
        $this->assertEquals(
4204
            $countBeforeReusing + 2,
4205
            $this->countRows()
4206
        );
4207
4208
        $urlAlias = $handler->lookup('jedan/swap-hr');
4209
        $this->assertEquals(
4210
            new UrlAlias(
4211
                array(
4212
                    'id' => '2-' . md5('swap-hr'),
4213
                    'type' => UrlAlias::LOCATION,
4214
                    'destination' => 316,
4215
                    'languageCodes' => array(
4216
                        'cro-HR',
4217
                    ),
4218
                    'pathData' => array(
4219
                        array(
4220
                            'always-available' => false,
4221
                            'translations' => array(
4222
                                'cro-HR' => 'jedan',
4223
                            ),
4224
                        ),
4225
                        array(
4226
                            'always-available' => false,
4227
                            'translations' => array(
4228
                                'cro-HR' => 'swap-hr',
4229
                                'ger-DE' => 'swap-de',
4230
                            ),
4231
                        ),
4232
                    ),
4233
                    'alwaysAvailable' => false,
4234
                    'isHistory' => false,
4235
                    'isCustom' => false,
4236
                    'forward' => false,
4237
                )
4238
            ),
4239
            $urlAlias
4240
        );
4241
4242
        $urlAlias = $handler->lookup('jedan/swap-de');
4243
        $this->assertEquals(
4244
            new UrlAlias(
4245
                array(
4246
                    'id' => '2-' . md5('swap-de'),
4247
                    'type' => UrlAlias::LOCATION,
4248
                    'destination' => 316,
4249
                    'languageCodes' => array(
4250
                        'ger-DE',
4251
                    ),
4252
                    'pathData' => array(
4253
                        array(
4254
                            'always-available' => false,
4255
                            'translations' => array(
4256
                                'cro-HR' => 'jedan',
4257
                            ),
4258
                        ),
4259
                        array(
4260
                            'always-available' => false,
4261
                            'translations' => array(
4262
                                'cro-HR' => 'swap-hr',
4263
                                'ger-DE' => 'swap-de',
4264
                            ),
4265
                        ),
4266
                    ),
4267
                    'alwaysAvailable' => false,
4268
                    'isHistory' => false,
4269
                    'isCustom' => false,
4270
                    'forward' => false,
4271
                )
4272
            ),
4273
            $urlAlias
4274
        );
4275
4276
        $urlAlias = $handler->lookup('jedan/swap-en');
4277
        $this->assertEquals(
4278
            new UrlAlias(
4279
                array(
4280
                    'id' => '2-' . md5('swap-en'),
4281
                    'type' => UrlAlias::LOCATION,
4282
                    'destination' => 316,
4283
                    'languageCodes' => array(
4284
                        'eng-GB',
4285
                    ),
4286
                    'pathData' => array(
4287
                        array(
4288
                            'always-available' => false,
4289
                            'translations' => array(
4290
                                'cro-HR' => 'jedan',
4291
                            ),
4292
                        ),
4293
                        array(
4294
                            'always-available' => false,
4295
                            'translations' => array(
4296
                                'eng-GB' => 'swap-en',
4297
                            ),
4298
                        ),
4299
                    ),
4300
                    'alwaysAvailable' => false,
4301
                    'isHistory' => true,
4302
                    'isCustom' => false,
4303
                    'forward' => false,
4304
                )
4305
            ),
4306
            $urlAlias
4307
        );
4308
4309
        $urlAlias = $handler->lookup('dva/swap-hr');
4310
        $this->assertEquals(
4311
            new UrlAlias(
4312
                array(
4313
                    'id' => '3-' . md5('swap-hr'),
4314
                    'type' => UrlAlias::LOCATION,
4315
                    'destination' => 317,
4316
                    'languageCodes' => array(
4317
                        'cro-HR',
4318
                    ),
4319
                    'pathData' => array(
4320
                        array(
4321
                            'always-available' => false,
4322
                            'translations' => array(
4323
                                'cro-HR' => 'dva',
4324
                            ),
4325
                        ),
4326
                        array(
4327
                            'always-available' => false,
4328
                            'translations' => array(
4329
                                'eng-GB' => 'swap-en',
4330
                                'cro-HR' => 'swap-hr',
4331
                            ),
4332
                        ),
4333
                    ),
4334
                    'alwaysAvailable' => false,
4335
                    'isHistory' => false,
4336
                    'isCustom' => false,
4337
                    'forward' => false,
4338
                )
4339
            ),
4340
            $urlAlias
4341
        );
4342
4343
        $urlAlias = $handler->lookup('dva/swap-en');
4344
        $this->assertEquals(
4345
            new UrlAlias(
4346
                array(
4347
                    'id' => '3-' . md5('swap-en'),
4348
                    'type' => UrlAlias::LOCATION,
4349
                    'destination' => 317,
4350
                    'languageCodes' => array(
4351
                        'eng-GB',
4352
                    ),
4353
                    'pathData' => array(
4354
                        array(
4355
                            'always-available' => false,
4356
                            'translations' => array(
4357
                                'cro-HR' => 'dva',
4358
                            ),
4359
                        ),
4360
                        array(
4361
                            'always-available' => false,
4362
                            'translations' => array(
4363
                                'eng-GB' => 'swap-en',
4364
                                'cro-HR' => 'swap-hr',
4365
                            ),
4366
                        ),
4367
                    ),
4368
                    'alwaysAvailable' => false,
4369
                    'isHistory' => false,
4370
                    'isCustom' => false,
4371
                    'forward' => false,
4372
                )
4373
            ),
4374
            $urlAlias
4375
        );
4376
4377
        $urlAlias = $handler->lookup('dva/swap-de');
4378
        $this->assertEquals(
4379
            new UrlAlias(
4380
                array(
4381
                    'id' => '3-' . md5('swap-de'),
4382
                    'type' => UrlAlias::LOCATION,
4383
                    'destination' => 317,
4384
                    'languageCodes' => array(
4385
                        'ger-DE',
4386
                    ),
4387
                    'pathData' => array(
4388
                        array(
4389
                            'always-available' => false,
4390
                            'translations' => array(
4391
                                'cro-HR' => 'dva',
4392
                            ),
4393
                        ),
4394
                        array(
4395
                            'always-available' => false,
4396
                            'translations' => array(
4397
                                'ger-DE' => 'swap-de',
4398
                            ),
4399
                        ),
4400
                    ),
4401
                    'alwaysAvailable' => false,
4402
                    'isHistory' => true,
4403
                    'isCustom' => false,
4404
                    'forward' => false,
4405
                )
4406
            ),
4407
            $urlAlias
4408
        );
4409
    }
4410
4411
    /**
4412
     * Test for the locationSwapped() method.
4413
     *
4414
     * @group swap
4415
     */
4416
    public function testLocationSwappedMultipleLanguagesDifferentLanguages()
4417
    {
4418
        $handler = $this->getHandler();
4419
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_diff.php');
4420
4421
        $countBeforeReusing = $this->countRows();
4422
4423
        $handler->locationSwapped(317, 315, 316, 314);
4424
4425
        $this->assertEquals(
4426
            $countBeforeReusing + 2,
4427
            $this->countRows()
4428
        );
4429
4430
        $urlAlias = $handler->lookup('jedan/swap-this');
4431
        $this->assertEquals(
4432
            new UrlAlias(
4433
                array(
4434
                    'id' => '2-' . md5('swap-this'),
4435
                    'type' => UrlAlias::LOCATION,
4436
                    'destination' => 316,
4437
                    'languageCodes' => array(
4438
                        'ger-DE',
4439
                        'nor-NO',
4440
                    ),
4441
                    'pathData' => array(
4442
                        array(
4443
                            'always-available' => false,
4444
                            'translations' => array(
4445
                                'cro-HR' => 'jedan',
4446
                            ),
4447
                        ),
4448
                        array(
4449
                            'always-available' => false,
4450
                            'translations' => array(
4451
                                'cro-HR' => 'swap-hr',
4452
                                'ger-DE' => 'swap-this',
4453
                                'nor-NO' => 'swap-this',
4454
                            ),
4455
                        ),
4456
                    ),
4457
                    'alwaysAvailable' => false,
4458
                    'isHistory' => false,
4459
                    'isCustom' => false,
4460
                    'forward' => false,
4461
                )
4462
            ),
4463
            $urlAlias
4464
        );
4465
4466
        $urlAlias = $handler->lookup('jedan/swap-en');
4467
        $this->assertEquals(
4468
            new UrlAlias(
4469
                array(
4470
                    'id' => '2-' . md5('swap-en'),
4471
                    'type' => UrlAlias::LOCATION,
4472
                    'destination' => 316,
4473
                    'languageCodes' => array(
4474
                        'eng-GB',
4475
                    ),
4476
                    'pathData' => array(
4477
                        array(
4478
                            'always-available' => false,
4479
                            'translations' => array(
4480
                                'cro-HR' => 'jedan',
4481
                            ),
4482
                        ),
4483
                        array(
4484
                            'always-available' => false,
4485
                            'translations' => array(
4486
                                'eng-GB' => 'swap-en',
4487
                            ),
4488
                        ),
4489
                    ),
4490
                    'alwaysAvailable' => false,
4491
                    'isHistory' => true,
4492
                    'isCustom' => false,
4493
                    'forward' => false,
4494
                )
4495
            ),
4496
            $urlAlias
4497
        );
4498
4499
        $urlAlias = $handler->lookup('dva/swap-hr');
4500
        $this->assertEquals(
4501
            new UrlAlias(
4502
                array(
4503
                    'id' => '3-' . md5('swap-hr'),
4504
                    'type' => UrlAlias::LOCATION,
4505
                    'destination' => 317,
4506
                    'languageCodes' => array(
4507
                        'cro-HR',
4508
                    ),
4509
                    'pathData' => array(
4510
                        array(
4511
                            'always-available' => false,
4512
                            'translations' => array(
4513
                                'cro-HR' => 'dva',
4514
                            ),
4515
                        ),
4516
                        array(
4517
                            'always-available' => false,
4518
                            'translations' => array(
4519
                                'cro-HR' => 'swap-hr',
4520
                            ),
4521
                        ),
4522
                    ),
4523
                    'alwaysAvailable' => false,
4524
                    'isHistory' => true,
4525
                    'isCustom' => false,
4526
                    'forward' => false,
4527
                )
4528
            ),
4529
            $urlAlias
4530
        );
4531
4532
        $urlAlias = $handler->lookup('dva/swap-this');
4533
        $this->assertEquals(
4534
            new UrlAlias(
4535
                array(
4536
                    'id' => '3-' . md5('swap-this'),
4537
                    'type' => UrlAlias::LOCATION,
4538
                    'destination' => 317,
4539
                    'languageCodes' => array(
4540
                        'cro-HR',
4541
                        'ger-DE',
4542
                    ),
4543
                    'pathData' => array(
4544
                        array(
4545
                            'always-available' => false,
4546
                            'translations' => array(
4547
                                'cro-HR' => 'dva',
4548
                            ),
4549
                        ),
4550
                        array(
4551
                            'always-available' => false,
4552
                            'translations' => array(
4553
                                'cro-HR' => 'swap-this',
4554
                                'ger-DE' => 'swap-this',
4555
                                'eng-GB' => 'swap-en',
4556
                            ),
4557
                        ),
4558
                    ),
4559
                    'alwaysAvailable' => false,
4560
                    'isHistory' => false,
4561
                    'isCustom' => false,
4562
                    'forward' => false,
4563
                )
4564
            ),
4565
            $urlAlias
4566
        );
4567
    }
4568
4569
    /**
4570
     * Test for the locationSwapped() method.
4571
     *
4572
     * @group swap
4573
     */
4574
    public function testLocationSwappedMultipleLanguagesWithCompositeHistory()
4575
    {
4576
        $handler = $this->getHandler();
4577
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_cleanup_composite.php');
4578
4579
        $countBeforeReusing = $this->countRows();
4580
4581
        $handler->locationSwapped(317, 315, 316, 314);
4582
4583
        $this->assertEquals(
4584
            $countBeforeReusing + 4,
4585
            $this->countRows()
4586
        );
4587
4588
        $urlAlias = $handler->lookup('jedan/swap-this');
4589
        $this->assertEquals(
4590
            new UrlAlias(
4591
                array(
4592
                    'id' => '2-' . md5('swap-this'),
4593
                    'type' => UrlAlias::LOCATION,
4594
                    'destination' => 316,
4595
                    'languageCodes' => array(
4596
                        'cro-HR',
4597
                    ),
4598
                    'pathData' => array(
4599
                        array(
4600
                            'always-available' => false,
4601
                            'translations' => array(
4602
                                'cro-HR' => 'jedan',
4603
                            ),
4604
                        ),
4605
                        array(
4606
                            'always-available' => false,
4607
                            'translations' => array(
4608
                                'cro-HR' => 'swap-this',
4609
                            ),
4610
                        ),
4611
                    ),
4612
                    'alwaysAvailable' => false,
4613
                    'isHistory' => true,
4614
                    'isCustom' => false,
4615
                    'forward' => false,
4616
                )
4617
            ),
4618
            $urlAlias
4619
        );
4620
4621
        $urlAlias = $handler->lookup('jedan/swap-en');
4622
        $this->assertEquals(
4623
            new UrlAlias(
4624
                array(
4625
                    'id' => '2-' . md5('swap-en'),
4626
                    'type' => UrlAlias::LOCATION,
4627
                    'destination' => 316,
4628
                    'languageCodes' => array(
4629
                        'eng-GB',
4630
                    ),
4631
                    'pathData' => array(
4632
                        array(
4633
                            'always-available' => false,
4634
                            'translations' => array(
4635
                                'cro-HR' => 'jedan',
4636
                            ),
4637
                        ),
4638
                        array(
4639
                            'always-available' => false,
4640
                            'translations' => array(
4641
                                'eng-GB' => 'swap-en',
4642
                            ),
4643
                        ),
4644
                    ),
4645
                    'alwaysAvailable' => false,
4646
                    'isHistory' => true,
4647
                    'isCustom' => false,
4648
                    'forward' => false,
4649
                )
4650
            ),
4651
            $urlAlias
4652
        );
4653
4654
        $urlAlias = $handler->lookup('jedan/swap-hr');
4655
        $this->assertEquals(
4656
            new UrlAlias(
4657
                array(
4658
                    'id' => '2-' . md5('swap-hr'),
4659
                    'type' => UrlAlias::LOCATION,
4660
                    'destination' => 316,
4661
                    'languageCodes' => array(
4662
                        'cro-HR',
4663
                    ),
4664
                    'pathData' => array(
4665
                        array(
4666
                            'always-available' => false,
4667
                            'translations' => array(
4668
                                'cro-HR' => 'jedan',
4669
                            ),
4670
                        ),
4671
                        array(
4672
                            'always-available' => false,
4673
                            'translations' => array(
4674
                                'cro-HR' => 'swap-hr',
4675
                                'ger-DE' => 'swap-that',
4676
                                'nor-NO' => 'swap-that',
4677
                            ),
4678
                        ),
4679
                    ),
4680
                    'alwaysAvailable' => false,
4681
                    'isHistory' => false,
4682
                    'isCustom' => false,
4683
                    'forward' => false,
4684
                )
4685
            ),
4686
            $urlAlias
4687
        );
4688
4689
        $urlAlias = $handler->lookup('jedan/swap-that');
4690
        $this->assertEquals(
4691
            new UrlAlias(
4692
                array(
4693
                    'id' => '2-' . md5('swap-that'),
4694
                    'type' => UrlAlias::LOCATION,
4695
                    'destination' => 316,
4696
                    'languageCodes' => array(
4697
                        'ger-DE',
4698
                        'nor-NO',
4699
                    ),
4700
                    'pathData' => array(
4701
                        array(
4702
                            'always-available' => false,
4703
                            'translations' => array(
4704
                                'cro-HR' => 'jedan',
4705
                            ),
4706
                        ),
4707
                        array(
4708
                            'always-available' => false,
4709
                            'translations' => array(
4710
                                'cro-HR' => 'swap-hr',
4711
                                'ger-DE' => 'swap-that',
4712
                                'nor-NO' => 'swap-that',
4713
                            ),
4714
                        ),
4715
                    ),
4716
                    'alwaysAvailable' => false,
4717
                    'isHistory' => false,
4718
                    'isCustom' => false,
4719
                    'forward' => false,
4720
                )
4721
            ),
4722
            $urlAlias
4723
        );
4724
4725
        $urlAlias = $handler->lookup('dva/swap-hr');
4726
        $this->assertEquals(
4727
            new UrlAlias(
4728
                array(
4729
                    'id' => '3-' . md5('swap-hr'),
4730
                    'type' => UrlAlias::LOCATION,
4731
                    'destination' => 317,
4732
                    'languageCodes' => array(
4733
                        'cro-HR',
4734
                    ),
4735
                    'pathData' => array(
4736
                        array(
4737
                            'always-available' => false,
4738
                            'translations' => array(
4739
                                'cro-HR' => 'dva',
4740
                            ),
4741
                        ),
4742
                        array(
4743
                            'always-available' => false,
4744
                            'translations' => array(
4745
                                'cro-HR' => 'swap-hr',
4746
                            ),
4747
                        ),
4748
                    ),
4749
                    'alwaysAvailable' => false,
4750
                    'isHistory' => true,
4751
                    'isCustom' => false,
4752
                    'forward' => false,
4753
                )
4754
            ),
4755
            $urlAlias
4756
        );
4757
4758
        $urlAlias = $handler->lookup('dva/swap-that');
4759
        $this->assertEquals(
4760
            new UrlAlias(
4761
                array(
4762
                    'id' => '3-' . md5('swap-that'),
4763
                    'type' => UrlAlias::LOCATION,
4764
                    'destination' => 317,
4765
                    'languageCodes' => array(
4766
                        'ger-DE',
4767
                        'nor-NO',
4768
                    ),
4769
                    'pathData' => array(
4770
                        array(
4771
                            'always-available' => false,
4772
                            'translations' => array(
4773
                                'cro-HR' => 'dva',
4774
                            ),
4775
                        ),
4776
                        array(
4777
                            'always-available' => false,
4778
                            'translations' => array(
4779
                                'ger-DE' => 'swap-that',
4780
                                'nor-NO' => 'swap-that',
4781
                            ),
4782
                        ),
4783
                    ),
4784
                    'alwaysAvailable' => false,
4785
                    'isHistory' => true,
4786
                    'isCustom' => false,
4787
                    'forward' => false,
4788
                )
4789
            ),
4790
            $urlAlias
4791
        );
4792
4793
        $urlAlias = $handler->lookup('dva/swap-this');
4794
        $this->assertEquals(
4795
            new UrlAlias(
4796
                array(
4797
                    'id' => '3-' . md5('swap-this'),
4798
                    'type' => UrlAlias::LOCATION,
4799
                    'destination' => 317,
4800
                    'languageCodes' => array(
4801
                        'cro-HR',
4802
                    ),
4803
                    'pathData' => array(
4804
                        array(
4805
                            'always-available' => false,
4806
                            'translations' => array(
4807
                                'cro-HR' => 'dva',
4808
                            ),
4809
                        ),
4810
                        array(
4811
                            'always-available' => false,
4812
                            'translations' => array(
4813
                                'cro-HR' => 'swap-this',
4814
                                'eng-GB' => 'swap-en',
4815
                            ),
4816
                        ),
4817
                    ),
4818
                    'alwaysAvailable' => false,
4819
                    'isHistory' => false,
4820
                    'isCustom' => false,
4821
                    'forward' => false,
4822
                )
4823
            ),
4824
            $urlAlias
4825
        );
4826
4827
        $urlAlias = $handler->lookup('dva/swap-en');
4828
        $this->assertEquals(
4829
            new UrlAlias(
4830
                array(
4831
                    'id' => '3-' . md5('swap-en'),
4832
                    'type' => UrlAlias::LOCATION,
4833
                    'destination' => 317,
4834
                    'languageCodes' => array(
4835
                        'eng-GB',
4836
                    ),
4837
                    'pathData' => array(
4838
                        array(
4839
                            'always-available' => false,
4840
                            'translations' => array(
4841
                                'cro-HR' => 'dva',
4842
                            ),
4843
                        ),
4844
                        array(
4845
                            'always-available' => false,
4846
                            'translations' => array(
4847
                                'cro-HR' => 'swap-this',
4848
                                'eng-GB' => 'swap-en',
4849
                            ),
4850
                        ),
4851
                    ),
4852
                    'alwaysAvailable' => false,
4853
                    'isHistory' => false,
4854
                    'isCustom' => false,
4855
                    'forward' => false,
4856
                )
4857
            ),
4858
            $urlAlias
4859
        );
4860
    }
4861
4862
    /**
4863
     * Test for the locationSwapped() method.
4864
     *
4865
     * @group swap
4866
     */
4867 View Code Duplication
    public function testLocationSwappedWithReusingExternalHistory()
4868
    {
4869
        $handler = $this->getHandler();
4870
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_external_history.php');
4871
4872
        $countBeforeReusing = $this->countRows();
4873
4874
        $handler->locationSwapped(318, 314, 319, 315);
4875
4876
        $this->assertEquals(
4877
            $countBeforeReusing,
4878
            $this->countRows()
4879
        );
4880
4881
        $urlAlias = $handler->lookup('jedan/swap-that');
4882
        $this->assertEquals(
4883
            new UrlAlias(
4884
                array(
4885
                    'id' => '2-' . md5('swap-that'),
4886
                    'type' => UrlAlias::LOCATION,
4887
                    'destination' => 318,
4888
                    'languageCodes' => array(
4889
                        'cro-HR',
4890
                    ),
4891
                    'pathData' => array(
4892
                        array(
4893
                            'always-available' => false,
4894
                            'translations' => array(
4895
                                'cro-HR' => 'jedan',
4896
                            ),
4897
                        ),
4898
                        array(
4899
                            'always-available' => false,
4900
                            'translations' => array(
4901
                                'cro-HR' => 'swap-that',
4902
                            ),
4903
                        ),
4904
                    ),
4905
                    'alwaysAvailable' => false,
4906
                    'isHistory' => false,
4907
                    'isCustom' => false,
4908
                    'forward' => false,
4909
                )
4910
            ),
4911
            $urlAlias
4912
        );
4913
4914
        $urlAlias = $handler->lookup('dva/swap-this');
4915
        $this->assertEquals(
4916
            new UrlAlias(
4917
                array(
4918
                    'id' => '3-' . md5('swap-this'),
4919
                    'type' => UrlAlias::LOCATION,
4920
                    'destination' => 319,
4921
                    'languageCodes' => array(
4922
                        'cro-HR',
4923
                    ),
4924
                    'pathData' => array(
4925
                        array(
4926
                            'always-available' => false,
4927
                            'translations' => array(
4928
                                'cro-HR' => 'dva',
4929
                            ),
4930
                        ),
4931
                        array(
4932
                            'always-available' => false,
4933
                            'translations' => array(
4934
                                'cro-HR' => 'swap-this',
4935
                            ),
4936
                        ),
4937
                    ),
4938
                    'alwaysAvailable' => false,
4939
                    'isHistory' => false,
4940
                    'isCustom' => false,
4941
                    'forward' => false,
4942
                )
4943
            ),
4944
            $urlAlias
4945
        );
4946
4947
        $urlAlias = $handler->lookup('dva/swap-that');
4948
        $this->assertEquals(
4949
            new UrlAlias(
4950
                array(
4951
                    'id' => '3-' . md5('swap-that'),
4952
                    'type' => UrlAlias::LOCATION,
4953
                    'destination' => 319,
4954
                    'languageCodes' => array(
4955
                        'cro-HR',
4956
                    ),
4957
                    'pathData' => array(
4958
                        array(
4959
                            'always-available' => false,
4960
                            'translations' => array(
4961
                                'cro-HR' => 'dva',
4962
                            ),
4963
                        ),
4964
                        array(
4965
                            'always-available' => false,
4966
                            'translations' => array(
4967
                                'cro-HR' => 'swap-that',
4968
                            ),
4969
                        ),
4970
                    ),
4971
                    'alwaysAvailable' => false,
4972
                    'isHistory' => true,
4973
                    'isCustom' => false,
4974
                    'forward' => false,
4975
                )
4976
            ),
4977
            $urlAlias
4978
        );
4979
4980
        $urlAlias = $handler->lookup('jedan/swap-this');
4981
        $this->assertEquals(
4982
            new UrlAlias(
4983
                array(
4984
                    'id' => '2-' . md5('swap-this'),
4985
                    'type' => UrlAlias::LOCATION,
4986
                    'destination' => 318,
4987
                    'languageCodes' => array(
4988
                        'cro-HR',
4989
                    ),
4990
                    'pathData' => array(
4991
                        array(
4992
                            'always-available' => false,
4993
                            'translations' => array(
4994
                                'cro-HR' => 'jedan',
4995
                            ),
4996
                        ),
4997
                        array(
4998
                            'always-available' => false,
4999
                            'translations' => array(
5000
                                'cro-HR' => 'swap-this',
5001
                            ),
5002
                        ),
5003
                    ),
5004
                    'alwaysAvailable' => false,
5005
                    'isHistory' => true,
5006
                    'isCustom' => false,
5007
                    'forward' => false,
5008
                )
5009
            ),
5010
            $urlAlias
5011
        );
5012
    }
5013
5014
    /**
5015
     * Test for the locationSwapped() method.
5016
     *
5017
     * @group swap
5018
     */
5019 View Code Duplication
    public function testLocationSwappedWithReusingNopEntry()
5020
    {
5021
        $handler = $this->getHandler();
5022
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5023
5024
        $countBeforeReusing = $this->countRows();
5025
5026
        $handler->locationSwapped(316, 314, 317, 315);
5027
5028
        $this->assertEquals(
5029
            $countBeforeReusing + 1,
5030
            $this->countRows()
5031
        );
5032
5033
        $urlAlias = $handler->lookup('jedan/swap-that');
5034
        $this->assertEquals(
5035
            new UrlAlias(
5036
                array(
5037
                    'id' => '2-' . md5('swap-that'),
5038
                    'type' => UrlAlias::LOCATION,
5039
                    'destination' => 316,
5040
                    'languageCodes' => array(
5041
                        'cro-HR',
5042
                    ),
5043
                    'pathData' => array(
5044
                        array(
5045
                            'always-available' => false,
5046
                            'translations' => array(
5047
                                'cro-HR' => 'jedan',
5048
                            ),
5049
                        ),
5050
                        array(
5051
                            'always-available' => false,
5052
                            'translations' => array(
5053
                                'cro-HR' => 'swap-that',
5054
                            ),
5055
                        ),
5056
                    ),
5057
                    'alwaysAvailable' => false,
5058
                    'isHistory' => false,
5059
                    'isCustom' => false,
5060
                    'forward' => false,
5061
                )
5062
            ),
5063
            $urlAlias
5064
        );
5065
5066
        $urlAlias = $handler->lookup('dva/swap-this');
5067
        $this->assertEquals(
5068
            new UrlAlias(
5069
                array(
5070
                    'id' => '3-' . md5('swap-this'),
5071
                    'type' => UrlAlias::LOCATION,
5072
                    'destination' => 317,
5073
                    'languageCodes' => array(
5074
                        'cro-HR',
5075
                    ),
5076
                    'pathData' => array(
5077
                        array(
5078
                            'always-available' => false,
5079
                            'translations' => array(
5080
                                'cro-HR' => 'dva',
5081
                            ),
5082
                        ),
5083
                        array(
5084
                            'always-available' => false,
5085
                            'translations' => array(
5086
                                'cro-HR' => 'swap-this',
5087
                            ),
5088
                        ),
5089
                    ),
5090
                    'alwaysAvailable' => false,
5091
                    'isHistory' => false,
5092
                    'isCustom' => false,
5093
                    'forward' => false,
5094
                )
5095
            ),
5096
            $urlAlias
5097
        );
5098
5099
        $urlAlias = $handler->lookup('dva/swap-that');
5100
        $this->assertEquals(
5101
            new UrlAlias(
5102
                array(
5103
                    'id' => '3-' . md5('swap-that'),
5104
                    'type' => UrlAlias::LOCATION,
5105
                    'destination' => 317,
5106
                    'languageCodes' => array(
5107
                        'cro-HR',
5108
                    ),
5109
                    'pathData' => array(
5110
                        array(
5111
                            'always-available' => false,
5112
                            'translations' => array(
5113
                                'cro-HR' => 'dva',
5114
                            ),
5115
                        ),
5116
                        array(
5117
                            'always-available' => false,
5118
                            'translations' => array(
5119
                                'cro-HR' => 'swap-that',
5120
                            ),
5121
                        ),
5122
                    ),
5123
                    'alwaysAvailable' => false,
5124
                    'isHistory' => true,
5125
                    'isCustom' => false,
5126
                    'forward' => false,
5127
                )
5128
            ),
5129
            $urlAlias
5130
        );
5131
5132
        $urlAlias = $handler->lookup('jedan/swap-this');
5133
        $this->assertEquals(
5134
            new UrlAlias(
5135
                array(
5136
                    'id' => '2-' . md5('swap-this'),
5137
                    'type' => UrlAlias::LOCATION,
5138
                    'destination' => 316,
5139
                    'languageCodes' => array(
5140
                        'cro-HR',
5141
                    ),
5142
                    'pathData' => array(
5143
                        array(
5144
                            'always-available' => false,
5145
                            'translations' => array(
5146
                                'cro-HR' => 'jedan',
5147
                            ),
5148
                        ),
5149
                        array(
5150
                            'always-available' => false,
5151
                            'translations' => array(
5152
                                'cro-HR' => 'swap-this',
5153
                            ),
5154
                        ),
5155
                    ),
5156
                    'alwaysAvailable' => false,
5157
                    'isHistory' => true,
5158
                    'isCustom' => false,
5159
                    'forward' => false,
5160
                )
5161
            ),
5162
            $urlAlias
5163
        );
5164
    }
5165
5166
    /**
5167
     * Test for the locationSwapped() method.
5168
     *
5169
     * @depends testLocationSwappedWithReusingNopEntry
5170
     * @group swap
5171
     */
5172 View Code Duplication
    public function testLocationSwappedWithReusingNopEntryCustomAliasIsDestroyed()
5173
    {
5174
        $handler = $this->getHandler();
5175
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_reusing_nop.php');
5176
5177
        $handler->lookup('jedan/swap-that/search');
5178
        $handler->locationSwapped(316, 314, 317, 315);
5179
5180
        try {
5181
            $handler->lookup('jedan/swap-that/search');
5182
            $this->fail('Custom alias is not destroyed');
5183
        } catch (NotFoundException $e) {
5184
            // Custom alias is destroyed by reusing NOP entry with existing autogenerated alias
5185
            // on the same level (that means link and ID are updated to the existing alias ID,
5186
            // so custom alias children entries are no longer properly linked (parent-link))
5187
        }
5188
    }
5189
5190
    /**
5191
     * Test for the locationSwapped() method.
5192
     *
5193
     * @group swap
5194
     *
5195
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5196
     */
5197 View Code Duplication
    public function testLocationSwappedUpdatesLocationPathIdentificationString()
5198
    {
5199
        $handler = $this->getHandler();
5200
        $locationGateway = $this->getLocationGateway();
5201
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_path_identification_string.php');
5202
5203
        $countBeforeReusing = $this->countRows();
5204
5205
        $handler->locationSwapped(314, 2, 315, 2);
5206
5207
        $this->assertEquals(
5208
            $countBeforeReusing,
5209
            $this->countRows()
5210
        );
5211
5212
        $locationData = $locationGateway->getBasicNodeData(314);
5213
        self::assertEquals('dva', $locationData['path_identification_string']);
5214
5215
        $locationData = $locationGateway->getBasicNodeData(315);
5216
        self::assertEquals('jedan', $locationData['path_identification_string']);
5217
    }
5218
5219
    /**
5220
     * Test for the locationSwapped() method.
5221
     *
5222
     * @group swap
5223
     *
5224
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::locationSwapped
5225
     */
5226 View Code Duplication
    public function testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString()
5227
    {
5228
        $handler = $this->getHandler();
5229
        $locationGateway = $this->getLocationGateway();
5230
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_swap_multilang_path_identification_string.php');
5231
5232
        $countBeforeReusing = $this->countRows();
5233
5234
        $handler->locationSwapped(314, 2, 315, 2);
5235
5236
        $this->assertEquals(
5237
            $countBeforeReusing,
5238
            $this->countRows()
5239
        );
5240
5241
        $locationData = $locationGateway->getBasicNodeData(314);
5242
        self::assertEquals('zwei', $locationData['path_identification_string']);
5243
5244
        $locationData = $locationGateway->getBasicNodeData(315);
5245
        self::assertEquals('jedan', $locationData['path_identification_string']);
5246
    }
5247
5248
    /**
5249
     * @return int
5250
     */
5251
    protected function countRows()
5252
    {
5253
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5254
        $query = $this->getDatabaseHandler()->createSelectQuery();
5255
        $query->select(
5256
            $query->expr->count('*')
5257
        )->from(
5258
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5259
        );
5260
5261
        $statement = $query->prepare();
5262
        $statement->execute();
5263
5264
        return (int)$statement->fetchColumn();
5265
    }
5266
5267
    protected function dump()
5268
    {
5269
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
5270
        $query = $this->getDatabaseHandler()->createSelectQuery();
5271
        $query->select(
5272
            '*'
5273
        )->from(
5274
            $this->getDatabaseHandler()->quoteTable('ezurlalias_ml')
5275
        );
5276
5277
        $statement = $query->prepare();
5278
        $statement->execute();
5279
5280
        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...
5281
    }
5282
5283
    /**
5284
     * @var \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler
5285
     */
5286
    protected $dbHandler;
5287
5288
    /**
5289
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5290
     */
5291
    protected $locationGateway;
5292
5293
    /**
5294
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5295
     */
5296
    protected $languageHandler;
5297
5298
    /**
5299
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5300
     */
5301
    protected $languageMaskGenerator;
5302
5303
    /**
5304
     * @param array $methods
5305
     *
5306
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler|\PHPUnit_Framework_MockObject_MockObject
5307
     */
5308
    protected function getPartlyMockedHandler(array $methods)
5309
    {
5310
        $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...
5311
            'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Handler',
5312
            $methods,
5313
            array(
5314
                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...
5315
                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...
5316
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Mapper',
5317
                    array(),
5318
                    array(),
5319
                    '',
5320
                    false
5321
                ),
5322
                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...
5323
                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...
5324
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Language\\Handler',
5325
                    array(),
5326
                    array(),
5327
                    '',
5328
                    false
5329
                ),
5330
                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...
5331
                    'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\SlugConverter',
5332
                    array(),
5333
                    array(),
5334
                    '',
5335
                    false
5336
                ),
5337
                $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...
5338
                    Gateway::class,
5339
                    [],
5340
                    [],
5341
                    '',
5342
                    false
5343
                ),
5344
                $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...
5345
                    LanguageMaskGenerator::class,
5346
                    [],
5347
                    [],
5348
                    '',
5349
                    false
5350
                ),
5351
                $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...
5352
                    'eZ\\Publish\\SPI\\Persistence\\TransactionHandler',
5353
                    [],
5354
                    [],
5355
                    '',
5356
                    false
5357
                ),
5358
            )
5359
        );
5360
5361
        return $mock;
5362
    }
5363
5364
    /**
5365
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5366
     */
5367
    protected function getHandler()
5368
    {
5369
        $languageHandler = $this->getLanguageHandler();
5370
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5371
        $databaseHandler = $this->getDatabaseHandler();
5372
        $gateway = new DoctrineDatabase(
5373
            $databaseHandler,
5374
            $languageMaskGenerator
5375
        );
5376
        $mapper = new Mapper($languageMaskGenerator);
5377
        $slugConverter = new SlugConverter($this->getProcessor());
5378
        $contentGateway = new ContentGateway(
5379
            $this->getDatabaseHandler(),
5380
            $this->getDatabaseConnection(),
5381
            new ContentGateway\QueryBuilder($this->getDatabaseHandler()),
5382
            $languageHandler,
5383
            $languageMaskGenerator
5384
        );
5385
5386
        return new Handler(
5387
            $gateway,
5388
            $mapper,
5389
            $this->getLocationGateway(),
5390
            $languageHandler,
5391
            $slugConverter,
5392
            $contentGateway,
5393
            $languageMaskGenerator,
5394
            $this->createMock('eZ\\Publish\\SPI\\Persistence\\TransactionHandler')
5395
        );
5396
    }
5397
5398
    /**
5399
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler
5400
     */
5401
    protected function getLanguageHandler()
5402
    {
5403
        if (!isset($this->languageHandler)) {
5404
            $this->languageHandler = new LanguageHandler(
5405
                new LanguageGateway(
5406
                    $this->getDatabaseHandler()
5407
                ),
5408
                new LanguageMapper()
5409
            );
5410
        }
5411
5412
        return $this->languageHandler;
5413
    }
5414
5415
    /**
5416
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5417
     */
5418
    protected function getLanguageMaskGenerator()
5419
    {
5420
        if (!isset($this->languageMaskGenerator)) {
5421
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5422
                $this->getLanguageHandler()
5423
            );
5424
        }
5425
5426
        return $this->languageMaskGenerator;
5427
    }
5428
5429
    /**
5430
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5431
     */
5432
    protected function getLocationGateway()
5433
    {
5434
        if (!isset($this->locationGateway)) {
5435
            $this->locationGateway = new DoctrineDatabaseLocation(
5436
                $this->getDatabaseHandler()
5437
            );
5438
        }
5439
5440
        return $this->locationGateway;
5441
    }
5442
5443
    /**
5444
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5445
     */
5446
    public function getProcessor()
5447
    {
5448
        return new DefinitionBased(
5449
            new Parser(),
5450
            new PcreCompiler(new Utf8Converter()),
5451
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5452
        );
5453
    }
5454
}
5455