Completed
Push — ezp30878_cant_add_image_with_p... ( e19ea7...263f1b )
by
unknown
20:16
created

UrlAliasTest::providerForTestReverseLookup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\UrlAliasTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\Tests\Service\Mock;
10
11
use eZ\Publish\Core\Repository\URLAliasService;
12
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
13
use eZ\Publish\SPI\Persistence\Content\UrlAlias as SPIUrlAlias;
14
use eZ\Publish\API\Repository\Values\Content\UrlAlias;
15
use eZ\Publish\Core\Repository\Values\Content\Location;
16
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
17
use eZ\Publish\Core\Base\Exceptions\ForbiddenException;
18
use Exception;
19
20
/**
21
 * Mock test case for UrlAlias Service.
22
 */
23
class UrlAliasTest extends BaseServiceMockTest
24
{
25
    /**
26
     * Test for the __construct() method.
27
     */
28
    public function testConstructor()
29
    {
30
        $repositoryMock = $this->getRepositoryMock();
31
        $languageServiceMock = $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
32
            'eZ\\Publish\\Core\\Repository\\LanguageService',
33
            [],
34
            [],
35
            '',
36
            false
37
        );
38
        /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler $urlAliasHandler */
39
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
40
        $settings = ['settings'];
41
42
        $languageServiceMock
43
            ->expects($this->once())
44
            ->method('getPrioritizedLanguageCodeList')
45
            ->will($this->returnValue(['prioritizedLanguageList']));
46
47
        $repositoryMock
48
            ->expects($this->once())
49
            ->method('getContentLanguageService')
50
            ->will($this->returnValue($languageServiceMock));
51
52
        $service = new UrlALiasService(
53
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 30 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...sService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
            $urlAliasHandler,
55
            $this->getNameSchemaServiceMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getNameSchemaServiceMock() targeting eZ\Publish\Core\Reposito...NameSchemaServiceMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...sService::__construct() does only seem to accept object<eZ\Publish\Core\R...lper\NameSchemaService>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
56
            $settings
57
        );
58
59
        $this->assertAttributeSame(
60
            $repositoryMock,
61
            'repository',
62
            $service
63
        );
64
65
        $this->assertAttributeSame(
66
            $urlAliasHandler,
67
            'urlAliasHandler',
68
            $service
69
        );
70
71
        $this->assertAttributeSame(
72
            [
73
                'settings',
74
                'showAllTranslations' => false,
75
                'prioritizedLanguageList' => ['prioritizedLanguageList'],
76
            ],
77
            'settings',
78
            $service
79
        );
80
    }
81
82
    /**
83
     * Test for the load() method.
84
     */
85
    public function testLoad()
86
    {
87
        $mockedService = $this->getPartlyMockedURLAliasServiceService(['extractPath']);
88
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
89
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
90
91
        $urlAliasHandlerMock
92
            ->expects($this->once())
93
            ->method('loadUrlAlias')
94
            ->with(42)
95
            ->will($this->returnValue(new SPIUrlAlias()));
96
97
        $mockedService
98
            ->expects($this->once())
99
            ->method('extractPath')
100
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias'), null)
101
            ->will($this->returnValue('path'));
102
103
        $urlAlias = $mockedService->load(42);
104
105
        self::assertInstanceOf(
106
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
107
            $urlAlias
108
        );
109
    }
110
111
    /**
112
     * Test for the load() method.
113
     *
114
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
115
     */
116
    public function testLoadThrowsNotFoundException()
117
    {
118
        $mockedService = $this->getPartlyMockedURLAliasServiceService(['extractPath']);
119
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
120
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
121
122
        $urlAliasHandlerMock
123
            ->expects($this->once())
124
            ->method('loadUrlAlias')
125
            ->with(42)
126
            ->will($this->throwException(new NotFoundException('UrlAlias', 42)));
127
128
        $mockedService->load(42);
129
    }
130
131
    protected function getSpiUrlAlias()
132
    {
133
        $pathElement1 = [
134
            'always-available' => true,
135
            'translations' => [
136
                'cro-HR' => 'jedan',
137
            ],
138
        ];
139
        $pathElement2 = [
140
            'always-available' => false,
141
            'translations' => [
142
                'cro-HR' => 'dva',
143
                'eng-GB' => 'two',
144
            ],
145
        ];
146
        $pathElement3 = [
147
            'always-available' => false,
148
            'translations' => [
149
                'cro-HR' => 'tri',
150
                'eng-GB' => 'three',
151
                'ger-DE' => 'drei',
152
            ],
153
        ];
154
155
        return new SPIUrlAlias(
156
            [
157
                'id' => '3',
158
                'pathData' => [$pathElement1, $pathElement2, $pathElement3],
159
                'languageCodes' => ['ger-DE'],
160
                'alwaysAvailable' => false,
161
            ]
162
        );
163
    }
164
165
    /**
166
     * Test for the load() method.
167
     *
168
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
169
     */
170
    public function testLoadThrowsNotFoundExceptionPath()
171
    {
172
        $spiUrlAlias = $this->getSpiUrlAlias();
173
        $urlAliasService = $this->getRepository()->getURLAliasService();
174
        $configuration = [
175
            'prioritizedLanguageList' => ['fre-FR'],
176
            'showAllTranslations' => false,
177
        ];
178
        $this->setConfiguration($urlAliasService, $configuration);
179
180
        $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
181
182
        $urlAliasHandlerMock
183
            ->expects($this->once())
184
            ->method('loadUrlAlias')
185
            ->with(42)
186
            ->will($this->returnValue($spiUrlAlias));
187
188
        $urlAliasService->load(42);
189
    }
190
191
    /**
192
     * Test for the removeAliases() method.
193
     *
194
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
195
     */
196
    public function testRemoveAliasesThrowsInvalidArgumentException()
197
    {
198
        $aliasList = [new UrlAlias(['isCustom' => false])];
199
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
200
        $mockedService->removeAliases($aliasList);
201
    }
202
203
    /**
204
     * Test for the removeAliases() method.
205
     */
206 View Code Duplication
    public function testRemoveAliases()
207
    {
208
        $aliasList = [new UrlAlias(['isCustom' => true])];
209
        $spiAliasList = [new SPIUrlAlias(['isCustom' => true])];
210
        $repositoryMock = $this->getRepositoryMock();
211
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
212
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
213
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
214
215
        $repositoryMock
216
            ->expects($this->once())
217
            ->method('beginTransaction');
218
        $repositoryMock
219
            ->expects($this->once())
220
            ->method('commit');
221
222
        $urlAliasHandlerMock
223
            ->expects($this->once())
224
            ->method('removeURLAliases')
225
            ->with($spiAliasList);
226
227
        $mockedService->removeAliases($aliasList);
228
    }
229
230
    /**
231
     * Test for the removeAliases() method.
232
     *
233
     * @expectedException \Exception
234
     * @expectedExceptionMessage Handler threw an exception
235
     */
236 View Code Duplication
    public function testRemoveAliasesWithRollback()
237
    {
238
        $aliasList = [new UrlAlias(['isCustom' => true])];
239
        $spiAliasList = [new SPIUrlAlias(['isCustom' => true])];
240
        $repositoryMock = $this->getRepositoryMock();
241
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
242
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
243
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
244
245
        $repositoryMock
246
            ->expects($this->once())
247
            ->method('beginTransaction');
248
        $repositoryMock
249
            ->expects($this->once())
250
            ->method('rollback');
251
252
        $urlAliasHandlerMock
253
            ->expects($this->once())
254
            ->method('removeURLAliases')
255
            ->with($spiAliasList)
256
            ->will($this->throwException(new Exception('Handler threw an exception')));
257
258
        $mockedService->removeAliases($aliasList);
259
    }
260
261
    public function providerForTestListAutogeneratedLocationAliasesPath()
262
    {
263
        $pathElement1 = [
264
            'always-available' => true,
265
            'translations' => [
266
                'cro-HR' => 'jedan',
267
            ],
268
        ];
269
        $pathElement2 = [
270
            'always-available' => false,
271
            'translations' => [
272
                'cro-HR' => 'dva',
273
                'eng-GB' => 'two',
274
            ],
275
        ];
276
        $pathElement3 = [
277
            'always-available' => false,
278
            'translations' => [
279
                'cro-HR' => 'tri',
280
                'eng-GB' => 'three',
281
                'ger-DE' => 'drei',
282
            ],
283
        ];
284
        $pathData1 = [$pathElement1];
285
        $pathData2 = [$pathElement1, $pathElement2];
286
        $pathData3 = [$pathElement1, $pathElement2, $pathElement3];
287
        $spiUrlAliases1 = [
288
            new SPIUrlAlias(
289
                [
290
                    'id' => '1',
291
                    'pathData' => $pathData1,
292
                    'languageCodes' => ['cro-HR'],
293
                    'alwaysAvailable' => true,
294
                ]
295
            ),
296
        ];
297
        $spiUrlAliases2 = [
298
            new SPIUrlAlias(
299
                [
300
                    'id' => '1',
301
                    'pathData' => $pathData2,
302
                    'languageCodes' => ['cro-HR'],
303
                    'alwaysAvailable' => false,
304
                ]
305
            ),
306
            new SPIUrlAlias(
307
                [
308
                    'id' => '2',
309
                    'pathData' => $pathData2,
310
                    'languageCodes' => ['eng-GB'],
311
                    'alwaysAvailable' => false,
312
                ]
313
            ),
314
        ];
315
        $spiUrlAliases3 = [
316
            new SPIUrlAlias(
317
                [
318
                    'id' => '1',
319
                    'pathData' => $pathData3,
320
                    'languageCodes' => ['cro-HR'],
321
                    'alwaysAvailable' => false,
322
                ]
323
            ),
324
            new SPIUrlAlias(
325
                [
326
                    'id' => '2',
327
                    'pathData' => $pathData3,
328
                    'languageCodes' => ['eng-GB'],
329
                    'alwaysAvailable' => false,
330
                ]
331
            ),
332
            new SPIUrlAlias(
333
                [
334
                    'id' => '3',
335
                    'pathData' => $pathData3,
336
                    'languageCodes' => ['ger-DE'],
337
                    'alwaysAvailable' => false,
338
                ]
339
            ),
340
        ];
341
342
        return [
343
            [
344
                $spiUrlAliases1,
345
                ['cro-HR'],
346
                [
347
                    'cro-HR' => '/jedan',
348
                ],
349
                'cro-HR',
350
            ],
351
            [
352
                $spiUrlAliases1,
353
                ['eng-GB'],
354
                [
355
                    'cro-HR' => '/jedan',
356
                ],
357
                'cro-HR',
358
            ],
359
            [
360
                $spiUrlAliases1,
361
                ['ger-DE'],
362
                [
363
                    'cro-HR' => '/jedan',
364
                ],
365
                'cro-HR',
366
            ],
367
            [
368
                $spiUrlAliases1,
369
                ['cro-HR', 'eng-GB', 'ger-DE'],
370
                [
371
                    'cro-HR' => '/jedan',
372
                ],
373
                'cro-HR',
374
            ],
375
            [
376
                $spiUrlAliases2,
377
                ['cro-HR'],
378
                [
379
                    'cro-HR' => '/jedan/dva',
380
                ],
381
                'cro-HR',
382
            ],
383
            [
384
                $spiUrlAliases2,
385
                ['eng-GB'],
386
                [
387
                    'eng-GB' => '/jedan/two',
388
                ],
389
                'eng-GB',
390
            ],
391
            [
392
                $spiUrlAliases2,
393
                ['cro-HR', 'eng-GB'],
394
                [
395
                    'cro-HR' => '/jedan/dva',
396
                    'eng-GB' => '/jedan/two',
397
                ],
398
                'cro-HR',
399
            ],
400
            [
401
                $spiUrlAliases2,
402
                ['cro-HR', 'ger-DE'],
403
                [
404
                    'cro-HR' => '/jedan/dva',
405
                ],
406
                'cro-HR',
407
            ],
408
            [
409
                $spiUrlAliases2,
410
                ['eng-GB', 'cro-HR'],
411
                [
412
                    'eng-GB' => '/jedan/two',
413
                    'cro-HR' => '/jedan/dva',
414
                ],
415
                'eng-GB',
416
            ],
417
            [
418
                $spiUrlAliases2,
419
                ['eng-GB', 'ger-DE'],
420
                [
421
                    'eng-GB' => '/jedan/two',
422
                ],
423
                'eng-GB',
424
            ],
425
            [
426
                $spiUrlAliases2,
427
                ['ger-DE', 'cro-HR'],
428
                [
429
                    'cro-HR' => '/jedan/dva',
430
                ],
431
                'cro-HR',
432
            ],
433
            [
434
                $spiUrlAliases2,
435
                ['ger-DE', 'eng-GB'],
436
                [
437
                    'eng-GB' => '/jedan/two',
438
                ],
439
                'eng-GB',
440
            ],
441
            [
442
                $spiUrlAliases2,
443
                ['cro-HR', 'eng-GB', 'ger-DE'],
444
                [
445
                    'cro-HR' => '/jedan/dva',
446
                    'eng-GB' => '/jedan/two',
447
                ],
448
                'cro-HR',
449
            ],
450
            [
451
                $spiUrlAliases2,
452
                ['cro-HR', 'ger-DE', 'eng-GB'],
453
                [
454
                    'cro-HR' => '/jedan/dva',
455
                    'eng-GB' => '/jedan/two',
456
                ],
457
                'cro-HR',
458
            ],
459
            [
460
                $spiUrlAliases2,
461
                ['eng-GB', 'cro-HR', 'ger-DE'],
462
                [
463
                    'eng-GB' => '/jedan/two',
464
                    'cro-HR' => '/jedan/dva',
465
                ],
466
                'eng-GB',
467
            ],
468
            [
469
                $spiUrlAliases2,
470
                ['eng-GB', 'ger-DE', 'cro-HR'],
471
                [
472
                    'eng-GB' => '/jedan/two',
473
                    'cro-HR' => '/jedan/dva',
474
                ],
475
                'eng-GB',
476
            ],
477
            [
478
                $spiUrlAliases2,
479
                ['ger-DE', 'cro-HR', 'eng-GB'],
480
                [
481
                    'cro-HR' => '/jedan/dva',
482
                    'eng-GB' => '/jedan/two',
483
                ],
484
                'cro-HR',
485
            ],
486
            [
487
                $spiUrlAliases2,
488
                ['ger-DE', 'eng-GB', 'cro-HR'],
489
                [
490
                    'eng-GB' => '/jedan/two',
491
                    'cro-HR' => '/jedan/dva',
492
                ],
493
                'eng-GB',
494
            ],
495
            [
496
                $spiUrlAliases3,
497
                ['cro-HR'],
498
                [
499
                    'cro-HR' => '/jedan/dva/tri',
500
                ],
501
                'cro-HR',
502
            ],
503
            [
504
                $spiUrlAliases3,
505
                ['eng-GB'],
506
                [
507
                    'eng-GB' => '/jedan/two/three',
508
                ],
509
                'eng-GB',
510
            ],
511
            [
512
                $spiUrlAliases3,
513
                ['cro-HR', 'eng-GB'],
514
                [
515
                    'cro-HR' => '/jedan/dva/tri',
516
                    'eng-GB' => '/jedan/dva/three',
517
                ],
518
                'cro-HR',
519
            ],
520
            [
521
                $spiUrlAliases3,
522
                ['cro-HR', 'ger-DE'],
523
                [
524
                    'cro-HR' => '/jedan/dva/tri',
525
                    'ger-DE' => '/jedan/dva/drei',
526
                ],
527
                'cro-HR',
528
            ],
529
            [
530
                $spiUrlAliases3,
531
                ['eng-GB', 'cro-HR'],
532
                [
533
                    'eng-GB' => '/jedan/two/three',
534
                    'cro-HR' => '/jedan/two/tri',
535
                ],
536
                'eng-GB',
537
            ],
538
            [
539
                $spiUrlAliases3,
540
                ['eng-GB', 'ger-DE'],
541
                [
542
                    'eng-GB' => '/jedan/two/three',
543
                    'ger-DE' => '/jedan/two/drei',
544
                ],
545
                'eng-GB',
546
            ],
547
            [
548
                $spiUrlAliases3,
549
                ['ger-DE', 'eng-GB'],
550
                [
551
                    'ger-DE' => '/jedan/two/drei',
552
                    'eng-GB' => '/jedan/two/three',
553
                ],
554
                'ger-DE',
555
            ],
556
            [
557
                $spiUrlAliases3,
558
                ['ger-DE', 'cro-HR'],
559
                [
560
                    'ger-DE' => '/jedan/dva/drei',
561
                    'cro-HR' => '/jedan/dva/tri',
562
                ],
563
                'ger-DE',
564
            ],
565
            [
566
                $spiUrlAliases3,
567
                ['cro-HR', 'eng-GB', 'ger-DE'],
568
                [
569
                    'cro-HR' => '/jedan/dva/tri',
570
                    'eng-GB' => '/jedan/dva/three',
571
                    'ger-DE' => '/jedan/dva/drei',
572
                ],
573
                'cro-HR',
574
            ],
575
            [
576
                $spiUrlAliases3,
577
                ['cro-HR', 'ger-DE', 'eng-GB'],
578
                [
579
                    'cro-HR' => '/jedan/dva/tri',
580
                    'ger-DE' => '/jedan/dva/drei',
581
                    'eng-GB' => '/jedan/dva/three',
582
                ],
583
                'cro-HR',
584
            ],
585
            [
586
                $spiUrlAliases3,
587
                ['eng-GB', 'cro-HR', 'ger-DE'],
588
                [
589
                    'eng-GB' => '/jedan/two/three',
590
                    'cro-HR' => '/jedan/two/tri',
591
                    'ger-DE' => '/jedan/two/drei',
592
                ],
593
                'eng-GB',
594
            ],
595
            [
596
                $spiUrlAliases3,
597
                ['eng-GB', 'ger-DE', 'cro-HR'],
598
                [
599
                    'eng-GB' => '/jedan/two/three',
600
                    'ger-DE' => '/jedan/two/drei',
601
                    'cro-HR' => '/jedan/two/tri',
602
                ],
603
                'eng-GB',
604
            ],
605
            [
606
                $spiUrlAliases3,
607
                ['ger-DE', 'cro-HR', 'eng-GB'],
608
                [
609
                    'ger-DE' => '/jedan/dva/drei',
610
                    'cro-HR' => '/jedan/dva/tri',
611
                    'eng-GB' => '/jedan/dva/three',
612
                ],
613
                'ger-DE',
614
            ],
615
            [
616
                $spiUrlAliases3,
617
                ['ger-DE', 'eng-GB', 'cro-HR'],
618
                [
619
                    'ger-DE' => '/jedan/two/drei',
620
                    'eng-GB' => '/jedan/two/three',
621
                    'cro-HR' => '/jedan/two/tri',
622
                ],
623
                'ger-DE',
624
            ],
625
        ];
626
    }
