Completed
Push — master ( c423d6...fbe27e )
by André
25:21
created

testCreateUrlAliasThrowsUnauthorizedException()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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