UrlAliasHandlerTest   F
last analyzed

Complexity

Total Complexity 128

Size/Duplication

Total Lines 5526
Duplicated Lines 36.68 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 0
Metric Value
dl 2027
loc 5526
rs 0.8
c 0
b 0
f 0
wmc 128
lcom 1
cbo 19

103 Methods

Rating   Name   Duplication   Size   Complexity  
B providerForTestLookupLocationUrlAlias() 0 244 1
A testLookupLocationUrlAlias() 31 31 1
A testLookupLocationCaseCorrection() 31 31 1
B providerForTestLookupLocationMultipleLanguages() 0 85 1
A testLookupLocationMultipleLanguages() 31 31 1
A testLookupLocationHistoryUrlAlias() 0 12 1
B providerForTestLookupCustomLocationUrlAlias() 0 115 1
A testLookupCustomLocationUrlAlias() 31 31 1
A testLookupCustomLocationUrlAliasCaseCorrection() 32 32 1
A providerForTestLookupVirtualUrlAlias() 0 13 1
A testLookupVirtualUrlAlias() 9 9 1
A providerForTestLookupResourceUrlAlias() 0 49 1
A testLookupResourceUrlAlias() 32 32 1
A testLookupResourceUrlAliasCaseInsensitive() 32 32 1
A testLookupUppercaseIri() 8 8 1
A assertVirtualUrlAliasValid() 0 22 1
B testListURLAliasesForLocation() 0 63 1
A testPublishUrlAliasForLocation() 34 34 1
A testPublishUrlAliasForLocationRepublish() 0 16 1
A testPublishUrlAliasCreatesUniqueAlias() 34 34 1
A providerForTestPublishUrlAliasForLocationComplex() 0 4 1
A testPublishUrlAliasForLocationComplex() 0 38 1
A testPublishUrlAliasForLocationSameAliasForMultipleLanguages() 0 39 4
B testPublishUrlAliasForLocationDowngradesOldEntryToHistory() 0 62 1
B testPublishUrlAliasForLocationDowngradesOldEntryRemovesLanguage() 0 63 1
A testPublishUrlAliasForLocationReusesHistory() 0 22 1
A testPublishUrlAliasForLocationReusesHistoryOfDifferentLanguage() 0 42 1
A testPublishUrlAliasForLocationReusesCustomAlias() 15 15 1
B testPublishUrlAliasForLocationReusingNopElement() 22 62 3
A testPublishUrlAliasForLocationReusingNopElementChangesCustomPath() 22 39 3
A testPublishUrlAliasForLocationReusingNopElementChangesCustomPathAndCreatesHistory() 0 18 1
A testPublishUrlAliasForLocationUpdatesLocationPathIdentificationString() 0 13 1
B testPublishUrlAliasReuseNopCleanupCustomAliasIsDestroyed() 0 68 2
B testPublishUrlAliasReuseHistoryCleanup() 58 58 1
B testPublishUrlAliasReuseAutogeneratedCleanup() 59 59 1
A testCreateCustomUrlAliasBehaviour() 25 25 1
A testCreateGlobalUrlAliasBehaviour() 25 25 1
A testCreateCustomUrlAlias() 0 39 1
B testCreateCustomUrlAliasWithNonameParts() 0 64 1
A testCreatedCustomUrlAliasIsLoadable() 0 36 3
A testLookup() 8 8 1
A testLookupThrowsNotFoundException() 0 7 1
A testLookupThrowsInvalidArgumentException() 0 7 1
A testCreateCustomUrlAliasWithNopElement() 0 54 1
A testCreateCustomUrlAliasReusesHistory() 40 40 1
A testCreateCustomUrlAliasAddLanguage() 0 43 1
A testCreateCustomUrlAliasReusesHistoryOfDifferentLanguage() 40 40 1
A testCreateCustomUrlAliasReusesNopElement() 0 46 1
A testCreateCustomUrlAliasReusesLocationElement() 26 26 1
A testListGlobalURLAliases() 0 16 1
A testListGlobalURLAliasesWithLanguageCode() 15 15 1
A testListGlobalURLAliasesWithOffset() 0 14 1
A testListGlobalURLAliasesWithOffsetAndLimit() 0 14 1
A testLocationDeleted() 0 49 3
A testLocationMovedHistorize() 31 31 1
A testLocationMovedHistory() 31 31 1
A testLocationMovedHistorySubtree() 39 39 1
A testLocationMovedReparent() 39 39 1
A testLocationMovedReparentHistory() 0 12 1
A testLocationMovedReparentSubtree() 43 43 1
A testLocationMovedReparentSubtreeHistory() 43 43 1
A testLocationCopiedCopiedLocationAliasIsValid() 14 14 1
A testLocationCopiedCopiedSubtreeIsValid() 14 14 1
A testLocationCopiedHistoryNotCopied() 11 11 1
A testLocationCopiedSubtreeHistoryNotCopied() 11 11 1
A testLocationCopiedSubtree() 0 49 1
A testLoadAutogeneratedUrlAlias() 31 31 1
A testLoadResourceUrlAlias() 32 32 1
A testLoadVirtualUrlAlias() 9 9 1
A getHistoryAlias() 0 34 1
A testLoadHistoryUrlAlias() 0 13 1
A testLoadUrlAliasThrowsNotFoundException() 0 8 1
A providerForTestPublishUrlAliasForLocationSkipsReservedWord() 0 13 1
A testPublishUrlAliasForLocationSkipsReservedWord() 0 12 1
B testLocationSwappedSimple() 0 80 1
B testLocationSwappedSimpleWithHistory() 146 146 1
B testLocationSwappedSimpleWithConflict() 0 100 1
B testLocationSwappedSiblingsSimple() 68 68 1
B testLocationSwappedSiblingsSimpleReverse() 68 68 1
B testLocationSwappedSiblingsSimpleWithHistory() 122 122 1
B testLocationSwappedSiblingsSimpleWithHistoryReverse() 122 122 1
B testLocationSwappedSiblingsSameName() 68 68 1
B testLocationSwappedSiblingsSameNameReverse() 68 68 1
B testLocationSwappedSiblingsSameNameMultipleLanguages() 0 126 1
A testLocationSwappedMultipleLanguagesSimple() 0 29 1
B testLocationSwappedMultipleLanguagesDifferentLanguagesSimple() 0 216 1
B testLocationSwappedMultipleLanguagesDifferentLanguages() 0 152 1
B testLocationSwappedMultipleLanguagesWithCompositeHistory() 0 287 1
B testLocationSwappedWithReusingExternalHistory() 146 146 1
B testLocationSwappedWithReusingNopEntry() 146 146 1
A testLocationSwappedWithReusingNopEntryCustomAliasIsDestroyed() 0 17 2
A testLocationSwappedUpdatesLocationPathIdentificationString() 21 21 1
A testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentificationString() 21 21 1
A countRows() 0 15 1
A dump() 0 15 1
A getPartlyMockedHandler() 0 18 1
A getHandler() 0 30 1
A getLanguageHandler() 0 13 2
A getLanguageMaskGenerator() 0 10 2
A getLocationGateway() 0 11 2
A getProcessor() 0 8 1
A providerForArchiveUrlAliasesForDeletedTranslations() 0 7 1
B testArchiveUrlAliasesForDeletedTranslations() 23 59 10

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like UrlAliasHandlerTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use UrlAliasHandlerTest, and based on these observations, apply Extract Interface, too.

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

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...
5368
            ->setConstructorArgs(
5369
                [
5370
                    $this->createMock(UrlAliasGateway::class),
5371
                    $this->createMock(Mapper::class),
5372
                    $this->createMock(LocationGateway::class),
5373
                    $this->createMock(LanguageHandler::class),
5374
                    $this->createMock(SlugConverter::class),
5375
                    $this->createMock(Gateway::class),
5376
                    $this->createMock(LanguageMaskGenerator::class),
5377
                    $this->createMock(TransactionHandler::class),
5378
                ]
5379
            )