627
628
    /**
629
     * Test for the listLocationAliases() method.
630
     *
631
     * @dataProvider providerForTestListAutogeneratedLocationAliasesPath
632
     */
633 View Code Duplication
    public function testListAutogeneratedLocationAliasesPath($spiUrlAliases, $prioritizedLanguageCodes, $paths)
634
    {
635
        $urlAliasService = $this->getRepository()->getURLAliasService();
636
        $configuration = [
637
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
638
            'showAllTranslations' => false,
639
        ];
640
        $this->setConfiguration($urlAliasService, $configuration);
641
642
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
643
        $urlAliasHandler->expects(
644
            $this->once()
645
        )->method(
646
            'listURLAliasesForLocation'
647
        )->with(
648
            $this->equalTo(42),
649
            $this->equalTo(false)
650
        )->will(
651
            $this->returnValue($spiUrlAliases)
652
        );
653
654
        $location = $this->getLocationStub();
655
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
656
657
        self::assertEquals(
658
            count($paths),
659
            count($urlAliases)
660
        );
661
662
        foreach ($urlAliases as $index => $urlAlias) {
663
            $pathKeys = array_keys($paths);
664
            self::assertEquals(
665
                $paths[$pathKeys[$index]],
666
                $urlAlias->path
667
            );
668
            self::assertEquals(
669
                [$pathKeys[$index]],
670
                $urlAlias->languageCodes
671
            );
672
        }
673
    }
674
675
    /**
676
     * Test for the listLocationAliases() method.
677
     *
678
     * @dataProvider providerForTestListAutogeneratedLocationAliasesPath
679
     */
680 View Code Duplication
    public function testListAutogeneratedLocationAliasesPathCustomConfiguration(
681
        $spiUrlAliases,
682
        $prioritizedLanguageCodes,
683
        $paths
684
    ) {
685
        $urlAliasService = $this->getRepository()->getURLAliasService();
686
        $configuration = [
687
            'prioritizedLanguageList' => [],
688
            'showAllTranslations' => false,
689
        ];
690
        $this->setConfiguration($urlAliasService, $configuration);
691
692
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
693
        $urlAliasHandler->expects(
694
            $this->once()
695
        )->method(
696
            'listURLAliasesForLocation'
697
        )->with(
698
            $this->equalTo(42),
699
            $this->equalTo(false)
700
        )->will(
701
            $this->returnValue($spiUrlAliases)
702
        );
703
704
        $location = $this->getLocationStub();
705
        $urlAliases = $urlAliasService->listLocationAliases(
706
            $location,
707
            false,
708
            null,
709
            false,
710
            $prioritizedLanguageCodes
711
        );
712
713
        self::assertEquals(
714
            count($paths),
715
            count($urlAliases)
716
        );
717
718
        foreach ($urlAliases as $index => $urlAlias) {
719
            $pathKeys = array_keys($paths);
720
            self::assertEquals(
721
                $paths[$pathKeys[$index]],
722
                $urlAlias->path
723
            );
724
            self::assertEquals(
725
                [$pathKeys[$index]],
726
                $urlAlias->languageCodes
727
            );
728
        }
729
    }
730
731
    /**
732
     * Test for the load() method.
733
     */
734 View Code Duplication
    public function testListLocationAliasesWithShowAllTranslations()
735
    {
736
        $pathElement1 = [
737
            'always-available' => true,
738
            'translations' => [
739
                'cro-HR' => 'jedan',
740
            ],
741
        ];
742
        $pathElement2 = [
743
            'always-available' => false,
744
            'translations' => [
745
                'cro-HR' => 'dva',
746
                'eng-GB' => 'two',
747
            ],
748
        ];
749
        $pathElement3 = [
750
            'always-available' => false,
751
            'translations' => [
752
                'cro-HR' => 'tri',
753
                'eng-GB' => 'three',
754
                'ger-DE' => 'drei',
755
            ],
756
        ];
757
        $spiUrlAlias = new SPIUrlAlias(
758
            [
759
                'id' => '3',
760
                'pathData' => [$pathElement1, $pathElement2, $pathElement3],
761
                'languageCodes' => ['ger-DE'],
762
                'alwaysAvailable' => false,
763
            ]
764
        );
765
        $urlAliasService = $this->getRepository()->getURLAliasService();
766
        $configuration = [
767
            'prioritizedLanguageList' => ['fre-FR'],
768
            'showAllTranslations' => true,
769
        ];
770
        $this->setConfiguration($urlAliasService, $configuration);
771
772
        $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
773
774
        $urlAliasHandlerMock->expects(
775
            $this->once()
776
        )->method(
777
            'listURLAliasesForLocation'
778
        )->with(
779
            $this->equalTo(42),
780
            $this->equalTo(false)
781
        )->will(
782
            $this->returnValue([$spiUrlAlias])
783
        );
784
785
        $location = $this->getLocationStub();
786
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
787
788
        self::assertCount(1, $urlAliases);
789
        self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', $urlAliases[0]);
790
        self::assertEquals('/jedan/dva/tri', $urlAliases[0]->path);
791
    }
792
793
    /**
794
     * Test for the load() method.
795
     */
796 View Code Duplication
    public function testListLocationAliasesWithShowAllTranslationsCustomConfiguration()
797
    {
798
        $pathElement1 = [
799
            'always-available' => true,
800
            'translations' => [
801
                'cro-HR' => 'jedan',
802
            ],
803
        ];
804
        $pathElement2 = [
805
            'always-available' => false,
806
            'translations' => [
807
                'cro-HR' => 'dva',
808
                'eng-GB' => 'two',
809
            ],
810
        ];
811
        $pathElement3 = [
812
            'always-available' => false,
813
            'translations' => [
814
                'cro-HR' => 'tri',
815
                'eng-GB' => 'three',
816
                'ger-DE' => 'drei',
817
            ],
818
        ];
819
        $spiUrlAlias = new SPIUrlAlias(
820
            [
821
                'id' => '3',
822
                'pathData' => [$pathElement1, $pathElement2, $pathElement3],
823
                'languageCodes' => ['ger-DE'],
824
                'alwaysAvailable' => false,
825
            ]
826
        );
827
        $urlAliasService = $this->getRepository()->getURLAliasService();
828
        $configuration = [
829
            'prioritizedLanguageList' => [],
830
            'showAllTranslations' => false,
831
        ];
832
        $this->setConfiguration($urlAliasService, $configuration);
833
834
        $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
835
836
        $urlAliasHandlerMock->expects(
837
            $this->once()
838
        )->method(
839
            'listURLAliasesForLocation'
840
        )->with(
841
            $this->equalTo(42),
842
            $this->equalTo(false)
843
        )->will(
844
            $this->returnValue([$spiUrlAlias])
845
        );
846
847
        $location = $this->getLocationStub();
848
        $urlAliases = $urlAliasService->listLocationAliases(
849
            $location,
850
            false,
851
            null,
852
            true,
853
            ['fre-FR']
854
        );
855
856
        self::assertCount(1, $urlAliases);
857
        self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', $urlAliases[0]);
858
        self::assertEquals('/jedan/dva/tri', $urlAliases[0]->path);
859
    }
860
861
    public function providerForTestListAutogeneratedLocationAliasesEmpty()
862
    {
863
        $pathElement1 = [
864
            'always-available' => true,
865
            'translations' => [
866
                'cro-HR' => '/jedan',
867
            ],
868
        ];
869
        $pathElement2 = [
870
            'always-available' => false,
871
            'translations' => [
872
                'cro-HR' => 'dva',
873
                'eng-GB' => 'two',
874
            ],
875
        ];
876
        $pathElement3 = [
877
            'always-available' => false,
878
            'translations' => [
879
                'cro-HR' => 'tri',
880
                'eng-GB' => 'three',
881
                'ger-DE' => 'drei',
882
            ],
883
        ];
884
        $pathData2 = [$pathElement1, $pathElement2];
885
        $pathData3 = [$pathElement1, $pathElement2, $pathElement3];
886
        $spiUrlAliases2 = [
887
            new SPIUrlAlias(
888
                [
889
                    'pathData' => $pathData2,
890
                    'languageCodes' => ['cro-HR'],
891
                    'alwaysAvailable' => false,
892
                ]
893
            ),
894
            new SPIUrlAlias(
895
                [
896
                    'pathData' => $pathData2,
897
                    'languageCodes' => ['eng-GB'],
898
                    'alwaysAvailable' => false,
899
                ]
900
            ),
901
        ];
902
        $spiUrlAliases3 = [
903
            new SPIUrlAlias(
904
                [
905
                    'pathData' => $pathData3,
906
                    'languageCodes' => ['cro-HR'],
907
                    'alwaysAvailable' => false,
908
                ]
909
            ),
910
            new SPIUrlAlias(
911
                [
912
                    'pathData' => $pathData3,
913
                    'languageCodes' => ['eng-GB'],
914
                    'alwaysAvailable' => false,
915
                ]
916
            ),
917
            new SPIUrlAlias(
918
                [
919
                    'pathData' => $pathData3,
920
                    'languageCodes' => ['ger-DE'],
921
                    'alwaysAvailable' => false,
922
                ]
923
            ),
924
        ];
925
926
        return [
927
            [
928
                $spiUrlAliases2,
929
                ['ger-DE'],
930
            ],
931
            [
932
                $spiUrlAliases3,
933
                ['ger-DE'],
934
            ],
935
        ];
936
    }
