Skip to content

Commit

Permalink
Merge pull request #25 from wachterjohannes/bugfix/document-gone-subs…
Browse files Browse the repository at this point in the history
…criber

Fixed get resource-segment by locale
  • Loading branch information
trickreich authored Feb 2, 2018
2 parents ebe736e + 23d4b5b commit 77e66d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 7 additions & 1 deletion GoneSubscriber/GoneDocumentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
),
Expand Down
29 changes: 13 additions & 16 deletions Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions Tests/app/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Doctrine Configuration
doctrine:
dbal:
host: 127.0.0.1
dbname: "su_redirect_test"

0 comments on commit 77e66d9

Please sign in to comment.