Completed
Push — migrate-files-no-interaction ( 025687...608925 )
by
unknown
46:43 queued 18:48
created

testReverseLookupWithShowAllTranslations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 26
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\URLAliasService;
12
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
13
use eZ\Publish\SPI\Persistence\Content\UrlAlias as SPIUrlAlias;
14
use eZ\Publish\API\Repository\Values\Content\UrlAlias;
15
use eZ\Publish\Core\Repository\Values\Content\Location;
16
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
17
use eZ\Publish\Core\Base\Exceptions\ForbiddenException;
18
use Exception;
19
20
/**
21
 * Mock test case for UrlAlias Service.
22
 */
23
class UrlAliasTest extends BaseServiceMockTest
24
{
25
    /**
26
     * Test for the __construct() method.
27
     */
28
    public function testConstructor()
29
    {
30
        $repositoryMock = $this->getRepositoryMock();
31
        $languageServiceMock = $this->createMock('eZ\\Publish\\Core\\Repository\\LanguageService');
32
        /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler $urlAliasHandler */
33
        $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler');
34
        $settings = array('settings');
35
36
        $languageServiceMock
37
            ->expects($this->once())
38
            ->method('getPrioritizedLanguageCodeList')
39
            ->will($this->returnValue(array('prioritizedLanguageList')));
40
41
        $repositoryMock
42
            ->expects($this->once())
43
            ->method('getContentLanguageService')
44
            ->will($this->returnValue($languageServiceMock));
45
46
        $service = new UrlALiasService(
47
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 30 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...sService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

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

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

    return array();
}

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

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

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