937
938
    /**
939
     * Test for the listLocationAliases() method.
940
     *
941
     * @dataProvider providerForTestListAutogeneratedLocationAliasesEmpty
942
     */
943 View Code Duplication
    public function testListAutogeneratedLocationAliasesEmpty($spiUrlAliases, $prioritizedLanguageCodes)
944
    {
945
        $urlAliasService = $this->getRepository()->getURLAliasService();
946
        $configuration = [
947
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
948
            'showAllTranslations' => false,
949
        ];
950
        $this->setConfiguration($urlAliasService, $configuration);
951
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
952
        $urlAliasHandler->expects(
953
            $this->once()
954
        )->method(
955
            'listURLAliasesForLocation'
956
        )->with(
957
            $this->equalTo(42),
958
            $this->equalTo(false)
959
        )->will(
960
            $this->returnValue($spiUrlAliases)
961
        );
962
963
        $location = $this->getLocationStub();
964
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
965
966
        self::assertEmpty($urlAliases);
967
    }
968
969
    /**
970
     * Test for the listLocationAliases() method.
971
     *
972
     * @dataProvider providerForTestListAutogeneratedLocationAliasesEmpty
973
     */
974 View Code Duplication
    public function testListAutogeneratedLocationAliasesEmptyCustomConfiguration(
975
        $spiUrlAliases,
976
        $prioritizedLanguageCodes
977
    ) {
978
        $urlAliasService = $this->getRepository()->getURLAliasService();
979
        $configuration = [
980
            'prioritizedLanguageList' => [],
981
            'showAllTranslations' => false,
982
        ];
983
        $this->setConfiguration($urlAliasService, $configuration);
984
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
985
        $urlAliasHandler->expects(
986
            $this->once()
987
        )->method(
988
            'listURLAliasesForLocation'
989
        )->with(
990
            $this->equalTo(42),
991
            $this->equalTo(false)
992
        )->will(
993
            $this->returnValue($spiUrlAliases)
994
        );
995
996
        $location = $this->getLocationStub();
997
        $urlAliases = $urlAliasService->listLocationAliases(
998
            $location,
999
            false,
1000
            null,
1001
            false,
1002
            $prioritizedLanguageCodes
1003
        );
1004
1005
        self::assertEmpty($urlAliases);
1006
    }
1007
1008
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodePath()
1009
    {
1010
        $pathElement1 = [
1011
            'always-available' => true,
1012
            'translations' => [
1013
                'cro-HR' => 'jedan',
1014
            ],
1015
        ];
1016
        $pathElement2 = [
1017
            'always-available' => false,
1018
            'translations' => [
1019
                'cro-HR' => 'dva',
1020
                'eng-GB' => 'two',
1021
            ],
1022
        ];
1023
        $pathElement3 = [
1024
            'always-available' => false,
1025
            'translations' => [
1026
                'cro-HR' => 'tri',
1027
                'eng-GB' => 'three',
1028
                'ger-DE' => 'drei',
1029
            ],
1030
        ];
1031
        $pathData1 = [$pathElement1];
1032
        $pathData2 = [$pathElement1, $pathElement2];
1033
        $pathData3 = [$pathElement1, $pathElement2, $pathElement3];
1034
        $spiUrlAliases1 = [
1035
            new SPIUrlAlias(
1036
                [
1037
                    'pathData' => $pathData1,
1038
                    'languageCodes' => ['cro-HR'],
1039
                    'alwaysAvailable' => true,
1040
                ]
1041
            ),
1042
        ];
1043
        $spiUrlAliases2 = [
1044
            new SPIUrlAlias(
1045
                [
1046
                    'pathData' => $pathData2,
1047
                    'languageCodes' => ['cro-HR'],
1048
                    'alwaysAvailable' => false,
1049
                ]
1050
            ),
1051
            new SPIUrlAlias(
1052
                [
1053
                    'pathData' => $pathData2,
1054
                    'languageCodes' => ['eng-GB'],
1055
                    'alwaysAvailable' => false,
1056
                ]
1057
            ),
1058
        ];
1059
        $spiUrlAliases3 = [
1060
            new SPIUrlAlias(
1061
                [
1062
                    'pathData' => $pathData3,
1063
                    'languageCodes' => ['cro-HR'],
1064
                    'alwaysAvailable' => false,
1065
                ]
1066
            ),
1067
            new SPIUrlAlias(
1068
                [
1069
                    'pathData' => $pathData3,
1070
                    'languageCodes' => ['eng-GB'],
1071
                    'alwaysAvailable' => false,
1072
                ]
1073
            ),
1074
            new SPIUrlAlias(
1075
                [
1076
                    'pathData' => $pathData3,
1077
                    'languageCodes' => ['ger-DE'],
1078
                    'alwaysAvailable' => false,
1079
                ]
1080
            ),
1081
        ];
1082
1083
        return [
1084
            [
1085
                $spiUrlAliases1,
1086
                'cro-HR',
1087
                ['cro-HR'],
1088
                [
1089
                    '/jedan',
1090
                ],
1091
            ],
1092
            [
1093
                $spiUrlAliases1,
1094
                'cro-HR',
1095
                ['eng-GB'],
1096
                [
1097
                    '/jedan',
1098
                ],
1099
            ],
1100
            [
1101
                $spiUrlAliases2,
1102
                'cro-HR',
1103
                ['cro-HR'],
1104
                [
1105
                    '/jedan/dva',
1106
                ],
1107
            ],
1108
            [
1109
                $spiUrlAliases2,
1110
                'eng-GB',
1111
                ['eng-GB'],
1112
                [
1113
                    '/jedan/two',
1114
                ],
1115
            ],
1116
            [
1117
                $spiUrlAliases2,
1118
                'eng-GB',
1119
                ['cro-HR', 'eng-GB'],
1120
                [
1121
                    '/jedan/two',
1122
                ],
1123
            ],
1124
            [
1125
                $spiUrlAliases2,
1126
                'cro-HR',
1127
                ['cro-HR', 'ger-DE'],
1128
                [
1129
                    '/jedan/dva',
1130
                ],
1131
            ],
1132
            [
1133
                $spiUrlAliases2,
1134
                'cro-HR',
1135
                ['eng-GB', 'cro-HR'],
1136
                [
1137
                    '/jedan/dva',
1138
                ],
1139
            ],
1140
            [
1141
                $spiUrlAliases2,
1142
                'eng-GB',
1143
                ['eng-GB', 'ger-DE'],
1144
                [
1145
                    '/jedan/two',
1146
                ],
1147
            ],
1148
            [
1149
                $spiUrlAliases2,
1150
                'cro-HR',
1151
                ['ger-DE', 'cro-HR'],
1152
                [
1153
                    '/jedan/dva',
1154
                ],
1155
            ],
1156
            [
1157
                $spiUrlAliases2,
1158
                'eng-GB',
1159
                ['ger-DE', 'eng-GB'],
1160
                [
1161
                    '/jedan/two',
1162
                ],
1163
            ],
1164
            [
1165
                $spiUrlAliases2,
1166
                'cro-HR',
1167
                ['cro-HR', 'eng-GB', 'ger-DE'],
1168
                [
1169
                    '/jedan/dva',
1170
                ],
1171
            ],
1172
            [
1173
                $spiUrlAliases2,
1174
                'eng-GB',
1175
                ['cro-HR', 'ger-DE', 'eng-GB'],
1176
                [
1177
                    '/jedan/two',
1178
                ],
1179
            ],
1180
            [
1181
                $spiUrlAliases2,
1182
                'cro-HR',
1183
                ['eng-GB', 'cro-HR', 'ger-DE'],
1184
                [
1185
                    '/jedan/dva',
1186
                ],
1187
            ],
1188
            [
1189
                $spiUrlAliases2,
1190
                'cro-HR',
1191
                ['eng-GB', 'ger-DE', 'cro-HR'],
1192
                [
1193
                    '/jedan/dva',
1194
                ],
1195
            ],
1196
            [
1197
                $spiUrlAliases2,
1198
                'cro-HR',
1199
                ['ger-DE', 'cro-HR', 'eng-GB'],
1200
                [
1201
                    '/jedan/dva',
1202
                ],
1203
            ],
1204
            [
1205
                $spiUrlAliases2,
1206
                'cro-HR',
1207
                ['ger-DE', 'eng-GB', 'cro-HR'],
1208
                [
1209
                    '/jedan/dva',
1210
                ],
1211
            ],
1212
            [
1213
                $spiUrlAliases3,
1214
                'cro-HR',
1215
                ['cro-HR'],
1216
                [
1217
                    '/jedan/dva/tri',
1218
                ],
1219
            ],
1220
            [
1221
                $spiUrlAliases3,
1222
                'eng-GB',
1223
                ['eng-GB'],
1224
                [
1225
                    '/jedan/two/three',
1226
                ],
1227
            ],
1228
            [
1229
                $spiUrlAliases3,
1230
                'eng-GB',
1231
                ['cro-HR', 'eng-GB'],
1232
                [
1233
                    '/jedan/dva/three',
1234
                ],
1235
            ],
1236
            [
1237
                $spiUrlAliases3,
1238
                'ger-DE',
1239
                ['cro-HR', 'ger-DE'],
1240
                [
1241
                    '/jedan/dva/drei',
1242
                ],
1243
            ],
1244
            [
1245
                $spiUrlAliases3,
1246
                'cro-HR',
1247
                ['eng-GB', 'cro-HR'],
1248
                [
1249
                    '/jedan/two/tri',
1250
                ],
1251
            ],
1252
            [
1253
                $spiUrlAliases3,
1254
                'ger-DE',
1255
                ['eng-GB', 'ger-DE'],
1256
                [
1257
                    '/jedan/two/drei',
1258
                ],
1259
            ],
1260
            [
1261
                $spiUrlAliases3,
1262
                'eng-GB',
1263
                ['ger-DE', 'eng-GB'],
1264
                [
1265
                    '/jedan/two/three',
1266
                ],
1267
            ],
1268
            [
1269
                $spiUrlAliases3,
1270
                'ger-DE',
1271
                ['ger-DE', 'cro-HR'],
1272
                [
1273
                    '/jedan/dva/drei',
1274
                ],
1275
            ],
1276
            [
1277
                $spiUrlAliases3,
1278
                'ger-DE',
1279
                ['cro-HR', 'eng-GB', 'ger-DE'],
1280
                [
1281
                    '/jedan/dva/drei',
1282
                ],
1283
            ],
1284
            [
1285
                $spiUrlAliases3,
1286
                'ger-DE',
1287
                ['cro-HR', 'ger-DE', 'eng-GB'],
1288
                [
1289
                    '/jedan/dva/drei',
1290
                ],
1291
            ],
1292
            [
1293
                $spiUrlAliases3,
1294
                'ger-DE',
1295
                ['eng-GB', 'cro-HR', 'ger-DE'],
1296
                [
1297
                    '/jedan/two/drei',
1298
                ],
1299
            ],
1300
            [
1301
                $spiUrlAliases3,
1302
                'ger-DE',
1303
                ['eng-GB', 'ger-DE', 'cro-HR'],
1304
                [
1305
                    '/jedan/two/drei',
1306
                ],
1307
            ],
1308
            [
1309
                $spiUrlAliases3,
1310
                'eng-GB',
1311
                ['ger-DE', 'cro-HR', 'eng-GB'],
1312
                [
1313
                    '/jedan/dva/three',
1314
                ],
1315
            ],
1316
            [
1317
                $spiUrlAliases3,
1318
                'cro-HR',
1319
                ['ger-DE', 'eng-GB', 'cro-HR'],
1320
                [
1321
                    '/jedan/two/tri',
1322
                ],
1323
            ],
1324
        ];
1325
    }
1326
1327
    /**
1328
     * Test for the listLocationAliases() method.
1329
     *
1330
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodePath
1331
     */
1332
    public function testListAutogeneratedLocationAliasesWithLanguageCodePath(
1333
        $spiUrlAliases,
1334
        $languageCode,
1335
        $prioritizedLanguageCodes,
1336
        $paths
1337
    ) {
1338
        $urlAliasService = $this->getRepository()->getURLAliasService();
1339
        $configuration = [
1340
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
1341
            'showAllTranslations' => false,
1342
        ];
1343
        $this->setConfiguration($urlAliasService, $configuration);
1344
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1345
        $urlAliasHandler->expects(
1346
            $this->once()
1347
        )->method(
1348
            'listURLAliasesForLocation'
1349
        )->with(
1350
            $this->equalTo(42),
1351
            $this->equalTo(false)
1352
        )->will(
1353
            $this->returnValue($spiUrlAliases)
1354
        );
1355
1356
        $location = $this->getLocationStub();
1357
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
1358
1359
        self::assertEquals(
1360
            count($paths),
1361
            count($urlAliases)
1362
        );
1363
1364
        foreach ($urlAliases as $index => $urlAlias) {
1365
            self::assertEquals(
1366
                $paths[$index],
1367
                $urlAlias->path
1368
            );
1369
        }
1370
    }
1371
1372
    /**
1373
     * Test for the listLocationAliases() method.
1374
     *
1375
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodePath
1376
     */
