Completed
Push — fix_ezp29385 ( 36b56f...415bc3 )
by
unknown
56:19 queued 22:25
created

testCreateGlobalUrlAliasForLocation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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