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