1377 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodePathCustomConfiguration(
1378
        $spiUrlAliases,
1379
        $languageCode,
1380
        $prioritizedLanguageCodes,
1381
        $paths
1382
    ) {
1383
        $urlAliasService = $this->getRepository()->getURLAliasService();
1384
        $configuration = [
1385
            'prioritizedLanguageList' => [],
1386
            'showAllTranslations' => false,
1387
        ];
1388
        $this->setConfiguration($urlAliasService, $configuration);
1389
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1390
        $urlAliasHandler->expects(
1391
            $this->once()
1392
        )->method(
1393
            'listURLAliasesForLocation'
1394
        )->with(
1395
            $this->equalTo(42),
1396
            $this->equalTo(false)
1397
        )->will(
1398
            $this->returnValue($spiUrlAliases)
1399
        );
1400
1401
        $location = $this->getLocationStub();
1402
        $urlAliases = $urlAliasService->listLocationAliases(
1403
            $location,
1404
            false,
1405
            $languageCode,
1406
            false,
1407
            $prioritizedLanguageCodes
1408
        );
1409
1410
        self::assertEquals(
1411
            count($paths),
1412
            count($urlAliases)
1413
        );
1414
1415
        foreach ($urlAliases as $index => $urlAlias) {
1416
            self::assertEquals(
1417
                $paths[$index],
1418
                $urlAlias->path
1419
            );
1420
        }
1421
    }
1422
1423
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodeEmpty()
1424
    {
1425
        $pathElement1 = [
1426
            'always-available' => true,
1427
            'translations' => [
1428
                'cro-HR' => '/jedan',
1429
            ],
1430
        ];
1431
        $pathElement2 = [
1432
            'always-available' => false,
1433
            'translations' => [
1434
                'cro-HR' => 'dva',
1435
                'eng-GB' => 'two',
1436
            ],
1437
        ];
1438
        $pathElement3 = [
1439
            'always-available' => false,
1440
            'translations' => [
1441
                'cro-HR' => 'tri',
1442
                'eng-GB' => 'three',
1443
                'ger-DE' => 'drei',
1444
            ],
1445
        ];
1446
        $pathData1 = [$pathElement1];
1447
        $pathData2 = [$pathElement1, $pathElement2];
1448
        $pathData3 = [$pathElement1, $pathElement2, $pathElement3];
1449
        $spiUrlAliases1 = [
1450
            new SPIUrlAlias(
1451
                [
1452
                    'pathData' => $pathData1,
1453
                    'languageCodes' => ['cro-HR'],
1454
                    'alwaysAvailable' => true,
1455
                ]
1456
            ),
1457
        ];
1458
        $spiUrlAliases2 = [
1459
            new SPIUrlAlias(
1460
                [
1461
                    'pathData' => $pathData2,
1462
                    'languageCodes' => ['cro-HR'],
1463
                    'alwaysAvailable' => false,
1464
                ]
1465
            ),
1466
            new SPIUrlAlias(
1467
                [
1468
                    'pathData' => $pathData2,
1469
                    'languageCodes' => ['eng-GB'],
1470
                    'alwaysAvailable' => false,
1471
                ]
1472
            ),
1473
        ];
1474
        $spiUrlAliases3 = [
1475
            new SPIUrlAlias(
1476
                [
1477
                    'pathData' => $pathData3,
1478
                    'languageCodes' => ['cro-HR'],
1479
                    'alwaysAvailable' => false,
1480
                ]
1481
            ),
1482
            new SPIUrlAlias(
1483
                [
1484
                    'pathData' => $pathData3,
1485
                    'languageCodes' => ['eng-GB'],
1486
                    'alwaysAvailable' => false,
1487
                ]
1488
            ),
1489
            new SPIUrlAlias(
1490
                [
1491
                    'pathData' => $pathData3,
1492
                    'languageCodes' => ['ger-DE'],
1493
                    'alwaysAvailable' => false,
1494
                ]
1495
            ),
1496
        ];
1497
1498
        return [
1499
            [
1500
                $spiUrlAliases1,
1501
                'eng-GB',
1502
                ['ger-DE'],
1503
            ],
1504
            [
1505
                $spiUrlAliases1,
1506
                'ger-DE',
1507
                ['cro-HR', 'eng-GB', 'ger-DE'],
1508
            ],
1509
            [
1510
                $spiUrlAliases2,
1511
                'eng-GB',
1512
                ['cro-HR'],
1513
            ],
1514
            [
1515
                $spiUrlAliases2,
1516
                'ger-DE',
1517
                ['cro-HR', 'eng-GB'],
1518
            ],
1519
            [
1520
                $spiUrlAliases2,
1521
                'ger-DE',
1522
                ['cro-HR', 'ger-DE'],
1523
            ],
1524
            [
1525
                $spiUrlAliases2,
1526
                'ger-DE',
1527
                ['eng-GB', 'ger-DE'],
1528
            ],
1529
            [
1530
                $spiUrlAliases2,
1531
                'ger-DE',
1532
                ['ger-DE', 'cro-HR'],
1533
            ],
1534
            [
1535
                $spiUrlAliases2,
1536
                'ger-DE',
1537
                ['ger-DE', 'eng-GB'],
1538
            ],
1539
            [
1540
                $spiUrlAliases2,
1541
                'ger-DE',
1542
                ['cro-HR', 'eng-GB', 'ger-DE'],
1543
            ],
1544
            [
1545
                $spiUrlAliases2,
1546
                'ger-DE',
1547
                ['cro-HR', 'ger-DE', 'eng-GB'],
1548
            ],
1549
            [
1550
                $spiUrlAliases2,
1551
                'ger-DE',
1552
                ['eng-GB', 'cro-HR', 'ger-DE'],
1553
            ],
1554
            [
1555
                $spiUrlAliases2,
1556
                'ger-DE',
1557
                ['eng-GB', 'ger-DE', 'cro-HR'],
1558
            ],
1559
            [
1560
                $spiUrlAliases2,
1561
                'ger-DE',
1562
                ['ger-DE', 'cro-HR', 'eng-GB'],
1563
            ],
1564
            [
1565
                $spiUrlAliases2,
1566
                'ger-DE',
1567
                ['ger-DE', 'eng-GB', 'cro-HR'],
1568
            ],
1569
            [
1570
                $spiUrlAliases3,
1571
                'ger-DE',
1572
                ['cro-HR'],
1573
            ],
1574
            [
1575
                $spiUrlAliases3,
1576
                'cro-HR',
1577
                ['eng-GB'],
1578
            ],
1579
            [
1580
                $spiUrlAliases3,
1581
                'ger-DE',
1582
                ['cro-HR', 'eng-GB'],
1583
            ],
1584
            [
1585
                $spiUrlAliases3,
1586
                'eng-GB',
1587
                ['cro-HR', 'ger-DE'],
1588
            ],
1589
            [
1590
                $spiUrlAliases3,
1591
                'ger-DE',
1592
                ['eng-GB', 'cro-HR'],
1593
            ],
1594
            [
1595
                $spiUrlAliases3,
1596
                'cro-HR',
1597
                ['eng-GB', 'ger-DE'],
1598
            ],
1599
            [
1600
                $spiUrlAliases3,
1601
                'cro-HR',
1602
                ['ger-DE', 'eng-GB'],
1603
            ],
1604
            [
1605
                $spiUrlAliases3,
1606
                'eng-GB',
1607
                ['ger-DE', 'cro-HR'],
1608
            ],
1609
        ];
1610
    }
1611
1612
    /**
1613
     * Test for the listLocationAliases() method.
1614
     *
1615
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeEmpty
1616
     */
1617 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeEmpty(
1618
        $spiUrlAliases,
1619
        $languageCode,
1620
        $prioritizedLanguageCodes
1621
    ) {
1622
        $urlAliasService = $this->getRepository()->getURLAliasService();
1623
        $configuration = [
1624
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
1625
            'showAllTranslations' => false,
1626
        ];
1627
        $this->setConfiguration($urlAliasService, $configuration);
1628
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1629
        $urlAliasHandler->expects(
1630
            $this->once()
1631
        )->method(
1632
            'listURLAliasesForLocation'
1633
        )->with(
1634
            $this->equalTo(42),
1635
            $this->equalTo(false)
1636
        )->will(
1637
            $this->returnValue($spiUrlAliases)
1638
        );
1639
1640
        $location = $this->getLocationStub();
1641
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
1642
1643
        self::assertEmpty($urlAliases);
1644
    }
1645
1646
    /**
1647
     * Test for the listLocationAliases() method.
1648
     *
1649
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeEmpty
1650
     */
1651 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeEmptyCustomConfiguration(
1652
        $spiUrlAliases,
1653
        $languageCode,
1654
        $prioritizedLanguageCodes
1655
    ) {
1656
        $urlAliasService = $this->getRepository()->getURLAliasService();
1657
        $configuration = [
1658
            'prioritizedLanguageList' => [],
1659
            'showAllTranslations' => false,
1660
        ];
1661
        $this->setConfiguration($urlAliasService, $configuration);
1662
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1663
        $urlAliasHandler->expects(
1664
            $this->once()
1665
        )->method(
1666
            'listURLAliasesForLocation'
1667
        )->with(
1668
            $this->equalTo(42),
1669
            $this->equalTo(false)
1670
        )->will(
1671
            $this->returnValue($spiUrlAliases)
1672
        );
1673
1674
        $location = $this->getLocationStub();
1675
        $urlAliases = $urlAliasService->listLocationAliases(
1676
            $location,
1677
            false,
1678
            $languageCode,
1679
            false,
1680
            $prioritizedLanguageCodes
1681
        );
1682
1683
        self::assertEmpty($urlAliases);
1684
    }
1685
1686
    public function providerForTestListAutogeneratedLocationAliasesMultipleLanguagesPath()
1687
    {
1688
        $spiUrlAliases = [
1689
            new SPIUrlAlias(
1690
                [
1691
                    'pathData' => [
1692
                        [
1693
                            'always-available' => false,
1694
                            'translations' => [
1695
                                'cro-HR' => 'jedan',
1696
                                'eng-GB' => 'jedan',
1697
                            ],
1698
                        ],
1699
                        [
1700
                            'always-available' => false,
1701
                            'translations' => [
1702
                                'eng-GB' => 'dva',
1703
                                'ger-DE' => 'dva',
1704
                            ],
1705
                        ],
1706
                    ],
1707
                    'languageCodes' => ['eng-GB', 'ger-DE'],
1708
                    'alwaysAvailable' => false,
1709
                ]
1710
            ),
1711
        ];
1712
1713
        return [
1714
            [
1715
                $spiUrlAliases,
1716
                ['cro-HR', 'ger-DE'],
1717
                [
1718
                    '/jedan/dva',
1719
                ],
1720
            ],
1721
            [
1722
                $spiUrlAliases,
1723
                ['ger-DE', 'cro-HR'],
1724
                [
1725
                    '/jedan/dva',
1726
                ],
1727
            ],
1728
            [
1729
                $spiUrlAliases,
1730
                ['eng-GB'],
1731
                [
1732
                    '/jedan/dva',
1733
                ],
1734
            ],
1735
            [
1736
                $spiUrlAliases,
1737
                ['eng-GB', 'ger-DE', 'cro-HR'],
1738
                [
1739
                    '/jedan/dva',
1740
                ],
1741
            ],
1742
        ];
1743
    }
1744
1745
    /**
1746
     * Test for the listLocationAliases() method.
1747
     *
1748
     * @dataProvider providerForTestListAutogeneratedLocationAliasesMultipleLanguagesPath
1749
     */
1750 View Code Duplication
    public function testListAutogeneratedLocationAliasesMultipleLanguagesPath($spiUrlAliases, $prioritizedLanguageCodes, $paths)
1751
    {
1752
        $urlAliasService = $this->getRepository()->getURLAliasService();
1753
        $configuration = [
1754
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
1755
            'showAllTranslations' => false,
1756
        ];
1757
        $this->setConfiguration($urlAliasService, $configuration);
1758
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1759
        $urlAliasHandler->expects(
1760
            $this->once()
1761
        )->method(
1762
            'listURLAliasesForLocation'
1763
        )->with(
1764
            $this->equalTo(42),
1765
            $this->equalTo(false)
1766
        )->will(
1767
            $this->returnValue($spiUrlAliases)
1768
        );
1769
1770
        $location = $this->getLocationStub();
1771
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
1772
1773
        self::assertEquals(
1774
            count($paths),
1775
            count($urlAliases)
1776
        );
1777
1778
        foreach ($urlAliases as $index => $urlAlias) {
1779
            self::assertEquals(
1780
                $paths[$index],
1781
                $urlAlias->path
1782
            );
1783
        }
1784
    }
1785
1786
    /**
1787
     * Test for the listLocationAliases() method.
1788
     *
1789
     * @dataProvider providerForTestListAutogeneratedLocationAliasesMultipleLanguagesPath
1790
     */
1791 View Code Duplication
    public function testListAutogeneratedLocationAliasesMultipleLanguagesPathCustomConfiguration(
1792
        $spiUrlAliases,
1793
        $prioritizedLanguageCodes,
1794
        $paths
1795
    ) {
1796
        $urlAliasService = $this->getRepository()->getURLAliasService();
1797
        $configuration = [
1798
            'prioritizedLanguageList' => [],
1799
            'showAllTranslations' => false,
1800
        ];
1801
        $this->setConfiguration($urlAliasService, $configuration);
1802
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1803
        $urlAliasHandler->expects(
1804
            $this->once()
1805
        )->method(
1806
            'listURLAliasesForLocation'
1807
        )->with(
1808
            $this->equalTo(42),
1809
            $this->equalTo(false)
1810
        )->will(
1811
            $this->returnValue($spiUrlAliases)
1812
        );
1813
1814
        $location = $this->getLocationStub();
1815
        $urlAliases = $urlAliasService->listLocationAliases(
1816
            $location,
1817
            false,
1818
            null,
1819
            false,
1820
            $prioritizedLanguageCodes
1821
        );
1822
1823
        self::assertEquals(
1824
            count($paths),
1825
            count($urlAliases)
1826
        );
1827
1828
        foreach ($urlAliases as $index => $urlAlias) {
1829
            self::assertEquals(
1830
                $paths[$index],
1831
                $urlAlias->path
1832
            );
1833
        }
1834
    }
