Skip to content

Commit

Permalink
Merge branch '6.7' into 6.8
Browse files Browse the repository at this point in the history
The conflicts were between ezsystems#1851 and ezsystems#1931.
  • Loading branch information
Bertrand Dunogier committed Mar 21, 2017
2 parents 34d5ab0 + 0cc073c commit 3e5be10
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Expand Up @@ -124,10 +124,15 @@ public function onKernelRequestRedirect(GetResponseEvent $event)
$semanticPathinfo = $siteaccess->matcher->analyseLink($semanticPathinfo);
}

$headers = [];
if ($request->attributes->has('locationId')) {
$headers[ 'X-Location-Id'] = $request->attributes->get('locationId');
}
$event->setResponse(
new RedirectResponse(
$semanticPathinfo . ($queryString ? "?$queryString" : ''),
301
301,
$headers
)
);
$event->stopPropagation();
Expand Down
Expand Up @@ -156,6 +156,29 @@ public function testOnKernelRequestRedirect()
$this->assertTrue($event->isPropagationStopped());
}

public function testOnKernelRequestRedirectWithLocationId()
{
$queryParameters = array('some' => 'thing');
$cookieParameters = array('cookie' => 'value');
$request = Request::create('/test_sa/foo/bar', 'GET', $queryParameters, $cookieParameters);
$semanticPathinfo = '/foo/something';
$request->attributes->set('semanticPathinfo', $semanticPathinfo);
$request->attributes->set('needsRedirect', true);
$request->attributes->set('locationId', 123);
$request->attributes->set('siteaccess', new SiteAccess());

$event = new GetResponseEvent($this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->requestEventListener->onKernelRequestRedirect($event);
$this->assertTrue($event->hasResponse());
/** @var RedirectResponse $response */
$response = $event->getResponse();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertSame("$semanticPathinfo?some=thing", $response->getTargetUrl());
$this->assertSame(301, $response->getStatusCode());
$this->assertEquals(123, $response->headers->get('X-Location-Id'));
$this->assertTrue($event->isPropagationStopped());
}

public function testOnKernelRequestRedirectPrependSiteaccess()
{
$queryParameters = array('some' => 'thing');
Expand Down
4 changes: 4 additions & 0 deletions eZ/Publish/Core/MVC/Symfony/Routing/UrlAliasRouter.php
Expand Up @@ -160,6 +160,10 @@ public function matchRequest(Request $request)
'semanticPathinfo' => $this->removePathPrefix($urlAlias->path, $pathPrefix),
'needsRedirect' => true,
);

if ($urlAlias->destination instanceof Location) {
$params += ['locationId' => $urlAlias->destination->id];
}
}

if (isset($this->logger)) {
Expand Down

0 comments on commit 3e5be10

Please sign in to comment.