merged branch kriswallsmith/wdt/no-session-fix (PR #3444)
Commits
-------
95ec4eb
[WebProfilerBundle] fixed session assumption
Discussion
----------
[WebProfilerBundle] fixed session assumption
```
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
```
[![Build Status](https://secure.travis-ci.org/kriswallsmith/symfony.png?branch=wdt/no-session-fix)](http://travis-ci.org/kriswallsmith/symfony)
This commit is contained in:
commit
c319ff5939
@ -72,7 +72,7 @@ class WebDebugToolbarListener
|
|||||||
|
|
||||||
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
|
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
|
||||||
$session = $request->getSession();
|
$session = $request->getSession();
|
||||||
if ($session->getFlashBag() instanceof AutoExpireFlashBag) {
|
if ($session && $session->getFlashBag() instanceof AutoExpireFlashBag) {
|
||||||
// keep current flashes for one more request if using AutoExpireFlashBag
|
// keep current flashes for one more request if using AutoExpireFlashBag
|
||||||
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
|
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
|
||||||
}
|
}
|
||||||
|
@ -51,19 +51,20 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRedirectionIsIntercepted()
|
/**
|
||||||
|
* @dataProvider provideRedirects
|
||||||
|
*/
|
||||||
|
public function testRedirectionIsIntercepted($statusCode, $hasSession)
|
||||||
{
|
{
|
||||||
foreach (array(301, 302) as $statusCode) {
|
$response = new Response('Some content', $statusCode);
|
||||||
$response = new Response('Some content', $statusCode);
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||||
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
|
|
||||||
|
|
||||||
$listener = new WebDebugToolbarListener($this->getTemplatingMock('Redirection'), true);
|
$listener = new WebDebugToolbarListener($this->getTemplatingMock('Redirection'), true);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$this->assertEquals('Redirection', $response->getContent());
|
$this->assertEquals('Redirection', $response->getContent());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToolbarIsInjected()
|
public function testToolbarIsInjected()
|
||||||
@ -81,19 +82,28 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testToolbarIsInjected
|
* @depends testToolbarIsInjected
|
||||||
|
* @dataProvider provideRedirects
|
||||||
*/
|
*/
|
||||||
public function testToolbarIsNotInjectedOnRedirection()
|
public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession)
|
||||||
{
|
{
|
||||||
foreach (array(301, 302) as $statusCode) {
|
$response = new Response('<html><head></head><body></body></html>', $statusCode);
|
||||||
$response = new Response('<html><head></head><body></body></html>', $statusCode);
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
|
||||||
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
|
|
||||||
|
|
||||||
$listener = new WebDebugToolbarListener($this->getTemplatingMock());
|
$listener = new WebDebugToolbarListener($this->getTemplatingMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
|
|
||||||
$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
|
$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function provideRedirects()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(301, true),
|
||||||
|
array(302, true),
|
||||||
|
array(301, false),
|
||||||
|
array(302, false),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,9 +185,8 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
|
$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html')
|
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html', $hasSession = true)
|
||||||
{
|
{
|
||||||
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session', array(), array(), '', false);
|
|
||||||
$request = $this->getMock(
|
$request = $this->getMock(
|
||||||
'Symfony\Component\HttpFoundation\Request',
|
'Symfony\Component\HttpFoundation\Request',
|
||||||
array('getSession', 'isXmlHttpRequest', 'getRequestFormat'),
|
array('getSession', 'isXmlHttpRequest', 'getRequestFormat'),
|
||||||
@ -189,9 +198,13 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$request->expects($this->any())
|
$request->expects($this->any())
|
||||||
->method('getRequestFormat')
|
->method('getRequestFormat')
|
||||||
->will($this->returnValue($requestFormat));
|
->will($this->returnValue($requestFormat));
|
||||||
$request->expects($this->any())
|
|
||||||
->method('getSession')
|
if ($hasSession) {
|
||||||
->will($this->returnValue($session));
|
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session', array(), array(), '', false);
|
||||||
|
$request->expects($this->any())
|
||||||
|
->method('getSession')
|
||||||
|
->will($this->returnValue($session));
|
||||||
|
}
|
||||||
|
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user