1835
1836
    public function providerForTestListAutogeneratedLocationAliasesMultipleLanguagesEmpty()
1837
    {
1838
        $spiUrlAliases = [
1839
            new SPIUrlAlias(
1840
                [
1841
                    'pathData' => [
1842
                        [
1843
                            'always-available' => false,
1844
                            'translations' => [
1845
                                'cro-HR' => '/jedan',
1846
                                'eng-GB' => '/jedan',
1847
                            ],
1848
                        ],
1849
                        [
1850
                            'always-available' => false,
1851
                            'translations' => [
1852
                                'eng-GB' => 'dva',
1853
                                'ger-DE' => 'dva',
1854
                            ],
1855
                        ],
1856
                    ],
1857
                    'languageCodes' => ['eng-GB', 'ger-DE'],
1858
                    'alwaysAvailable' => false,
1859
                ]
1860
            ),
1861
        ];
1862
1863
        return [
1864
            [
1865
                $spiUrlAliases,
1866
                ['cro-HR'],
1867
            ],
1868
            [
1869
                $spiUrlAliases,
1870
                ['ger-DE'],
1871
            ],
1872
        ];
1873
    }
1874
1875
    /**
1876
     * Test for the listLocationAliases() method.
1877
     *
1878
     * @dataProvider providerForTestListAutogeneratedLocationAliasesMultipleLanguagesEmpty
1879
     */
1880 View Code Duplication
    public function testListAutogeneratedLocationAliasesMultipleLanguagesEmpty($spiUrlAliases, $prioritizedLanguageCodes)
1881
    {
1882
        $urlAliasService = $this->getRepository()->getURLAliasService();
1883
        $configuration = [
1884
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
1885
            'showAllTranslations' => false,
1886
        ];
1887
        $this->setConfiguration($urlAliasService, $configuration);
1888
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1889
        $urlAliasHandler->expects(
1890
            $this->once()
1891
        )->method(
1892
            'listURLAliasesForLocation'
1893
        )->with(
1894
            $this->equalTo(42),
1895
            $this->equalTo(false)
1896
        )->will(
1897
            $this->returnValue($spiUrlAliases)
1898
        );
1899
1900
        $location = $this->getLocationStub();
1901
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
1902
1903
        self::assertEmpty($urlAliases);
1904
    }
1905
1906
    /**
1907
     * Test for the listLocationAliases() method.
1908
     *
1909
     * @dataProvider providerForTestListAutogeneratedLocationAliasesMultipleLanguagesEmpty
1910
     */
1911 View Code Duplication
    public function testListAutogeneratedLocationAliasesMultipleLanguagesEmptyCustomConfiguration(
1912
        $spiUrlAliases,
1913
        $prioritizedLanguageCodes
1914
    ) {
1915
        $urlAliasService = $this->getRepository()->getURLAliasService();
1916
        $configuration = [
1917
            'prioritizedLanguageList' => [],
1918
            'showAllTranslations' => false,
1919
        ];
1920
        $this->setConfiguration($urlAliasService, $configuration);
1921
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
1922
        $urlAliasHandler->expects(
1923
            $this->once()
1924
        )->method(
1925
            'listURLAliasesForLocation'
1926
        )->with(
1927
            $this->equalTo(42),
1928
            $this->equalTo(false)
1929
        )->will(
1930
            $this->returnValue($spiUrlAliases)
1931
        );
1932
1933
        $location = $this->getLocationStub();
1934
        $urlAliases = $urlAliasService->listLocationAliases(
1935
            $location,
1936
            false,
1937
            null,
1938
            false,
1939
            $prioritizedLanguageCodes
1940
        );
1941
1942
        self::assertEmpty($urlAliases);
1943
    }
1944
1945
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesPath()
1946
    {
1947
        $spiUrlAliases = [
1948
            new SPIUrlAlias(
1949
                [
1950
                    'pathData' => [
1951
                        [
1952
                            'always-available' => false,
1953
                            'translations' => [
1954
                                'cro-HR' => 'jedan',
1955
                                'eng-GB' => 'jedan',
1956
                            ],
1957
                        ],
1958
                        [
1959
                            'always-available' => false,
1960
                            'translations' => [
1961
                                'eng-GB' => 'dva',
1962
                                'ger-DE' => 'dva',
1963
                            ],
1964
                        ],
1965
                    ],
1966
                    'languageCodes' => ['eng-GB', 'ger-DE'],
1967
                    'alwaysAvailable' => false,
1968
                ]
1969
            ),
1970
        ];
1971
1972
        return [
1973
            [
1974
                $spiUrlAliases,
1975
                'ger-DE',
1976
                ['cro-HR', 'ger-DE'],
1977
                [
1978
                    '/jedan/dva',
1979
                ],
1980
            ],
1981
            [
1982
                $spiUrlAliases,
1983
                'ger-DE',
1984
                ['ger-DE', 'cro-HR'],
1985
                [
1986
                    '/jedan/dva',
1987
                ],
1988
            ],
1989
            [
1990
                $spiUrlAliases,
1991
                'eng-GB',
1992
                ['eng-GB'],
1993
                [
1994
                    '/jedan/dva',
1995
                ],
1996
            ],
1997
            [
1998
                $spiUrlAliases,
1999
                'eng-GB',
2000
                ['eng-GB', 'ger-DE', 'cro-HR'],
2001
                [
2002
                    '/jedan/dva',
2003
                ],
2004
            ],
2005
        ];
2006
    }
2007
2008
    /**
2009
     * Test for the listLocationAliases() method.
2010
     *
2011
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesPath
2012
     */
2013
    public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesPath(
2014
        $spiUrlAliases,
2015
        $languageCode,
2016
        $prioritizedLanguageCodes,
2017
        $paths
2018
    ) {
2019
        $urlAliasService = $this->getRepository()->getURLAliasService();
2020
        $configuration = [
2021
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
2022
            'showAllTranslations' => false,
2023
        ];
2024
        $this->setConfiguration($urlAliasService, $configuration);
2025
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2026
        $urlAliasHandler->expects(
2027
            $this->once()
2028
        )->method(
2029
            'listURLAliasesForLocation'
2030
        )->with(
2031
            $this->equalTo(42),
2032
            $this->equalTo(false)
2033
        )->will(
2034
            $this->returnValue($spiUrlAliases)
2035
        );
2036
2037
        $location = $this->getLocationStub();
2038
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
2039
2040
        self::assertEquals(
2041
            count($paths),
2042
            count($urlAliases)
2043
        );
2044
2045
        foreach ($urlAliases as $index => $urlAlias) {
2046
            self::assertEquals(
2047
                $paths[$index],
2048
                $urlAlias->path
2049
            );
2050
        }
2051
    }
2052
2053
    /**
2054
     * Test for the listLocationAliases() method.
2055
     *
2056
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesPath
2057
     */
2058 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesPathCustomConfiguration(
2059
        $spiUrlAliases,
2060
        $languageCode,
2061
        $prioritizedLanguageCodes,
2062
        $paths
2063
    ) {
2064
        $urlAliasService = $this->getRepository()->getURLAliasService();
2065
        $configuration = [
2066
            'prioritizedLanguageList' => [],
2067
            'showAllTranslations' => false,
2068
        ];
2069
        $this->setConfiguration($urlAliasService, $configuration);
2070
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2071
        $urlAliasHandler->expects(
2072
            $this->once()
2073
        )->method(
2074
            'listURLAliasesForLocation'
2075
        )->with(
2076
            $this->equalTo(42),
2077
            $this->equalTo(false)
2078
        )->will(
2079
            $this->returnValue($spiUrlAliases)
2080
        );
2081
2082
        $location = $this->getLocationStub();
2083
        $urlAliases = $urlAliasService->listLocationAliases(
2084
            $location,
2085
            false,
2086
            $languageCode,
2087
            false,
2088
            $prioritizedLanguageCodes
2089
        );
2090
2091
        self::assertEquals(
2092
            count($paths),
2093
            count($urlAliases)
2094
        );
2095
2096
        foreach ($urlAliases as $index => $urlAlias) {
2097
            self::assertEquals(
2098
                $paths[$index],
2099
                $urlAlias->path
2100
            );
2101
        }
2102
    }
2103
2104
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesEmpty()
2105
    {
2106
        $spiUrlAliases = [
2107
            new SPIUrlAlias(
2108
                [
2109
                    'pathData' => [
2110
                        [
2111
                            'always-available' => false,
2112
                            'translations' => [
2113
                                'cro-HR' => '/jedan',
2114
                                'eng-GB' => '/jedan',
2115
                            ],
2116
                        ],
2117
                        [
2118
                            'always-available' => false,
2119
                            'translations' => [
2120
                                'eng-GB' => 'dva',
2121
                                'ger-DE' => 'dva',
2122
                            ],
2123
                        ],
2124
                    ],
2125
                    'languageCodes' => ['eng-GB', 'ger-DE'],
2126
                    'alwaysAvailable' => false,
2127
                ]
2128
            ),
2129
        ];
2130
2131
        return [
2132
            [
2133
                $spiUrlAliases,
2134
                'cro-HR',
2135
                ['cro-HR'],
2136
            ],
2137
            [
2138
                $spiUrlAliases,
2139
                'cro-HR',
2140
                ['cro-HR', 'eng-GB'],
2141
            ],
2142
            [
2143
                $spiUrlAliases,
2144
                'cro-HR',
2145
                ['ger-DE'],
2146
            ],
2147
            [
2148
                $spiUrlAliases,
2149
                'cro-HR',
2150
                ['cro-HR', 'eng-GB', 'ger-DE'],
2151
            ],
2152
        ];
2153
    }
2154
2155
    /**
2156
     * Test for the listLocationAliases() method.
2157
     *
2158
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesEmpty
2159
     */
2160 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesEmpty(
2161
        $spiUrlAliases,
2162
        $languageCode,
2163
        $prioritizedLanguageCodes
2164
    ) {
2165
        $urlAliasService = $this->getRepository()->getURLAliasService();
2166
        $configuration = [
2167
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
2168
            'showAllTranslations' => false,
2169
        ];
2170
        $this->setConfiguration($urlAliasService, $configuration);
2171
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2172
        $urlAliasHandler->expects(
2173
            $this->once()
2174
        )->method(
2175
            'listURLAliasesForLocation'
2176
        )->with(
2177
            $this->equalTo(42),
2178
            $this->equalTo(false)
2179
        )->will(
2180
            $this->returnValue($spiUrlAliases)
2181
        );
2182
2183
        $location = $this->getLocationStub();
2184
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
2185
2186
        self::assertEmpty($urlAliases);
2187
    }
2188
2189
    /**
2190
     * Test for the listLocationAliases() method.
2191
     *
2192
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesEmpty
2193
     */
2194 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLanguagesEmptyCustomConfiguration(
2195
        $spiUrlAliases,
2196
        $languageCode,
2197
        $prioritizedLanguageCodes
2198
    ) {
2199
        $urlAliasService = $this->getRepository()->getURLAliasService();
2200
        $configuration = [
2201
            'prioritizedLanguageList' => [],
2202
            'showAllTranslations' => false,
2203
        ];
2204
        $this->setConfiguration($urlAliasService, $configuration);
2205
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2206
        $urlAliasHandler->expects(
2207
            $this->once()
2208
        )->method(
2209
            'listURLAliasesForLocation'
2210
        )->with(
2211
            $this->equalTo(42),
2212
            $this->equalTo(false)
2213
        )->will(
2214
            $this->returnValue($spiUrlAliases)
2215
        );
2216
2217
        $location = $this->getLocationStub();
2218
        $urlAliases = $urlAliasService->listLocationAliases(
2219
            $location,
2220
            false,
2221
            $languageCode,
2222
            false,
2223
            $prioritizedLanguageCodes
2224
        );
2225
2226
        self::assertEmpty($urlAliases);
2227
    }
2228
2229
    public function providerForTestListAutogeneratedLocationAliasesAlwaysAvailablePath()
2230
    {
2231
        $spiUrlAliases = [
2232
            new SPIUrlAlias(
2233
                [
2234
                    'pathData' => [
2235
                        [
2236
                            'always-available' => false,
2237
                            'translations' => [
2238
                                'cro-HR' => 'jedan',
2239
                                'eng-GB' => 'one',
2240
                            ],
2241
                        ],
2242
                        [
2243
                            'always-available' => true,
2244
                            'translations' => [
2245
                                'ger-DE' => 'zwei',
2246
                            ],
2247
                        ],
2248
                    ],
2249
                    'languageCodes' => ['ger-DE'],
2250
                    'alwaysAvailable' => true,
2251
                ]
2252
            ),
2253
        ];
2254
2255
        return [
2256
            [
2257
                $spiUrlAliases,
2258
                ['cro-HR', 'ger-DE'],
2259
                [
2260
                    '/jedan/zwei',
2261
                ],
2262
            ],
2263
            [
2264
                $spiUrlAliases,
2265
                ['ger-DE', 'cro-HR'],
2266
                [
2267
                    '/jedan/zwei',
2268
                ],
2269
            ],
2270
            [
2271
                $spiUrlAliases,
2272
                ['eng-GB'],
2273
                [
2274
                    '/one/zwei',
2275
                ],
2276
            ],
2277
            [
2278
                $spiUrlAliases,
2279
                ['cro-HR', 'eng-GB', 'ger-DE'],
2280
                [
2281
                    '/jedan/zwei',
2282
                ],
2283
            ],
2284
            [
2285
                $spiUrlAliases,
2286
                ['eng-GB', 'ger-DE', 'cro-HR'],
2287
                [
2288
                    '/one/zwei',
2289
                ],
2290
            ],
2291
        ];
2292
    }
2293
2294
    /**
2295
     * Test for the listLocationAliases() method.
2296
     *
2297
     * @dataProvider providerForTestListAutogeneratedLocationAliasesAlwaysAvailablePath
2298
     */