5380
            ->setMethods($methods)
5381
            ->getMock();
5382
    }
5383
5384
    /**
5385
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
5386
     *
5387
     * @throws \Doctrine\DBAL\DBALException
5388
     */
5389
    protected function getHandler(): Handler
5390
    {
5391
        $languageHandler = $this->getLanguageHandler();
5392
        $languageMaskGenerator = $this->getLanguageMaskGenerator();
5393
        $gateway = new DoctrineDatabase(
5394
            $this->getDatabaseConnection(),
5395
            $languageMaskGenerator
5396
        );
5397
        $mapper = new Mapper($languageMaskGenerator);
5398
        $slugConverter = new SlugConverter($this->getProcessor());
5399
        $connection = $this->getDatabaseConnection();
5400
        $contentGateway = new ContentGateway(
5401
            $connection,
5402
            $this->getSharedGateway(),
5403
            new ContentGateway\QueryBuilder($connection),
5404
            $languageHandler,
5405
            $languageMaskGenerator
5406
        );
5407
5408
        return new Handler(
5409
            $gateway,
5410
            $mapper,
5411
            $this->getLocationGateway(),
5412
            $languageHandler,
5413
            $slugConverter,
5414
            $contentGateway,
5415
            $languageMaskGenerator,
5416
            $this->createMock(TransactionHandler::class)
5417
        );
5418
    }
5419
5420
    /**
5421
     * @throws \Doctrine\DBAL\DBALException
5422
     */
5423
    protected function getLanguageHandler(): LanguageHandler
5424
    {
5425
        if (!isset($this->languageHandler)) {
5426
            $this->languageHandler = new LanguageHandler(
5427
                new LanguageGateway(
5428
                    $this->getDatabaseConnection()
5429
                ),
5430
                new LanguageMapper()
5431
            );
5432
        }
5433
5434
        return $this->languageHandler;
5435
    }
5436
5437
    /**
5438
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator
5439
     */
5440
    protected function getLanguageMaskGenerator()
