Completed
Push — master ( d7552a...5d26cc )
by André
21:40
created

UrlAliasTest::testListGlobalAliases()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 30

Duplication

Lines 44
Ratio 100 %

Importance

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