2299 View Code Duplication
    public function testListAutogeneratedLocationAliasesAlwaysAvailablePath(
2300
        $spiUrlAliases,
2301
        $prioritizedLanguageCodes,
2302
        $paths
2303
    ) {
2304
        $urlAliasService = $this->getRepository()->getURLAliasService();
2305
        $configuration = [
2306
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
2307
            'showAllTranslations' => false,
2308
        ];
2309
        $this->setConfiguration($urlAliasService, $configuration);
2310
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2311
        $urlAliasHandler->expects(
2312
            $this->once()
2313
        )->method(
2314
            'listURLAliasesForLocation'
2315
        )->with(
2316
            $this->equalTo(42),
2317
            $this->equalTo(false)
2318
        )->will(
2319
            $this->returnValue($spiUrlAliases)
2320
        );
2321
2322
        $location = $this->getLocationStub();
2323
        $urlAliases = $urlAliasService->listLocationAliases($location, false, null);
2324
2325
        self::assertEquals(
2326
            count($paths),
2327
            count($urlAliases)
2328
        );
2329
2330
        foreach ($urlAliases as $index => $urlAlias) {
2331
            self::assertEquals(
2332
                $paths[$index],
2333
                $urlAlias->path
2334
            );
2335
        }
2336
    }
2337
2338
    /**
2339
     * Test for the listLocationAliases() method.
2340
     *
2341
     * @dataProvider providerForTestListAutogeneratedLocationAliasesAlwaysAvailablePath
2342
     */
2343 View Code Duplication
    public function testListAutogeneratedLocationAliasesAlwaysAvailablePathCustomConfiguration(
2344
        $spiUrlAliases,
2345
        $prioritizedLanguageCodes,
2346
        $paths
2347
    ) {
2348
        $urlAliasService = $this->getRepository()->getURLAliasService();
2349
        $configuration = [
2350
            'prioritizedLanguageList' => [],
2351
            'showAllTranslations' => false,
2352
        ];
2353
        $this->setConfiguration($urlAliasService, $configuration);
2354
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2355
        $urlAliasHandler->expects(
2356
            $this->once()
2357
        )->method(
2358
            'listURLAliasesForLocation'
2359
        )->with(
2360
            $this->equalTo(42),
2361
            $this->equalTo(false)
2362
        )->will(
2363
            $this->returnValue($spiUrlAliases)
2364
        );
2365
2366
        $location = $this->getLocationStub();
2367
        $urlAliases = $urlAliasService->listLocationAliases(
2368
            $location,
2369
            false,
2370
            null,
2371
            false,
2372
            $prioritizedLanguageCodes
2373
        );
2374
2375
        self::assertEquals(
2376
            count($paths),
2377
            count($urlAliases)
2378
        );
2379
2380
        foreach ($urlAliases as $index => $urlAlias) {
2381
            self::assertEquals(
2382
                $paths[$index],
2383
                $urlAlias->path
2384
            );
2385
        }
2386
    }
2387
2388
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailablePath()
2389
    {
2390
        $spiUrlAliases = [
2391
            new SPIUrlAlias(
2392
                [
2393
                    'pathData' => [
2394
                        [
2395
                            'always-available' => false,
2396
                            'translations' => [
2397
                                'cro-HR' => 'jedan',
2398
                                'eng-GB' => 'one',
2399
                            ],
2400
                        ],
2401
                        [
2402
                            'always-available' => true,
2403
                            'translations' => [
2404
                                'ger-DE' => 'zwei',
2405
                            ],
2406
                        ],
2407
                    ],
2408
                    'languageCodes' => ['ger-DE'],
2409
                    'alwaysAvailable' => true,
2410
                ]
2411
            ),
2412
        ];
2413
2414
        return [
2415
            [
2416
                $spiUrlAliases,
2417
                'ger-DE',
2418
                ['cro-HR', 'ger-DE'],
2419
                [
2420
                    '/jedan/zwei',
2421
                ],
2422
            ],
2423
            [
2424
                $spiUrlAliases,
2425
                'ger-DE',
2426
                ['ger-DE', 'cro-HR'],
2427
                [
2428
                    '/jedan/zwei',
2429
                ],
2430
            ],
2431
        ];
2432
    }
2433
2434
    /**
2435
     * Test for the listLocationAliases() method.
2436
     *
2437
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailablePath
2438
     */
2439
    public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailablePath(
2440
        $spiUrlAliases,
2441
        $languageCode,
2442
        $prioritizedLanguageCodes,
2443
        $paths
2444
    ) {
2445
        $urlAliasService = $this->getRepository()->getURLAliasService();
2446
        $configuration = [
2447
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
2448
            'showAllTranslations' => false,
2449
        ];
2450
        $this->setConfiguration($urlAliasService, $configuration);
2451
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2452
        $urlAliasHandler->expects(
2453
            $this->once()
2454
        )->method(
2455
            'listURLAliasesForLocation'
2456
        )->with(
2457
            $this->equalTo(42),
2458
            $this->equalTo(false)
2459
        )->will(
2460
            $this->returnValue($spiUrlAliases)
2461
        );
2462
2463
        $location = $this->getLocationStub();
2464
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
2465
2466
        self::assertEquals(
2467
            count($paths),
2468
            count($urlAliases)
2469
        );
2470
2471
        foreach ($urlAliases as $index => $urlAlias) {
2472
            self::assertEquals(
2473
                $paths[$index],
2474
                $urlAlias->path
2475
            );
2476
        }
2477
    }
2478
2479
    /**
2480
     * Test for the listLocationAliases() method.
2481
     *
2482
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailablePath
2483
     */
2484 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailablePathCustomConfiguration(
2485
        $spiUrlAliases,
2486
        $languageCode,
2487
        $prioritizedLanguageCodes,
2488
        $paths
2489
    ) {
2490
        $urlAliasService = $this->getRepository()->getURLAliasService();
2491
        $configuration = [
2492
            'prioritizedLanguageList' => [],
2493
            'showAllTranslations' => false,
2494
        ];
2495
        $this->setConfiguration($urlAliasService, $configuration);
2496
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2497
        $urlAliasHandler->expects(
2498
            $this->once()
2499
        )->method(
2500
            'listURLAliasesForLocation'
2501
        )->with(
2502
            $this->equalTo(42),
2503
            $this->equalTo(false)
2504
        )->will(
2505
            $this->returnValue($spiUrlAliases)
2506
        );
2507
2508
        $location = $this->getLocationStub();
2509
        $urlAliases = $urlAliasService->listLocationAliases(
2510
            $location,
2511
            false,
2512
            $languageCode,
2513
            false,
2514
            $prioritizedLanguageCodes
2515
        );
2516
2517
        self::assertEquals(
2518
            count($paths),
2519
            count($urlAliases)
2520
        );
2521
2522
        foreach ($urlAliases as $index => $urlAlias) {
2523
            self::assertEquals(
2524
                $paths[$index],
2525
                $urlAlias->path
2526
            );
2527
        }
2528
    }
2529
2530
    public function providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailableEmpty()
2531
    {
2532
        $spiUrlAliases = [
2533
            new SPIUrlAlias(
2534
                [
2535
                    'pathData' => [
2536
                        [
2537
                            'always-available' => false,
2538
                            'translations' => [
2539
                                'cro-HR' => 'jedan',
2540
                                'eng-GB' => 'one',
2541
                            ],
2542
                        ],
2543
                        [
2544
                            'always-available' => true,
2545
                            'translations' => [
2546
                                'ger-DE' => 'zwei',
2547
                            ],
2548
                        ],
2549
                    ],
2550
                    'languageCodes' => ['ger-DE'],
2551
                    'alwaysAvailable' => true,
2552
                ]
2553
            ),
2554
        ];
2555
2556
        return [
2557
            [
2558
                $spiUrlAliases,
2559
                'eng-GB',
2560
                ['eng-GB'],
2561
            ],
2562
            [
2563
                $spiUrlAliases,
2564
                'eng-GB',
2565
                ['cro-HR', 'eng-GB', 'ger-DE'],
2566
            ],
2567
            [
2568
                $spiUrlAliases,
2569
                'eng-GB',
2570
                ['eng-GB', 'ger-DE', 'cro-HR'],
2571
            ],
2572
        ];
2573
    }
2574
2575
    /**
2576
     * Test for the listLocationAliases() method.
2577
     *
2578
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailableEmpty
2579
     */
2580 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailableEmpty(
2581
        $spiUrlAliases,
2582
        $languageCode,
2583
        $prioritizedLanguageCodes
2584
    ) {
2585
        $urlAliasService = $this->getRepository()->getURLAliasService();
2586
        $configuration = [
2587
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
2588
            'showAllTranslations' => false,
2589
        ];
2590
        $this->setConfiguration($urlAliasService, $configuration);
2591
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2592
        $urlAliasHandler->expects(
2593
            $this->once()
2594
        )->method(
2595
            'listURLAliasesForLocation'
2596
        )->with(
2597
            $this->equalTo(42),
2598
            $this->equalTo(false)
2599
        )->will(
2600
            $this->returnValue($spiUrlAliases)
2601
        );
2602
2603
        $location = $this->getLocationStub();
2604
        $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
2605
2606
        self::assertEmpty($urlAliases);
2607
    }
2608
2609
    /**
2610
     * Test for the listLocationAliases() method.
2611
     *
2612
     * @dataProvider providerForTestListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailableEmpty
2613
     */
2614 View Code Duplication
    public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvailableEmptyCustomConfiguration(
2615
        $spiUrlAliases,
2616
        $languageCode,
2617
        $prioritizedLanguageCodes
2618
    ) {
2619
        $urlAliasService = $this->getRepository()->getURLAliasService();
2620
        $configuration = [
2621
            'prioritizedLanguageList' => [],
2622
            'showAllTranslations' => false,
2623
        ];
2624
        $this->setConfiguration($urlAliasService, $configuration);
2625
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2626
        $urlAliasHandler->expects(
2627
            $this->once()
2628
        )->method(
2629
            'listURLAliasesForLocation'
2630
        )->with(
2631
            $this->equalTo(42),
2632
            $this->equalTo(false)
2633
        )->will(
2634
            $this->returnValue($spiUrlAliases)
2635
        );
2636
2637
        $location = $this->getLocationStub();
2638
        $urlAliases = $urlAliasService->listLocationAliases(
2639
            $location,
2640
            false,
2641
            $languageCode,
2642
            false,
2643
            $prioritizedLanguageCodes
2644
        );
2645
2646
        self::assertEmpty($urlAliases);
2647
    }
2648
2649
    /**
2650
     * Test for the listGlobalAliases() method.
2651
     */
2652 View Code Duplication
    public function testListGlobalAliases()
2653
    {
2654
        $urlAliasService = $this->getRepository()->getURLAliasService();
2655
        $configuration = [
2656
            'prioritizedLanguageList' => ['ger-DE'],
2657
            'showAllTranslations' => true,
2658
        ];
2659
        $this->setConfiguration($urlAliasService, $configuration);
2660
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2661
2662
        $urlAliasHandler->expects(
2663
            $this->once()
2664
        )->method(
2665
            'listGlobalURLAliases'
2666
        )->with(
2667
            $this->equalTo(null),
2668
            $this->equalTo(0),
2669
            $this->equalTo(-1)
2670
        )->will(
2671
            $this->returnValue(
2672
                [
2673
                    new SPIUrlAlias(
2674
                        [
2675
                            'pathData' => [
2676
                                [
2677
                                    'always-available' => true,
2678
                                    'translations' => [
2679
                                        'ger-DE' => 'squirrel',
2680
                                    ],
2681
                                ],
2682
                            ],
2683
                            'languageCodes' => ['ger-DE'],
2684
                            'alwaysAvailable' => true,
2685
                        ]
2686
                    ),
2687
                ]
2688
            )
2689
        );
2690
2691
        $urlAliases = $urlAliasService->listGlobalAliases();
2692
2693
        self::assertCount(1, $urlAliases);
2694
        self::assertInstanceOf(
2695
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
2696
            $urlAliases[0]
2697
        );
2698
    }
2699
2700
    /**
2701
     * Test for the listGlobalAliases() method.
2702
     */
2703 View Code Duplication
    public function testListGlobalAliasesEmpty()
2704
    {
2705
        $urlAliasService = $this->getRepository()->getURLAliasService();
2706
        $configuration = [
2707
            'prioritizedLanguageList' => ['eng-GB'],
2708
            'showAllTranslations' => false,
2709
        ];
2710
        $this->setConfiguration($urlAliasService, $configuration);
2711
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2712
2713
        $urlAliasHandler->expects(
2714
            $this->once()
2715
        )->method(
2716
            'listGlobalURLAliases'
2717
        )->with(
2718
            $this->equalTo(null),
2719
            $this->equalTo(0),
2720
            $this->equalTo(-1)
2721
        )->will(
2722
            $this->returnValue(
2723
                [
2724
                    new SPIUrlAlias(
2725
                        [
2726
                            'pathData' => [
2727
                                [
2728
                                    'always-available' => false,
2729
                                    'translations' => [
2730
                                        'ger-DE' => 'squirrel',
2731
                                    ],
2732
                                ],
2733
                            ],
2734
                            'languageCodes' => ['ger-DE'],
2735
                            'alwaysAvailable' => false,
2736
                        ]
2737
                    ),
2738
                ]
2739
            )
2740
        );
2741
2742
        $urlAliases = $urlAliasService->listGlobalAliases();
2743
2744
        self::assertCount(0, $urlAliases);
2745
    }
2746
2747
    /**
2748
     * Test for the listGlobalAliases() method.
2749
     */
2750
    public function testListGlobalAliasesWithParameters()