5441
    {
5442
        if (!isset($this->languageMaskGenerator)) {
5443
            $this->languageMaskGenerator = new LanguageMaskGenerator(
5444
                $this->getLanguageHandler()
5445
            );
5446
        }
5447
5448
        return $this->languageMaskGenerator;
5449
    }
5450
5451
    /**
5452
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
5453
     */
5454
    protected function getLocationGateway()
5455
    {
5456
        if (!isset($this->locationGateway)) {
5457
            $this->locationGateway = new DoctrineDatabaseLocation(
5458
                $this->getDatabaseConnection(),
5459
                $this->getLanguageMaskGenerator()
5460
            );
5461
        }
5462
5463
        return $this->locationGateway;
5464
    }
5465
5466
    /**
5467
     * @return \eZ\Publish\Core\Persistence\TransformationProcessor
5468
     */
5469
    public function getProcessor()
5470
    {
5471
        return new DefinitionBased(
5472
            new Parser(),
5473
            new PcreCompiler(new Utf8Converter()),
5474
            glob(__DIR__ . '/../../../../Tests/TransformationProcessor/_fixtures/transformations/*.tr')
5475
        );
5476
    }
5477
5478
    /**
5479
     * Data provider for tests of archiveUrlAliasesForDeletedTranslations.
5480
     *
5481
     * @see testArchiveUrlAliasesForDeletedTranslations for the description of parameters
5482
     *
5483
     * @return array
5484
     */
5485
    public function providerForArchiveUrlAliasesForDeletedTranslations()
5486
    {
5487
        return [
5488
            [2, ['eng-GB', 'pol-PL'], 'pol-PL'],
5489
            [3, ['eng-GB', 'pol-PL', 'nor-NO'], 'pol-PL'],
5490
        ];
5491
    }
5492
5493
    /**
5494
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::archiveUrlAliasesForDeletedTranslations()
5495
     *
5496
     * @dataProvider providerForArchiveUrlAliasesForDeletedTranslations
5497
     *
5498
     * @param int $locationId
5499
     * @param string[] $expectedLanguages expected language codes before deleting
5500
     * @param string $removeLanguage language code to be deleted
5501
     */
5502
    public function testArchiveUrlAliasesForDeletedTranslations(
5503
        $locationId,
5504
        array $expectedLanguages,
5505
        $removeLanguage
5506
    ) {
5507
        $handler = $this->getHandler();
5508
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/publish_multilingual.php');
5509
5510
        // collect data persisted from fixtures
5511
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5512
        $collectedLanguages = [];
5513
        $collectedUrls = [];
5514
        foreach ($urlAliases as $urlAlias) {
5515
            // collect languages of all URL aliases
5516
            $collectedLanguages = array_merge($collectedLanguages, $urlAlias->languageCodes);
5517
            $isComposite = count($urlAlias->languageCodes) > 1;
5518
            foreach ($urlAlias->pathData as $pathData) {
5519
                // collect also actual unique URLs to be removed to check them after removal
5520
                if (!empty($pathData['translations'][$removeLanguage])) {
5521
                    $url = $pathData['translations'][$removeLanguage];
5522
                    $collectedUrls[$url] = $isComposite;
5523
                }
5524
            }
5525
        }
5526
        // sanity check
5527
        self::assertEquals($expectedLanguages, $collectedLanguages);
5528
5529
        // remove language
5530
        $publishedLanguages = array_values(array_diff($collectedLanguages, [$removeLanguage]));
5531
        $handler->archiveUrlAliasesForDeletedTranslations($locationId, 1, $publishedLanguages);
5532
5533
        // check reloaded structures
5534
        $urlAliases = $handler->listURLAliasesForLocation($locationId);
5535 View Code Duplication
        foreach ($urlAliases as $urlAlias) {
0 ignored issues
show
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...
5536
            self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5537
            foreach ($urlAlias->pathData as $pathData) {
5538
                self::assertNotContains($removeLanguage, $pathData['translations']);
5539
                foreach ($pathData['translations'] as $url) {
5540
                    $lookupUrlAlias = $handler->lookup($url);
5541
                    self::assertNotContains($removeLanguage, $lookupUrlAlias->languageCodes);
5542
                }
5543
            }
5544
        }
5545
5546
        // lookup removed URLs to check they're not found
5547 View Code Duplication
        foreach ($collectedUrls as $url => $isComposite) {
0 ignored issues
show
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...
5548
            $urlAlias = $handler->lookup($url);
5549
            if ($isComposite) {
5550
                // check if alias no longer refers to removed Translation
5551
                self::assertNotContains($removeLanguage, $urlAlias->languageCodes);
5552
                foreach ($urlAlias->pathData as $pathData) {
5553
                    self::assertNotContains($removeLanguage, $pathData['translations']);
5554
                }
5555
            } else {
5556
                // check if non composite alias for removed translation is historized
5557
                self::assertTrue($urlAlias->isHistory);
5558
            }
5559
        }
5560
    }
5561
}
5562