From 23d4b5be8fc2b822ee099ce51ff352e2e2341b79 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Fri, 2 Feb 2018 13:42:53 +0100 Subject: [PATCH] fixed get resource-segment by locale --- GoneSubscriber/GoneDocumentSubscriber.php | 8 ++++- .../GoneDocumentSubscriberTest.php | 29 +++++++++---------- Tests/app/config/config.yml | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/GoneSubscriber/GoneDocumentSubscriber.php b/GoneSubscriber/GoneDocumentSubscriber.php index d55c1c5..aa0d562 100644 --- a/GoneSubscriber/GoneDocumentSubscriber.php +++ b/GoneSubscriber/GoneDocumentSubscriber.php @@ -134,10 +134,16 @@ protected function getUrls(BasePageDocument $document) return $urls; } + $localizedUrls = $this->documentInspector->getLocalizedUrlsForPage($document); + foreach ($webspace->getAllLocalizations() as $localization) { + if (!array_key_exists($localization->getLocale(), $localizedUrls)) { + continue; + } + $urls = array_merge( $this->webspaceManager->findUrlsByResourceLocator( - $document->getResourceSegment(), + $localizedUrls[$localization->getLocale()], $this->environment, $localization->getLocale() ), diff --git a/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php b/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php index 00fe0ef..dfff8ca 100644 --- a/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php +++ b/Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php @@ -82,14 +82,15 @@ protected function setUp() { $this->document = $this->prophesize(BasePageDocument::class); $this->document->getUuid()->willReturn('123-123-123'); - $this->document->getResourceSegment()->willReturn('/abc'); $this->entityManager = $this->prophesize(EntityManager::class); $this->redirectRouteManager = $this->prophesize(RedirectRouteManager::class); $this->documentInspector = $this->prophesize(DocumentInspector::class); - $this->documentInspector->getWebspace($this->document)->willReturn('example'); + $this->documentInspector->getWebspace($this->document->reveal())->willReturn('example'); + + $this->documentInspector->getLocalizedUrlsForPage($this->document->reveal())->willReturn(['de' => '/artikel', 'en' => '/article']); $this->webspace = $this->prophesize(Webspace::class); $this->webspace->getAllLocalizations()->willReturn([ @@ -99,25 +100,21 @@ protected function setUp() $this->webspaceManager = $this->prophesize(WebspaceManager::class); $this->webspaceManager->findWebspaceByKey('example')->willReturn($this->webspace->reveal()); - $this->webspaceManager->findUrlsByResourceLocator('/abc', 'test', 'en') - ->willReturn(['http://{host}/en/abc']); - $this->webspaceManager->findUrlsByResourceLocator('/abc1', 'test', 'en') - ->willReturn(['http://{host}/en/abc1']); - $this->webspaceManager->findUrlsByResourceLocator('/abc2', 'test', 'en') - ->willReturn(['http://{host}/en/abc2']); - $this->webspaceManager->findUrlsByResourceLocator('/abc', 'test', 'de') - ->willReturn(['http://{host}/en/abc']); - $this->webspaceManager->findUrlsByResourceLocator('/abc1', 'test', 'de') - ->willReturn(['http://{host}/en/abc1']); - $this->webspaceManager->findUrlsByResourceLocator('/abc2', 'test', 'de') - ->willReturn(['http://{host}/en/abc2']); + $this->webspaceManager->findUrlsByResourceLocator('/article', 'test', 'en') + ->willReturn(['http://{host}/en/article']); + $this->webspaceManager->findUrlsByResourceLocator('/article1', 'test', 'en') + ->willReturn(['http://{host}/en/article1']); + $this->webspaceManager->findUrlsByResourceLocator('/article2', 'test', 'en') + ->willReturn(['http://{host}/en/article2']); + $this->webspaceManager->findUrlsByResourceLocator('/artikel', 'test', 'de') + ->willReturn(['http://{host}/de/artikel']); $this->resourceLocatorStrategy = $this->prophesize(ResourceLocatorStrategyInterface::class); $this->resourceLocatorStrategy->loadHistoryByContentUuid('123-123-123', 'example', 'en') ->willReturn( [ - new ResourceLocatorInformation('/abc1', new \DateTime(), '1'), - new ResourceLocatorInformation('/abc2', new \DateTime(), '1'), + new ResourceLocatorInformation('/article1', new \DateTime(), '1'), + new ResourceLocatorInformation('/article2', new \DateTime(), '1'), ] ); $this->resourceLocatorStrategy->loadHistoryByContentUuid('123-123-123', 'example', 'de') diff --git a/Tests/app/config/config.yml b/Tests/app/config/config.yml index bee79d0..99f5df8 100644 --- a/Tests/app/config/config.yml +++ b/Tests/app/config/config.yml @@ -1,4 +1,5 @@ # Doctrine Configuration doctrine: dbal: + host: 127.0.0.1 dbname: "su_redirect_test"