2751
    {
2752
        $urlAliasService = $this->getRepository()->getURLAliasService();
2753
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2754
2755
        $urlAliasHandler->expects(
2756
            $this->once()
2757
        )->method(
2758
            'listGlobalURLAliases'
2759
        )->with(
2760
            $this->equalTo('languageCode'),
2761
            $this->equalTo('offset'),
2762
            $this->equalTo('limit')
2763
        )->will(
2764
            $this->returnValue([])
2765
        );
2766
2767
        $urlAliases = $urlAliasService->listGlobalAliases('languageCode', 'offset', 'limit');
2768
2769
        self::assertEmpty($urlAliases);
2770
    }
2771
2772
    /**
2773
     * Test for the lookup() method.
2774
     *
2775
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2776
     */
2777
    public function testLookupThrowsNotFoundException()
2778
    {
2779
        $urlAliasService = $this->getRepository()->getURLAliasService();
2780
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2781
2782
        $urlAliasHandler->expects(
2783
            $this->once()
2784
        )->method(
2785
            'lookup'
2786
        )->with(
2787
            $this->equalTo('url')
2788
        )->will(
2789
            $this->throwException(new NotFoundException('UrlAlias', 'url'))
2790
        );
2791
2792
        $urlAliasService->lookup('url');
2793
    }
2794
2795
    public function providerForTestLookupThrowsNotFoundExceptionPath()
2796
    {
2797
        return [
2798
            // alias does not exist in requested language
2799
            ['ein/dva', ['cro-HR', 'ger-DE'], 'ger-DE'],
2800
            // alias exists in requested language but the language is not in prioritized languages list
2801
            ['ein/dva', ['ger-DE'], 'eng-GB'],
2802
            // alias path is not matched
2803
            ['jedan/dva', ['cro-HR', 'ger-DE'], 'cro-HR'],
2804
            // path is not loadable for prioritized languages list
2805
            ['ein/dva', ['cro-HR'], 'cro-HR'],
2806
        ];
2807
    }
2808
2809
    /**
2810
     * Test for the lookup() method.
2811
     *
2812
     * @dataProvider providerForTestLookupThrowsNotFoundExceptionPath
2813
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2814
     */
2815
    public function testLookupThrowsNotFoundExceptionPathNotMatchedOrNotLoadable($url, $prioritizedLanguageList, $languageCode)
2816
    {
2817
        $urlAliasService = $this->getRepository()->getURLAliasService();
2818
        $configuration = [
2819
            'prioritizedLanguageList' => $prioritizedLanguageList,
2820
            'showAllTranslations' => false,
2821
        ];
2822
        $this->setConfiguration($urlAliasService, $configuration);
2823
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2824
2825
        $urlAliasHandler->expects(
2826
            $this->once()
2827
        )->method(
2828
            'lookup'
2829
        )->with(
2830
            $this->equalTo($url)
2831
        )->will(
2832
            $this->returnValue(
2833
                new SPIUrlAlias(
2834
                    [
2835
                        'pathData' => [
2836
                            [
2837
                                'always-available' => false,
2838
                                'translations' => ['ger-DE' => 'ein'],
2839
                            ],
2840
                            [
2841
                                'always-available' => false,
2842
                                'translations' => [
2843
                                    'cro-HR' => 'dva',
2844
                                    'eng-GB' => 'two',
2845
                                ],
2846
                            ],
2847
                        ],
2848
                        'languageCodes' => ['eng-GB', 'cro-HR'],
2849
                        'alwaysAvailable' => false,
2850
                    ]
2851
                )
2852
            )
2853
        );
2854
2855
        $urlAliasService->lookup($url, $languageCode);
2856
    }
2857
2858
    public function providerForTestLookup()
2859
    {
2860
        return [
2861
            // showAllTranslations setting is true
2862
            [['ger-DE'], true, false, null],
2863
            // alias is always available
2864
            [['ger-DE'], false, true, null],
2865
            // works with available language code
2866
            [['cro-HR'], false, false, 'eng-GB'],
2867
        ];
2868
    }
2869
2870
    /**
2871
     * Test for the lookup() method.
2872
     *
2873
     * @dataProvider providerForTestLookup
2874
     */
2875 View Code Duplication
    public function testLookup($prioritizedLanguageList, $showAllTranslations, $alwaysAvailable, $languageCode)
2876
    {
2877
        $urlAliasService = $this->getRepository()->getURLAliasService();
2878
        $configuration = [
2879
            'prioritizedLanguageList' => $prioritizedLanguageList,
2880
            'showAllTranslations' => $showAllTranslations,
2881
        ];
2882
        $this->setConfiguration($urlAliasService, $configuration);
2883
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2884
2885
        $urlAliasHandler->expects(
2886
            $this->once()
2887
        )->method(
2888
            'lookup'
2889
        )->with(
2890
            $this->equalTo('jedan/dva')
2891
        )->will(
2892
            $this->returnValue(
2893
                new SPIUrlAlias(
2894
                    [
2895
                        'pathData' => [
2896
                            [
2897
                                'always-available' => $alwaysAvailable,
2898
                                'translations' => ['cro-HR' => 'jedan'],
2899
                            ],
2900
                            [
2901
                                'always-available' => $alwaysAvailable,
2902
                                'translations' => [
2903
                                    'cro-HR' => 'dva',
2904
                                    'eng-GB' => 'two',
2905
                                ],
2906
                            ],
2907
                        ],
2908
                        'languageCodes' => ['eng-GB', 'cro-HR'],
2909
                        'alwaysAvailable' => $alwaysAvailable,
2910
                    ]
2911
                )
2912
            )
2913
        );
2914
2915
        $urlAlias = $urlAliasService->lookup('jedan/dva', $languageCode);
2916
2917
        self::assertInstanceOf(
2918
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
2919
            $urlAlias
2920
        );
2921
    }
2922
2923
    public function providerForTestLookupWithSharedTranslation()
2924
    {
2925
        return [
2926
            // showAllTranslations setting is true
2927
            [['ger-DE'], true, false, null],
2928
            // alias is always available
2929
            [['ger-DE'], false, true, null],
2930
            // works with available language codes
2931
            [['cro-HR'], false, false, 'eng-GB'],
2932
            [['eng-GB'], false, false, 'cro-HR'],
2933
            // works with cro-HR only
2934
            [['cro-HR'], false, false, null],
2935
            // works with eng-GB only
2936
            [['eng-GB'], false, false, null],
2937
            // works with cro-HR first
2938
            [['cro-HR', 'eng-GB'], false, false, null],
2939
            // works with eng-GB first
2940
            [['eng-GB', 'cro-HR'], false, false, null],
2941
        ];
2942
    }
2943
2944
    /**
2945
     * Test for the lookup() method.
2946
     *
2947
     * @dataProvider providerForTestLookupWithSharedTranslation
2948
     */
2949 View Code Duplication
    public function testLookupWithSharedTranslation(
2950
        $prioritizedLanguageList,
2951
        $showAllTranslations,
2952
        $alwaysAvailable,
2953
        $languageCode
2954
    ) {
2955
        $urlAliasService = $this->getRepository()->getURLAliasService();
2956
        $configuration = [
2957
            'prioritizedLanguageList' => $prioritizedLanguageList,
2958
            'showAllTranslations' => $showAllTranslations,
2959
        ];
2960
        $this->setConfiguration($urlAliasService, $configuration);
2961
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
2962
2963
        $urlAliasHandler->expects(
2964
            $this->once()
2965
        )->method(
2966
            'lookup'
2967
        )->with(
2968
            $this->equalTo('jedan/two')
2969
        )->will(
2970
            $this->returnValue(
2971
                new SPIUrlAlias(
2972
                    [
2973
                        'pathData' => [
2974
                            [
2975
                                'always-available' => $alwaysAvailable,
2976
                                'translations' => [
2977
                                    'cro-HR' => 'jedan',
2978
                                    'eng-GB' => 'jedan',
2979
                                ],
2980
                            ],
2981
                            [
2982
                                'always-available' => $alwaysAvailable,
2983
                                'translations' => [
2984
                                    'cro-HR' => 'two',
2985
                                    'eng-GB' => 'two',
2986
                                ],
2987
                            ],
2988
                        ],
2989
                        'languageCodes' => ['eng-GB', 'cro-HR'],
2990
                        'alwaysAvailable' => $alwaysAvailable,
2991
                    ]
2992
                )
2993
            )
2994
        );
2995
2996
        $urlAlias = $urlAliasService->lookup('jedan/two', $languageCode);
2997
2998
        self::assertInstanceOf(
2999
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
3000
            $urlAlias
3001
        );
3002
    }
3003
3004
    /**
3005
     * Test for the reverseLookup() method.
3006
     *
3007
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3008
     */
3009
    public function testReverseLookupCustomConfiguration()
3010
    {
3011
        $mockedService = $this->getPartlyMockedURLAliasServiceService(['listLocationAliases']);
3012
        $location = $this->getLocationStub();
3013
        $mockedService->expects(
3014
            $this->once()
3015
        )->method(
3016
            'listLocationAliases'
3017
        )->with(
3018
            $this->equalTo($location),
3019
            $this->equalTo(false),
3020
            $this->equalTo(null),
3021
            $this->equalTo($showAllTranslations = 'HELLO!'),
3022
            $this->equalTo($prioritizedLanguageList = ['LANGUAGES!'])
3023
        )->will(
3024
            $this->returnValue([])
3025
        );
3026
3027
        $mockedService->reverseLookup($location, null, $showAllTranslations, $prioritizedLanguageList);
3028
    }
3029
3030
    /**
3031
     * Test for the reverseLookup() method.
3032
     *
3033
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3034
     */
3035
    public function testReverseLookupThrowsNotFoundException()
3036
    {
3037
        $mockedService = $this->getPartlyMockedURLAliasServiceService(['listLocationAliases']);
3038
        $configuration = [
3039
            'prioritizedLanguageList' => ['ger-DE'],
3040
            'showAllTranslations' => false,
3041
        ];
3042
        $this->setConfiguration($mockedService, $configuration);
3043
3044
        $languageCode = 'eng-GB';
3045
        $location = $this->getLocationStub();
3046
3047
        $mockedService->expects(
3048
            $this->once()
3049
        )->method(
3050
            'listLocationAliases'
3051
        )->with(
3052
            $this->equalTo($location),
3053
            $this->equalTo(false),
3054
            $this->equalTo($languageCode)
3055
        )->will(
3056
            $this->returnValue(
3057
                [
3058
                    new UrlAlias(
3059
                        [
3060
                            'languageCodes' => ['eng-GB'],
3061
                            'alwaysAvailable' => false,
3062
                        ]
3063
                    ),
3064
                ]
3065
            )
3066
        );
3067
3068
        $mockedService->reverseLookup($location, $languageCode);
3069
    }
3070
3071
    public function providerForTestReverseLookup()
3072
    {
3073
        return $this->providerForTestListAutogeneratedLocationAliasesPath();
3074
    }
3075
3076
    /**
3077
     * Test for the reverseLookup() method.
3078
     *
3079
     * @dataProvider providerForTestReverseLookup
3080
     */
3081
    public function testReverseLookupPath($spiUrlAliases, $prioritizedLanguageCodes, $paths, $reverseLookupLanguageCode)
3082
    {
3083
        $urlAliasService = $this->getRepository()->getURLAliasService();
3084
        $configuration = [
3085
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
3086
            'showAllTranslations' => false,
3087
        ];
3088
        $this->setConfiguration($urlAliasService, $configuration);
3089
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
3090
        $urlAliasHandler->expects(
3091
            $this->once()
3092
        )->method(
3093
            'listURLAliasesForLocation'
3094
        )->with(
3095
            $this->equalTo(42),
3096
            $this->equalTo(false)
3097
        )->will(
3098
            $this->returnValue($spiUrlAliases)
3099
        );
3100
3101
        $location = $this->getLocationStub();
3102
        $urlAlias = $urlAliasService->reverseLookup($location);
3103
3104
        self::assertEquals(
3105
            [$reverseLookupLanguageCode],
3106
            $urlAlias->languageCodes
3107
        );
3108
        self::assertEquals(
3109
            $paths[$reverseLookupLanguageCode],
3110
            $urlAlias->path
3111
        );
3112
    }
3113
3114
    public function providerForTestReverseLookupAlwaysAvailablePath()
3115
    {
3116
        return $this->providerForTestListAutogeneratedLocationAliasesAlwaysAvailablePath();
3117
    }
3118
3119
    /**
3120
     * Test for the reverseLookup() method.
3121
     *
3122
     * @dataProvider providerForTestReverseLookupAlwaysAvailablePath
3123
     */
3124 View Code Duplication
    public function testReverseLookupAlwaysAvailablePath(
3125
        $spiUrlAliases,
3126
        $prioritizedLanguageCodes,
3127
        $paths
3128
    ) {
3129
        $urlAliasService = $this->getRepository()->getURLAliasService();
3130
        $configuration = [
3131
            'prioritizedLanguageList' => $prioritizedLanguageCodes,
3132
            'showAllTranslations' => false,
3133
        ];
3134
        $this->setConfiguration($urlAliasService, $configuration);
3135
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
3136
        $urlAliasHandler->expects(
3137
            $this->once()
3138
        )->method(
3139
            'listURLAliasesForLocation'
3140
        )->with(
3141
            $this->equalTo(42),
3142
            $this->equalTo(false)
3143
        )->will(
3144
            $this->returnValue($spiUrlAliases)
3145
        );
3146
3147
        $location = $this->getLocationStub();
3148
        $urlAlias = $urlAliasService->reverseLookup($location);
3149
3150
        self::assertEquals(
3151
            reset($paths),
3152
            $urlAlias->path
3153
        );
3154
    }
3155
3156
    /**
3157
     * Test for the reverseLookup() method.
3158
     */
3159
    public function testReverseLookupWithShowAllTranslations()
