Skip to content

Commit

Permalink
merged branch kriswallsmith/wdt/no-session-fix (PR #3444)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
fabpot committed Feb 27, 2012
2 parents 518b96e + 95ec4eb commit c319ff5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
Expand Up @@ -72,7 +72,7 @@ public function onKernelResponse(FilterResponseEvent $event)

if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
$session = $request->getSession();
if ($session->getFlashBag() instanceof AutoExpireFlashBag) {
if ($session && $session->getFlashBag() instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
Expand Down
Expand Up @@ -51,19 +51,20 @@ public function getInjectToolbarTests()
);
}

public function testRedirectionIsIntercepted()
/**
* @dataProvider provideRedirects
*/
public function testRedirectionIsIntercepted($statusCode, $hasSession)
{
foreach (array(301, 302) as $statusCode) {
$response = new Response('Some content', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$response = new Response('Some content', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTemplatingMock('Redirection'), true);
$listener->onKernelResponse($event);
$listener = new WebDebugToolbarListener($this->getTemplatingMock('Redirection'), true);
$listener->onKernelResponse($event);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Redirection', $response->getContent());
}
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Redirection', $response->getContent());
}

public function testToolbarIsInjected()
Expand All @@ -81,19 +82,28 @@ public function 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->headers->set('X-Debug-Token', 'xxxxxxxx');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$response = new Response('<html><head></head><body></body></html>', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTemplatingMock());
$listener->onKernelResponse($event);
$listener = new WebDebugToolbarListener($this->getTemplatingMock());
$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),
);
}

/**
Expand Down Expand Up @@ -175,9 +185,8 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests()
$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(
'Symfony\Component\HttpFoundation\Request',
array('getSession', 'isXmlHttpRequest', 'getRequestFormat'),
Expand All @@ -189,9 +198,13 @@ protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'h
$request->expects($this->any())
->method('getRequestFormat')
->will($this->returnValue($requestFormat));
$request->expects($this->any())
->method('getSession')
->will($this->returnValue($session));

if ($hasSession) {
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session', array(), array(), '', false);
$request->expects($this->any())
->method('getSession')
->will($this->returnValue($session));
}

return $request;
}
Expand Down

0 comments on commit c319ff5

Please sign in to comment.