diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceAuthorizationTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceAuthorizationTest.php index 7b831d0cd84..4bee4ff03e6 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceAuthorizationTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceAuthorizationTest.php @@ -8,13 +8,14 @@ */ namespace eZ\Publish\API\Repository\Tests; +use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; + class URLAliasServiceAuthorizationTest extends BaseTest { /** * Test for the createUrlAlias() method. * * @covers \eZ\Publish\API\Repository\URLAliasService::createUrlAlias() - * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * @depends \eZ\Publish\API\Repository\Tests\URLAliasServiceTest::testCreateUrlAlias */ public function testCreateUrlAliasThrowsUnauthorizedException() @@ -31,12 +32,13 @@ public function testCreateUrlAliasThrowsUnauthorizedException() $urlAliasService = $repository->getURLAliasService(); $locationService = $repository->getLocationService(); - $location = $locationService->newLocationCreateStruct($parentLocationId); + $content = $this->createFolder(['eng-GB' => 'Foo'], $parentLocationId); + $location = $locationService->loadLocation($content->contentInfo->mainLocationId); $anonymousUser = $userService->loadUser($anonymousUserId); $repository->getPermissionResolver()->setCurrentUserReference($anonymousUser); - // This call will fail with an UnauthorizedException + $this->expectException(UnauthorizedException::class); $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US'); /* END: Use Case */ } diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php index 6c7d23ee57c..0f954fe4244 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php @@ -87,7 +87,7 @@ public function testCreateUrlAlias() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -144,7 +144,7 @@ public function testCreateUrlAliasWithForwarding() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -200,7 +200,7 @@ public function testCreateUrlAliasWithAlwaysAvailable() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -279,7 +279,7 @@ public function testCreateGlobalUrlAlias() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -331,7 +331,7 @@ public function testCreateGlobalUrlAliasWithForward() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -384,7 +384,7 @@ public function testCreateGlobalUrlAliasWithAlwaysAvailable() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -443,7 +443,7 @@ public function testCreateGlobalUrlAliasForLocation() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -478,7 +478,7 @@ public function testCreateGlobalUrlAliasForLocationVariation() /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $createdUrlAlias ); @@ -569,13 +569,10 @@ public function testListLocationAliases() $loadedAliases = $urlAliasService->listLocationAliases($location); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); + $this->assertIsArray($loadedAliases); // Only 1 non-history alias - $this->assertEquals(1, count($loadedAliases)); + $this->assertCount(1, $loadedAliases); return [$loadedAliases, $location]; } @@ -591,7 +588,7 @@ public function testListLocationAliasesLoadsCorrectly(array $testData) foreach ($loadedAliases as $loadedAlias) { $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $loadedAlias ); $this->assertEquals( @@ -626,11 +623,8 @@ public function testListLocationAliasesWithCustomFilter() $loadedAliases = $urlAliasService->listLocationAliases($location, false, 'eng-US'); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(1, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(1, $loadedAliases); } /** @@ -657,11 +651,8 @@ public function testListLocationAliasesWithLanguageCodeFilter() $loadedAliases = $urlAliasService->listLocationAliases($location, true, 'eng-US'); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(1, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(1, $loadedAliases); } /** @@ -683,11 +674,8 @@ public function testListGlobalAliases() $loadedAliases = $urlAliasService->listGlobalAliases(); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(3, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(3, $loadedAliases); } /** @@ -736,11 +724,8 @@ public function testListGlobalAliasesWithLanguageFilter() $loadedAliases = $urlAliasService->listGlobalAliases('eng-US'); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(2, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(2, $loadedAliases); } /** @@ -762,11 +747,8 @@ public function testListGlobalAliasesWithOffset() $loadedAliases = $urlAliasService->listGlobalAliases(null, 1); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(2, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(2, $loadedAliases); } /** @@ -788,11 +770,8 @@ public function testListGlobalAliasesWithLimit() $loadedAliases = $urlAliasService->listGlobalAliases(null, 0, 1); /* END: Use Case */ - $this->assertInternalType( - 'array', - $loadedAliases - ); - $this->assertEquals(1, count($loadedAliases)); + $this->assertIsArray($loadedAliases); + $this->assertCount(1, $loadedAliases); } /** @@ -876,11 +855,11 @@ public function testLookUp() /* BEGIN: Use Case */ $urlAliasService = $repository->getURLAliasService(); - $loadedAlias = $urlAliasService->lookUp('/Setup2'); + $loadedAlias = $urlAliasService->lookup('/Setup2'); /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $loadedAlias ); @@ -902,11 +881,11 @@ public function testLookUpWithLanguageFilter() // Create aliases in multiple languages $this->createGlobalAliases(); - $loadedAlias = $urlAliasService->lookUp('/My/Special-Support', 'eng-US'); + $loadedAlias = $urlAliasService->lookup('/My/Special-Support', 'eng-US'); /* END: Use Case */ $this->assertInstanceOf( - 'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias', + URLAlias::class, $loadedAlias ); $this->assertEquals( @@ -929,7 +908,7 @@ public function testLookUpThrowsNotFoundException() $urlAliasService = $repository->getURLAliasService(); // Throws NotFoundException - $loadedAlias = $urlAliasService->lookUp('/non-existent-url'); + $urlAliasService->lookup('/non-existent-url'); /* END: Use Case */ } @@ -947,7 +926,7 @@ public function testLookUpThrowsNotFoundExceptionWithLanguageFilter() $urlAliasService = $repository->getURLAliasService(); // Throws NotFoundException - $loadedAlias = $urlAliasService->lookUp('/Contact-Us', 'ger-DE'); + $urlAliasService->lookup('/Contact-Us', 'ger-DE'); /* END: Use Case */ } @@ -965,7 +944,7 @@ public function testLookUpThrowsInvalidArgumentException() $urlAliasService = $repository->getURLAliasService(); // Throws InvalidArgumentException - $loadedAlias = $urlAliasService->lookUp(str_repeat('/1', 99), 'ger-DE'); + $loadedAlias = $urlAliasService->lookup(str_repeat('/1', 99), 'ger-DE'); /* END: Use Case */ } diff --git a/eZ/Publish/Core/Repository/Repository.php b/eZ/Publish/Core/Repository/Repository.php index 3c1f09d9c9e..3e27df78213 100644 --- a/eZ/Publish/Core/Repository/Repository.php +++ b/eZ/Publish/Core/Repository/Repository.php @@ -626,6 +626,7 @@ public function getURLAliasService() $this, $this->persistenceHandler->urlAliasHandler(), $this->getNameSchemaService(), + $this->getPermissionResolver(), $this->serviceSettings['urlAlias'] ); diff --git a/eZ/Publish/Core/Repository/Tests/Service/Mock/UrlAliasTest.php b/eZ/Publish/Core/Repository/Tests/Service/Mock/UrlAliasTest.php index 0a5629424a7..8e92dd13d81 100644 --- a/eZ/Publish/Core/Repository/Tests/Service/Mock/UrlAliasTest.php +++ b/eZ/Publish/Core/Repository/Tests/Service/Mock/UrlAliasTest.php @@ -8,17 +8,18 @@ */ namespace eZ\Publish\Core\Repository\Tests\Service\Mock; +use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException; +use eZ\Publish\API\Repository\Exceptions\NotFoundException as ApiNotFoundException; use eZ\Publish\Core\Repository\Helper\NameSchemaService; use eZ\Publish\Core\Repository\LanguageService; use eZ\Publish\Core\Repository\LocationService; use eZ\Publish\Core\Repository\URLAliasService; use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest; use eZ\Publish\SPI\Persistence\Content\UrlAlias as SPIUrlAlias; -use eZ\Publish\API\Repository\Values\Content\UrlAlias; +use eZ\Publish\API\Repository\Values\Content\URLAlias; use eZ\Publish\Core\Repository\Values\Content\Location; use eZ\Publish\Core\Base\Exceptions\NotFoundException; use eZ\Publish\Core\Base\Exceptions\ForbiddenException; -use eZ\Publish\API\Repository\PermissionResolver; use Exception; /** @@ -26,6 +27,19 @@ */ class UrlAliasTest extends BaseServiceMockTest { + /** @var \eZ\Publish\API\Repository\PermissionResolver|\PHPUnit\Framework\MockObject\MockObject */ + private $permissionResolver; + + /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler|\PHPUnit\Framework\MockObject\MockObject */ + private $urlAliasHandler; + + protected function setUp() + { + parent::setUp(); + $this->urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); + $this->permissionResolver = $this->getPermissionResolverMock(); + } + /** * Test for the __construct() method. */ @@ -33,10 +47,6 @@ public function testConstructor() { $repositoryMock = $this->getRepositoryMock(); $languageServiceMock = $this->createMock(LanguageService::class); - /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler $urlAliasHandler */ - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $settings = ['settings']; - $languageServiceMock ->expects($this->once()) ->method('getPrioritizedLanguageCodeList') @@ -47,33 +57,11 @@ public function testConstructor() ->method('getContentLanguageService') ->will($this->returnValue($languageServiceMock)); - $service = new UrlALiasService( + new UrlALiasService( $repositoryMock, - $urlAliasHandler, + $this->urlAliasHandler, $this->getNameSchemaServiceMock(), - $settings - ); - - $this->assertAttributeSame( - $repositoryMock, - 'repository', - $service - ); - - $this->assertAttributeSame( - $urlAliasHandler, - 'urlAliasHandler', - $service - ); - - $this->assertAttributeSame( - [ - 'settings', - 'showAllTranslations' => false, - 'prioritizedLanguageList' => ['prioritizedLanguageList'], - ], - 'settings', - $service + $this->permissionResolver ); } @@ -105,8 +93,6 @@ public function testLoad() /** * Test for the load() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException */ public function testLoadThrowsNotFoundException() { @@ -120,6 +106,7 @@ public function testLoadThrowsNotFoundException() ->with(42) ->will($this->throwException(new NotFoundException('UrlAlias', 42))); + $this->expectException(ApiNotFoundException::class); $mockedService->load(42); } @@ -159,53 +146,44 @@ protected function getSpiUrlAlias() /** * Test for the load() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException */ public function testLoadThrowsNotFoundExceptionPath() { $spiUrlAlias = $this->getSpiUrlAlias(); - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => ['fre-FR'], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - - $urlAliasHandlerMock + $this->urlAliasHandler ->expects($this->once()) ->method('loadUrlAlias') ->with(42) ->will($this->returnValue($spiUrlAlias)); + $this->expectException(ApiNotFoundException::class); + $urlAliasService->load(42); } /** * Test for the removeAliases() method. - * - * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException */ public function testRemoveAliasesThrowsInvalidArgumentException() { - $aliasList = [new UrlAlias(['isCustom' => false])]; + $aliasList = [new URLAlias(['isCustom' => false])]; $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(true)); - - $repositoryMock = $this->getRepositoryMock(); + ) + ->will($this->returnValue(true)); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); + $this->expectException(InvalidArgumentException::class); $mockedService->removeAliases($aliasList); } @@ -215,10 +193,9 @@ public function testRemoveAliasesThrowsInvalidArgumentException() */ public function testRemoveAliases() { - $aliasList = [new UrlAlias(['isCustom' => true])]; + $aliasList = [new URLAlias(['isCustom' => true])]; $spiAliasList = [new SPIUrlAlias(['isCustom' => true])]; - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), @@ -227,10 +204,6 @@ public function testRemoveAliases() $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); @@ -252,16 +225,12 @@ public function testRemoveAliases() /** * Test for the removeAliases() method. - * - * @expectedException \Exception - * @expectedExceptionMessage Handler threw an exception */ public function testRemoveAliasesWithRollback() { - $aliasList = [new UrlAlias(['isCustom' => true])]; + $aliasList = [new URLAlias(['isCustom' => true])]; $spiAliasList = [new SPIUrlAlias(['isCustom' => true])]; - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), @@ -270,10 +239,6 @@ public function testRemoveAliasesWithRollback() $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); @@ -291,6 +256,9 @@ public function testRemoveAliasesWithRollback() ->with($spiAliasList) ->will($this->throwException(new Exception('Handler threw an exception'))); + $this->expectException(Exception::class); + $this->expectExceptionMessage('Handler threw an exception'); + $mockedService->removeAliases($aliasList); } @@ -668,24 +636,13 @@ public function providerForTestListAutogeneratedLocationAliasesPath() */ public function testListAutogeneratedLocationAliasesPath($spiUrlAliases, $prioritizedLanguageCodes, $paths) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -718,24 +675,13 @@ public function testListAutogeneratedLocationAliasesPathCustomConfiguration( $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -798,25 +744,21 @@ public function testListLocationAliasesWithShowAllTranslations() 'alwaysAvailable' => false, ] ); - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => ['fre-FR'], 'showAllTranslations' => true, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - - $urlAliasHandlerMock->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue([$spiUrlAlias]) - ); + $this->urlAliasHandler + ->expects($this->once()) + ->method('listURLAliasesForLocation') + ->with( + $this->equalTo(42), + $this->equalTo(false) + ) + ->will($this->returnValue([$spiUrlAlias])); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -860,25 +802,21 @@ public function testListLocationAliasesWithShowAllTranslationsCustomConfiguratio 'alwaysAvailable' => false, ] ); - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandlerMock = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - - $urlAliasHandlerMock->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue([$spiUrlAlias]) - ); + $this->urlAliasHandler + ->expects($this->once()) + ->method('listURLAliasesForLocation') + ->with( + $this->equalTo(42), + $this->equalTo(false) + ) + ->will($this->returnValue([$spiUrlAlias])); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -978,23 +916,13 @@ public function providerForTestListAutogeneratedLocationAliasesEmpty() */ public function testListAutogeneratedLocationAliasesEmpty($spiUrlAliases, $prioritizedLanguageCodes) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -1011,23 +939,13 @@ public function testListAutogeneratedLocationAliasesEmptyCustomConfiguration( $spiUrlAliases, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -1371,23 +1289,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodePath( $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -1416,23 +1324,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodePathCustomCo $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -1655,23 +1553,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeEmpty( $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -1689,23 +1577,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeEmptyCustomC $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -1785,23 +1663,13 @@ public function providerForTestListAutogeneratedLocationAliasesMultipleLanguages */ public function testListAutogeneratedLocationAliasesMultipleLanguagesPath($spiUrlAliases, $prioritizedLanguageCodes, $paths) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -1829,23 +1697,13 @@ public function testListAutogeneratedLocationAliasesMultipleLanguagesPathCustomC $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -1915,23 +1773,13 @@ public function providerForTestListAutogeneratedLocationAliasesMultipleLanguages */ public function testListAutogeneratedLocationAliasesMultipleLanguagesEmpty($spiUrlAliases, $prioritizedLanguageCodes) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -1948,23 +1796,13 @@ public function testListAutogeneratedLocationAliasesMultipleLanguagesEmptyCustom $spiUrlAliases, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2052,23 +1890,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLang $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -2097,23 +1925,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLang $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2198,23 +2016,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLang $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -2232,23 +2040,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeMultipleLang $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2337,23 +2135,13 @@ public function testListAutogeneratedLocationAliasesAlwaysAvailablePath( $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, null); @@ -2381,23 +2169,13 @@ public function testListAutogeneratedLocationAliasesAlwaysAvailablePathCustomCon $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2478,23 +2256,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvaila $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -2523,23 +2291,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvaila $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2618,23 +2376,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvaila $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases($location, false, $languageCode); @@ -2652,23 +2400,13 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvaila $languageCode, $prioritizedLanguageCodes ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => [], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAliases = $urlAliasService->listLocationAliases( @@ -2687,15 +2425,14 @@ public function testListAutogeneratedLocationAliasesWithLanguageCodeAlwaysAvaila */ public function testListGlobalAliases() { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => ['ger-DE'], 'showAllTranslations' => true, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'listGlobalURLAliases' @@ -2735,15 +2472,14 @@ public function testListGlobalAliases() */ public function testListGlobalAliasesEmpty() { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => ['eng-GB'], 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'listGlobalURLAliases' @@ -2782,10 +2518,9 @@ public function testListGlobalAliasesEmpty() */ public function testListGlobalAliasesWithParameters() { - $urlAliasService = $this->getRepository()->getURLAliasService(); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'listGlobalURLAliases' @@ -2809,10 +2544,9 @@ public function testListGlobalAliasesWithParameters() */ public function testLookupThrowsNotFoundException() { - $urlAliasService = $this->getRepository()->getURLAliasService(); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'lookup' @@ -2847,15 +2581,14 @@ public function providerForTestLookupThrowsNotFoundExceptionPath() */ public function testLookupThrowsNotFoundExceptionPathNotMatchedOrNotLoadable($url, $prioritizedLanguageList, $languageCode) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageList, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'lookup' @@ -2907,15 +2640,14 @@ public function providerForTestLookup() */ public function testLookup($prioritizedLanguageList, $showAllTranslations, $alwaysAvailable, $languageCode) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageList, 'showAllTranslations' => $showAllTranslations, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'lookup' @@ -2985,15 +2717,14 @@ public function testLookupWithSharedTranslation( $alwaysAvailable, $languageCode ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageList, 'showAllTranslations' => $showAllTranslations, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'lookup' @@ -3110,23 +2841,13 @@ public function providerForTestReverseLookup() */ public function testReverseLookupPath($spiUrlAliases, $prioritizedLanguageCodes, $paths, $reverseLookupLanguageCode) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAlias = $urlAliasService->reverseLookup($location); @@ -3156,23 +2877,13 @@ public function testReverseLookupAlwaysAvailablePath( $prioritizedLanguageCodes, $paths ) { - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => $prioritizedLanguageCodes, 'showAllTranslations' => false, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue($spiUrlAliases) - ); + $this->configureListURLAliasesForLocation($spiUrlAliases); $location = $this->getLocationStub(); $urlAlias = $urlAliasService->reverseLookup($location); @@ -3189,23 +2900,13 @@ public function testReverseLookupAlwaysAvailablePath( public function testReverseLookupWithShowAllTranslations() { $spiUrlAlias = $this->getSpiUrlAlias(); - $urlAliasService = $this->getRepository()->getURLAliasService(); + $urlAliasService = $this->getPartlyMockedURLAliasServiceService(); $configuration = [ 'prioritizedLanguageList' => ['fre-FR'], 'showAllTranslations' => true, ]; $this->setConfiguration($urlAliasService, $configuration); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); - $urlAliasHandler->expects( - $this->once() - )->method( - 'listURLAliasesForLocation' - )->with( - $this->equalTo(42), - $this->equalTo(false) - )->will( - $this->returnValue([$spiUrlAlias]) - ); + $this->configureListURLAliasesForLocation([$spiUrlAlias]); $location = $this->getLocationStub(); $urlAlias = $urlAliasService->reverseLookup($location); @@ -3218,25 +2919,21 @@ public function testReverseLookupWithShowAllTranslations() */ public function testCreateUrlAlias() { - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $location = $this->getLocationStub(); + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('canUser')->with( $this->equalTo('content'), - $this->equalTo('urltranslator') - )->will($this->returnValue(true)); + $this->equalTo('urltranslator'), + $this->equalTo($location) + ) + ->will($this->returnValue(true)); $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); - $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); - $location = $this->getLocationStub(); $repositoryMock ->expects($this->once()) @@ -3278,25 +2975,23 @@ public function testCreateUrlAlias() */ public function testCreateUrlAliasWithRollback() { - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $location = $this->getLocationStub(); + + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('canUser') + ->with( $this->equalTo('content'), - $this->equalTo('urltranslator') - )->will($this->returnValue(true)); + $this->equalTo('urltranslator'), + $this->equalTo($location) + ) + ->will($this->returnValue(true)); $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); - $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); - $location = $this->getLocationStub(); $repositoryMock ->expects($this->once()) @@ -3340,20 +3035,16 @@ public function testCreateUrlAliasThrowsInvalidArgumentException() $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $handlerMock */ $handlerMock = $this->getPersistenceMock()->urlAliasHandler(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('canUser') + ->with( $this->equalTo('content'), - $this->equalTo('urltranslator') - )->will($this->returnValue(true)); - - $repositoryMock = $this->getRepositoryMock(); - - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); + $this->equalTo('urltranslator'), + $this->equalTo($location) + ) + ->will($this->returnValue(true)); $handlerMock->expects( $this->once() @@ -3384,20 +3075,18 @@ public function testCreateUrlAliasThrowsInvalidArgumentException() public function testCreateGlobalUrlAlias() { $resource = 'module:content/search'; - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('hasAccess') + ->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(true)); + ) + ->will($this->returnValue(true)); $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); @@ -3443,20 +3132,18 @@ public function testCreateGlobalUrlAlias() public function testCreateGlobalUrlAliasWithRollback() { $resource = 'module:content/search'; - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('hasAccess') + ->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(true)); + ) + ->will($this->returnValue(true)); $repositoryMock = $this->getRepositoryMock(); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService = $this->getPartlyMockedURLAliasServiceService(); /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */ $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler(); @@ -3499,20 +3186,13 @@ public function testCreateGlobalUrlAliasWithRollback() public function testCreateGlobalUrlAliasThrowsInvalidArgumentExceptionResource() { $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(true)); - - $repositoryMock = $this->getRepositoryMock(); - - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); + ) + ->will($this->returnValue(true)); $mockedService->createGlobalUrlAlias( 'invalid/resource', @@ -3532,23 +3212,17 @@ public function testCreateGlobalUrlAliasThrowsInvalidArgumentExceptionPath() { $resource = 'module:content/search'; $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('hasAccess') + ->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(true)); - - $repositoryMock = $this->getRepositoryMock(); - - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); - $urlAliasHandler = $this->getPersistenceMockHandler('Content\\UrlAlias\\Handler'); + ) + ->will($this->returnValue(true)); - $urlAliasHandler->expects( + $this->urlAliasHandler->expects( $this->once() )->method( 'createGlobalUrlAlias' @@ -3603,18 +3277,14 @@ public function testCreateGlobalUrlAliasForLocation() $this->returnValue($locationServiceMock) ); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->exactly(2)) - ->method('hasAccess')->with( + ->method('canUser')->with( $this->equalTo('content'), - $this->equalTo('urltranslator') - )->will($this->returnValue(true)); - - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); + $this->equalTo('urltranslator'), + $this->equalTo($location) + ) + ->will($this->returnValue(true)); $mockedService->expects( $this->exactly(2) @@ -3705,6 +3375,7 @@ protected function getPartlyMockedURLAliasServiceService(array $methods = null) $this->getRepositoryMock(), $this->getPersistenceMock()->urlAliasHandler(), $this->getNameSchemaServiceMock(), + $this->permissionResolver, ] ) ->getMock(); @@ -3713,27 +3384,21 @@ protected function getPartlyMockedURLAliasServiceService(array $methods = null) /** * Test for the createUrlAlias() method. * - * @depends testConstructor * @covers \eZ\Publish\Core\Repository\URLAliasService::createUrlAlias * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException */ public function testCreateUrlAliasThrowsUnauthorizedException() { $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $repositoryMock = $this->getRepositoryMock(); $location = $this->getLocationStub(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) - ->method('hasAccess')->with( + ->method('canUser')->with( $this->equalTo('content'), - $this->equalTo('urltranslator') - )->will($this->returnValue(false)); - - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); + $this->equalTo('urltranslator'), + $this->equalTo($location) + ) + ->will($this->returnValue(false)); $mockedService->createUrlAlias( $location, @@ -3746,26 +3411,20 @@ public function testCreateUrlAliasThrowsUnauthorizedException() /** * Test for the createGlobalUrlAlias() method. * - * @depends testConstructor * @covers \eZ\Publish\Core\Repository\URLAliasService::createGlobalUrlAlias * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException */ public function testCreateGlobalUrlAliasThrowsUnauthorizedException() { $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $repositoryMock = $this->getRepositoryMock(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(false)); + ) + ->will($this->returnValue(false)); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService->createGlobalUrlAlias( 'eznode:42', 'path', @@ -3778,27 +3437,21 @@ public function testCreateGlobalUrlAliasThrowsUnauthorizedException() /** * Test for the removeAliases() method. * - * @depends testConstructor * @covers \eZ\Publish\Core\Repository\URLAliasService::removeAliases * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException */ public function testRemoveAliasesThrowsUnauthorizedException() { - $aliasList = [new UrlAlias(['isCustom' => true])]; + $aliasList = [new URLAlias(['isCustom' => true])]; $mockedService = $this->getPartlyMockedURLAliasServiceService(); - $repositoryMock = $this->getRepositoryMock(); - $permissionResolverMock = $this->createMock(PermissionResolver::class); - $permissionResolverMock + $this->permissionResolver ->expects($this->once()) ->method('hasAccess')->with( $this->equalTo('content'), $this->equalTo('urltranslator') - )->will($this->returnValue(false)); + ) + ->will($this->returnValue(false)); - $repositoryMock - ->expects($this->atLeastOnce()) - ->method('getPermissionResolver') - ->willReturn($permissionResolverMock); $mockedService->removeAliases($aliasList); } @@ -3809,4 +3462,19 @@ protected function getNameSchemaServiceMock() { return $this->createMock(NameSchemaService::class); } + + /** + * @param SPIUrlAlias[] $spiUrlAliases + */ + private function configureListURLAliasesForLocation(array $spiUrlAliases): void + { + $this->urlAliasHandler + ->expects($this->once()) + ->method('listURLAliasesForLocation') + ->with( + $this->equalTo(42), + $this->equalTo(false) + ) + ->will($this->returnValue($spiUrlAliases)); + } } diff --git a/eZ/Publish/Core/Repository/URLAliasService.php b/eZ/Publish/Core/Repository/URLAliasService.php index 0cfea73d3c3..c1847f09b3a 100644 --- a/eZ/Publish/Core/Repository/URLAliasService.php +++ b/eZ/Publish/Core/Repository/URLAliasService.php @@ -8,6 +8,7 @@ */ namespace eZ\Publish\Core\Repository; +use eZ\Publish\API\Repository\PermissionResolver; use eZ\Publish\API\Repository\URLAliasService as URLAliasServiceInterface; use eZ\Publish\API\Repository\Repository as RepositoryInterface; use eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler; @@ -39,18 +40,23 @@ class URLAliasService implements URLAliasServiceInterface /** @var \eZ\Publish\Core\Repository\Helper\NameSchemaService */ protected $nameSchemaService; + /** @var \eZ\Publish\API\Repository\PermissionResolver */ + private $permissionResolver; + /** * Setups service with reference to repository object that created it & corresponding handler. * * @param \eZ\Publish\API\Repository\Repository $repository * @param \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler $urlAliasHandler * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService + * @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver * @param array $settings */ public function __construct( RepositoryInterface $repository, Handler $urlAliasHandler, Helper\NameSchemaService $nameSchemaService, + PermissionResolver $permissionResolver, array $settings = [] ) { $this->repository = $repository; @@ -62,6 +68,7 @@ public function __construct( // Get prioritized languages from language service to not have to call it several times $this->settings['prioritizedLanguageList'] = $repository->getContentLanguageService()->getPrioritizedLanguageCodeList(); $this->nameSchemaService = $nameSchemaService; + $this->permissionResolver = $permissionResolver; } /** @@ -84,7 +91,7 @@ public function __construct( */ public function createUrlAlias(Location $location, $path, $languageCode, $forwarding = false, $alwaysAvailable = false) { - if ($this->repository->getPermissionResolver()->hasAccess('content', 'urltranslator') !== true) { + if (!$this->permissionResolver->canUser('content', 'urltranslator', $location)) { throw new UnauthorizedException('content', 'urltranslator'); } @@ -140,7 +147,7 @@ public function createUrlAlias(Location $location, $path, $languageCode, $forwar */ public function createGlobalUrlAlias($resource, $path, $languageCode, $forwarding = false, $alwaysAvailable = false) { - if ($this->repository->getPermissionResolver()->hasAccess('content', 'urltranslator') !== true) { + if ($this->permissionResolver->hasAccess('content', 'urltranslator') === false) { throw new UnauthorizedException('content', 'urltranslator'); } @@ -158,8 +165,14 @@ public function createGlobalUrlAlias($resource, $path, $languageCode, $forwardin $locationId = end($resourcePath); } + $location = $this->repository->getLocationService()->loadLocation($locationId); + + if (!$this->permissionResolver->canUser('content', 'urltranslator', $location)) { + throw new UnauthorizedException('content', 'urltranslator'); + } + return $this->createUrlAlias( - $this->repository->getLocationService()->loadLocation($locationId), + $location, $path, $languageCode, $forwarding, @@ -468,6 +481,8 @@ private function sortTranslationsByPrioritizedLanguages(array $translations) * * @param \eZ\Publish\SPI\Persistence\Content\URLAlias $spiUrlAlias * @param string|null $languageCode + * @param bool $showAllTranslations + * @param string[] $prioritizedLanguageList * * @return bool */ @@ -580,7 +595,7 @@ public function listGlobalAliases($languageCode = null, $offset = 0, $limit = -1 */ public function removeAliases(array $aliasList) { - if ($this->repository->getPermissionResolver()->hasAccess('content', 'urltranslator') !== true) { + if ($this->permissionResolver->hasAccess('content', 'urltranslator') === false) { throw new UnauthorizedException('content', 'urltranslator'); } @@ -784,7 +799,7 @@ public function refreshSystemUrlAliasesForLocation(Location $location): void */ public function deleteCorruptedUrlAliases(): int { - if ($this->repository->getPermissionResolver()->hasAccess('content', 'urltranslator') !== true) { + if ($this->repository->getPermissionResolver()->hasAccess('content', 'urltranslator') === false) { throw new UnauthorizedException('content', 'urltranslator'); }