| @@ 3277-3327 (lines=51) @@ | ||
| 3274 | * @expectedException \Exception |
|
| 3275 | * @expectedExceptionMessage Handler threw an exception |
|
| 3276 | */ |
|
| 3277 | public function testCreateUrlAliasWithRollback() |
|
| 3278 | { |
|
| 3279 | $permissionResolverMock = $this->createMock(PermissionResolver::class); |
|
| 3280 | $permissionResolverMock |
|
| 3281 | ->expects($this->once()) |
|
| 3282 | ->method('hasAccess')->with( |
|
| 3283 | $this->equalTo('content'), |
|
| 3284 | $this->equalTo('urltranslator') |
|
| 3285 | )->will($this->returnValue(true)); |
|
| 3286 | ||
| 3287 | $repositoryMock = $this->getRepositoryMock(); |
|
| 3288 | ||
| 3289 | $repositoryMock |
|
| 3290 | ->expects($this->atLeastOnce()) |
|
| 3291 | ->method('getPermissionResolver') |
|
| 3292 | ->willReturn($permissionResolverMock); |
|
| 3293 | ||
| 3294 | $mockedService = $this->getPartlyMockedURLAliasServiceService(); |
|
| 3295 | /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ |
|
| 3296 | $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); |
|
| 3297 | $location = $this->getLocationStub(); |
|
| 3298 | ||
| 3299 | $repositoryMock |
|
| 3300 | ->expects($this->once()) |
|
| 3301 | ->method('beginTransaction'); |
|
| 3302 | $repositoryMock |
|
| 3303 | ->expects($this->once()) |
|
| 3304 | ->method('rollback'); |
|
| 3305 | ||
| 3306 | $urlAliasHandlerMock->expects( |
|
| 3307 | $this->once() |
|
| 3308 | )->method( |
|
| 3309 | 'createCustomUrlAlias' |
|
| 3310 | )->with( |
|
| 3311 | $this->equalTo($location->id), |
|
| 3312 | $this->equalTo('path'), |
|
| 3313 | $this->equalTo('forwarding'), |
|
| 3314 | $this->equalTo('languageCode'), |
|
| 3315 | $this->equalTo('alwaysAvailable') |
|
| 3316 | )->will( |
|
| 3317 | $this->throwException(new Exception('Handler threw an exception')) |
|
| 3318 | ); |
|
| 3319 | ||
| 3320 | $mockedService->createUrlAlias( |
|
| 3321 | $location, |
|
| 3322 | 'path', |
|
| 3323 | 'languageCode', |
|
| 3324 | 'forwarding', |
|
| 3325 | 'alwaysAvailable' |
|
| 3326 | ); |
|
| 3327 | } |
|
| 3328 | ||
| 3329 | /** |
|
| 3330 | * Test for the createUrlAlias() method. |
|
| @@ 3441-3490 (lines=50) @@ | ||
| 3438 | * @expectedException \Exception |
|
| 3439 | * @expectedExceptionMessage Handler threw an exception |
|
| 3440 | */ |
|
| 3441 | public function testCreateGlobalUrlAliasWithRollback() |
|
| 3442 | { |
|
| 3443 | $resource = 'module:content/search'; |
|
| 3444 | $permissionResolverMock = $this->createMock(PermissionResolver::class); |
|
| 3445 | $permissionResolverMock |
|
| 3446 | ->expects($this->once()) |
|
| 3447 | ->method('hasAccess')->with( |
|
| 3448 | $this->equalTo('content'), |
|
| 3449 | $this->equalTo('urltranslator') |
|
| 3450 | )->will($this->returnValue(true)); |
|
| 3451 | ||
| 3452 | $repositoryMock = $this->getRepositoryMock(); |
|
| 3453 | ||
| 3454 | $repositoryMock |
|
| 3455 | ->expects($this->atLeastOnce()) |
|
| 3456 | ->method('getPermissionResolver') |
|
| 3457 | ->willReturn($permissionResolverMock); |
|
| 3458 | $mockedService = $this->getPartlyMockedURLAliasServiceService(); |
|
| 3459 | /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ |
|
| 3460 | $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); |
|
| 3461 | ||
| 3462 | $repositoryMock |
|
| 3463 | ->expects($this->once()) |
|
| 3464 | ->method('beginTransaction'); |
|
| 3465 | $repositoryMock |
|
| 3466 | ->expects($this->once()) |
|
| 3467 | ->method('rollback'); |
|
| 3468 | ||
| 3469 | $urlAliasHandlerMock->expects( |
|
| 3470 | $this->once() |
|
| 3471 | )->method( |
|
| 3472 | 'createGlobalUrlAlias' |
|
| 3473 | )->with( |
|
| 3474 | $this->equalTo($resource), |
|
| 3475 | $this->equalTo('path'), |
|
| 3476 | $this->equalTo('forwarding'), |
|
| 3477 | $this->equalTo('languageCode'), |
|
| 3478 | $this->equalTo('alwaysAvailable') |
|
| 3479 | )->will( |
|
| 3480 | $this->throwException(new Exception('Handler threw an exception')) |
|
| 3481 | ); |
|
| 3482 | ||
| 3483 | $mockedService->createGlobalUrlAlias( |
|
| 3484 | $resource, |
|
| 3485 | 'path', |
|
| 3486 | 'languageCode', |
|
| 3487 | 'forwarding', |
|
| 3488 | 'alwaysAvailable' |
|
| 3489 | ); |
|
| 3490 | } |
|
| 3491 | ||
| 3492 | /** |
|
| 3493 | * Test for the createGlobalUrlAlias() method. |
|