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