3160
    {
3161
        $spiUrlAlias = $this->getSpiUrlAlias();
3162
        $urlAliasService = $this->getRepository()->getURLAliasService();
3163
        $configuration = [
3164
            'prioritizedLanguageList' => ['fre-FR'],
3165
            'showAllTranslations' => true,
3166
        ];
3167
        $this->setConfiguration($urlAliasService, $configuration);
3168
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
3169
        $urlAliasHandler->expects(
3170
            $this->once()
3171
        )->method(
3172
            'listURLAliasesForLocation'
3173
        )->with(
3174
            $this->equalTo(42),
3175
            $this->equalTo(false)
3176
        )->will(
3177
            $this->returnValue([$spiUrlAlias])
3178
        );
3179
3180
        $location = $this->getLocationStub();
3181
        $urlAlias = $urlAliasService->reverseLookup($location);
3182
3183
        self::assertEquals('/jedan/dva/tri', $urlAlias->path);
3184
    }
3185
3186
    /**
3187
     * Test for the createUrlAlias() method.
3188
     */
3189 View Code Duplication
    public function testCreateUrlAlias()
3190
    {
3191
        $repositoryMock = $this->getRepositoryMock();
3192
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
3193
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
3194
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
3195
        $location = $this->getLocationStub();
3196
3197
        $repositoryMock
3198
            ->expects($this->once())
3199
            ->method('beginTransaction');
3200
        $repositoryMock
3201
            ->expects($this->once())
3202
            ->method('commit');
3203
3204
        $urlAliasHandlerMock->expects(
3205
            $this->once()
3206
        )->method(
3207
            'createCustomUrlAlias'
3208
        )->with(
3209
            $this->equalTo($location->id),
3210
            $this->equalTo('path'),
3211
            $this->equalTo('forwarding'),
3212
            $this->equalTo('languageCode'),
3213
            $this->equalTo('alwaysAvailable')
3214
        )->will(
3215
            $this->returnValue(new SPIUrlAlias())
3216
        );
3217
3218
        $urlAlias = $mockedService->createUrlAlias(
3219
            $location,
3220
            'path',
3221
            'languageCode',
3222
            'forwarding',
3223
            'alwaysAvailable'
3224
        );
3225
3226
        self::assertInstanceOf(
3227
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
3228
            $urlAlias
3229
        );
3230
    }
3231
3232
    /**
3233
     * Test for the createUrlAlias() method.
3234
     *
3235
     * @expectedException \Exception
3236
     * @expectedExceptionMessage Handler threw an exception
3237
     */
3238
    public function testCreateUrlAliasWithRollback()
3239
    {
3240
        $repositoryMock = $this->getRepositoryMock();
3241
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
3242
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
3243
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
3244
        $location = $this->getLocationStub();
3245
3246
        $repositoryMock
3247
            ->expects($this->once())
3248
            ->method('beginTransaction');
3249
        $repositoryMock
3250
            ->expects($this->once())
3251
            ->method('rollback');
3252
3253
        $urlAliasHandlerMock->expects(
3254
            $this->once()
3255
        )->method(
3256
            'createCustomUrlAlias'
3257
        )->with(
3258
            $this->equalTo($location->id),
3259
            $this->equalTo('path'),
3260
            $this->equalTo('forwarding'),
3261
            $this->equalTo('languageCode'),
3262
            $this->equalTo('alwaysAvailable')
3263
        )->will(
3264
            $this->throwException(new Exception('Handler threw an exception'))
3265
        );
3266
3267
        $mockedService->createUrlAlias(
3268
            $location,
3269
            'path',
3270
            'languageCode',
3271
            'forwarding',
3272
            'alwaysAvailable'
3273
        );
3274
    }
3275
3276
    /**
3277
     * Test for the createUrlAlias() method.
3278
     *
3279
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
3280
     */
3281 View Code Duplication
    public function testCreateUrlAliasThrowsInvalidArgumentException()
3282
    {
3283
        $location = $this->getLocationStub();
3284
        $urlAliasService = $this->getRepository()->getURLAliasService();
3285
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
3286
3287
        $urlAliasHandler->expects(
3288
            $this->once()
3289
        )->method(
3290
            'createCustomUrlAlias'
3291
        )->with(
3292
            $this->equalTo($location->id),
3293
            $this->equalTo('path'),
3294
            $this->equalTo('forwarding'),
3295
            $this->equalTo('languageCode'),
3296
            $this->equalTo('alwaysAvailable')
3297
        )->will(
3298
            $this->throwException(new ForbiddenException('Forbidden!'))
3299
        );
3300
3301
        $urlAliasService->createUrlAlias(
3302
            $location,
3303
            'path',
3304
            'languageCode',
3305
            'forwarding',
3306
            'alwaysAvailable'
3307
        );
3308
    }
3309
3310
    /**
3311
     * Test for the createGlobalUrlAlias() method.
3312
     */
3313 View Code Duplication
    public function testCreateGlobalUrlAlias()
3314
    {
3315
        $resource = 'module:content/search';
3316
        $repositoryMock = $this->getRepositoryMock();
3317
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
3318
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
3319
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
3320
3321
        $repositoryMock
3322
            ->expects($this->once())
3323
            ->method('beginTransaction');
3324
        $repositoryMock
3325
            ->expects($this->once())
3326
            ->method('commit');
3327
3328
        $urlAliasHandlerMock->expects(
3329
            $this->once()
3330
        )->method(
3331
            'createGlobalUrlAlias'
3332
        )->with(
3333
            $this->equalTo($resource),
3334
            $this->equalTo('path'),
3335
            $this->equalTo('forwarding'),
3336
            $this->equalTo('languageCode'),
3337
            $this->equalTo('alwaysAvailable')
3338
        )->will(
3339
            $this->returnValue(new SPIUrlAlias())
3340
        );
3341
3342
        $urlAlias = $mockedService->createGlobalUrlAlias(
3343
            $resource,
3344
            'path',
3345
            'languageCode',
3346
            'forwarding',
3347
            'alwaysAvailable'
3348
        );
3349
3350
        self::assertInstanceOf(
3351
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
3352
            $urlAlias
3353
        );
3354
    }
3355
3356
    /**
3357
     * Test for the createGlobalUrlAlias() method.
3358
     *
3359
     * @expectedException \Exception
3360
     * @expectedExceptionMessage Handler threw an exception
3361
     */
3362
    public function testCreateGlobalUrlAliasWithRollback()
3363
    {
3364
        $resource = 'module:content/search';
3365
        $repositoryMock = $this->getRepositoryMock();
3366
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
3367
        /** @var \PHPUnit_Framework_MockObject_MockObject $urlAliasHandlerMock */
3368
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
3369
3370
        $repositoryMock
3371
            ->expects($this->once())
3372
            ->method('beginTransaction');
3373
        $repositoryMock
3374
            ->expects($this->once())
3375
            ->method('rollback');
3376
3377
        $urlAliasHandlerMock->expects(
3378
            $this->once()
3379
        )->method(
3380
            'createGlobalUrlAlias'
3381
        )->with(
3382
            $this->equalTo($resource),
3383
            $this->equalTo('path'),
3384
            $this->equalTo('forwarding'),
3385
            $this->equalTo('languageCode'),
3386
            $this->equalTo('alwaysAvailable')
3387
        )->will(
3388
            $this->throwException(new Exception('Handler threw an exception'))
3389
        );
3390
3391
        $mockedService->createGlobalUrlAlias(
3392
            $resource,
3393
            'path',
3394
            'languageCode',
3395
            'forwarding',
3396
            'alwaysAvailable'
3397
        );
3398
    }
3399
3400
    /**
3401
     * Test for the createGlobalUrlAlias() method.
3402
     *
3403
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
3404
     */
3405
    public function testCreateGlobalUrlAliasThrowsInvalidArgumentExceptionResource()
3406
    {
3407
        $urlAliasService = $this->getRepository()->getURLAliasService();
3408
        $urlAliasService->createGlobalUrlAlias(
3409
            'invalid/resource',
3410
            'path',
3411
            'languageCode',
3412
            'forwarding',
3413
            'alwaysAvailable'
3414
        );
3415
    }
3416
3417
    /**
3418
     * Test for the createGlobalUrlAlias() method.
3419
     *
3420
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
3421
     */
3422 View Code Duplication
    public function testCreateGlobalUrlAliasThrowsInvalidArgumentExceptionPath()
3423
    {
3424
        $resource = 'module:content/search';
3425
        $urlAliasService = $this->getRepository()->getURLAliasService();
3426
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
3427
3428
        $urlAliasHandler->expects(
3429
            $this->once()
3430
        )->method(
3431
            'createGlobalUrlAlias'
3432
        )->with(
3433
            $this->equalTo($resource),
3434
            $this->equalTo('path'),
3435
            $this->equalTo('forwarding'),
3436
            $this->equalTo('languageCode'),
3437
            $this->equalTo('alwaysAvailable')
3438
        )->will(
3439
            $this->throwException(new ForbiddenException('Forbidden!'))
3440
        );
3441
3442
        $urlAliasService->createGlobalUrlAlias(
3443
            $resource,
3444
            'path',
3445
            'languageCode',
3446
            'forwarding',
3447
            'alwaysAvailable'
3448
        );
3449
    }
3450
3451
    /**
3452
     * Test for the createGlobalUrlAlias() method.
3453
     *
3454
     * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\UrlAliasTest::testCreateUrlAlias
3455
     * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\UrlAliasTest::testCreateUrlAliasWithRollback
3456
     * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\UrlAliasTest::testCreateUrlAliasThrowsInvalidArgumentException
3457
     */
3458
    public function testCreateGlobalUrlAliasForLocation()
3459
    {
3460
        $repositoryMock = $this->getRepositoryMock();
3461
        $mockedService = $this->getPartlyMockedURLAliasServiceService(['createUrlAlias']);
3462
        $location = $this->getLocationStub();
3463
        $locationServiceMock = $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
3464
            'eZ\\Publish\\Core\\Repository\\LocationService',
3465
            [],
3466
            [],
3467
            '',
3468
            false
3469
        );
3470
3471
        $locationServiceMock->expects(
3472
            $this->exactly(2)
3473
        )->method(
3474
            'loadLocation'
3475
        )->with(
3476
            $this->equalTo(42)
3477
        )->will(
3478
            $this->returnValue($location)
3479
        );
3480
3481
        $repositoryMock->expects(
3482
            $this->exactly(2)
3483
        )->method(
3484
            'getLocationService'
3485
        )->will(
3486
            $this->returnValue($locationServiceMock)
3487
        );
3488
3489
        $mockedService->expects(
3490
            $this->exactly(2)
3491
        )->method(
3492
            'createUrlAlias'
3493
        )->with(
3494
            $this->equalTo($location),
3495
            $this->equalTo('path'),
3496
            $this->equalTo('languageCode'),
3497
            $this->equalTo('forwarding'),
3498
            $this->equalTo('alwaysAvailable')
3499
        );
3500
3501
        $mockedService->createGlobalUrlAlias(
3502
            'eznode:42',
3503
            'path',
3504
            'languageCode',
3505
            'forwarding',
3506
            'alwaysAvailable'
3507
        );
3508
        $mockedService->createGlobalUrlAlias(
3509
            'module:content/view/full/42',
3510
            'path',
3511
            'languageCode',
3512
            'forwarding',
3513
            'alwaysAvailable'
3514
        );
3515
    }
3516
3517
    /**
3518
     * @param int $id
3519
     *
3520
     * @return \eZ\Publish\Core\Repository\Values\Content\Location
3521
     */
3522
    protected function getLocationStub($id = 42)
3523
    {
3524
        return new Location(['id' => $id]);
3525
    }
3526
3527
    /**
3528
     * @param object $urlAliasService
3529
     * @param array $configuration
3530
     */
3531 View Code Duplication
    protected function setConfiguration($urlAliasService, array $configuration)
3532
    {
3533
        $refObject = new \ReflectionObject($urlAliasService);
3534
        $refProperty = $refObject->getProperty('settings');
3535
        $refProperty->setAccessible(true);
3536
        $refProperty->setValue(
3537
            $urlAliasService,
3538
            $configuration
3539
        );
3540
    }
3541
3542
    /**
3543
     * Returns the content service to test with $methods mocked.
3544
     *
3545
     * Injected Repository comes from {@see getRepositoryMock()} and persistence handler from {@see getPersistenceMock()}
3546
     *
3547
     * @param string[] $methods
3548
     *
3549
     * @return \eZ\Publish\Core\Repository\URLAliasService|\PHPUnit_Framework_MockObject_MockObject
3550
     */
3551
    protected function getPartlyMockedURLAliasServiceService(array $methods = null)
3552
    {
3553
        $languageServiceMock = $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
3554
            'eZ\\Publish\\Core\\Repository\\LanguageService',
3555
            [],
3556
            [],
3557
            '',
3558
            false
3559
        );
3560
        $languageServiceMock->expects(
3561
            $this->once()
3562
        )->method(
3563
            'getPrioritizedLanguageCodeList'
3564
        )->will(
3565
            $this->returnValue(['eng-GB'])
3566
        );
3567
3568
        $this->getRepositoryMock()->expects(
3569
            $this->once()
3570
        )->method(
3571
            'getContentLanguageService'
3572
        )->will(
3573
            $this->returnValue($languageServiceMock)
3574
        );
3575
3576
        return $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
3577
            'eZ\\Publish\\Core\\Repository\\URLAliasService',
3578
            $methods,
0 ignored issues
show
Bug introduced by
It seems like $methods defined by parameter $methods on line 3551 can also be of type null; however, eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
3579
            [
3580
                $this->getRepositoryMock(),
3581
                $this->getPersistenceMock()->urlAliasHandler(),
3582
                $this->getNameSchemaServiceMock(),
3583
            ]
3584
        );
3585
    }
3586
3587
    /**
3588
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Repository\Helper\NameSchemaService
3589
     */
3590
    protected function getNameSchemaServiceMock()
3591
    {
3592
        return $this->createMock('eZ\\Publish\\Core\\Repository\\Helper\\NameSchemaService');
3593
    }
3594
}
3595