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