summaryrefslogtreecommitdiffstats
path: root/Http/Tests/Firewall
diff options
context:
space:
mode:
Diffstat (limited to 'Http/Tests/Firewall')
-rw-r--r--Http/Tests/Firewall/ContextListenerTest.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/Http/Tests/Firewall/ContextListenerTest.php b/Http/Tests/Firewall/ContextListenerTest.php
index cb9685a..ae1199a 100644
--- a/Http/Tests/Firewall/ContextListenerTest.php
+++ b/Http/Tests/Firewall/ContextListenerTest.php
@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Firewall\ContextListener;
+use Symfony\Component\EventDispatcher\EventDispatcher;
class ContextListenerTest extends \PHPUnit_Framework_TestCase
{
@@ -99,7 +100,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($tokenStorage, array(), 'session');
+ $listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertTrue($session->isStarted());
@@ -118,7 +119,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener(new TokenStorage(), array(), 'session');
+ $listener = new ContextListener(new TokenStorage(), array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertFalse($session->isStarted());
@@ -190,6 +191,35 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($event);
}
+ public function testOnKernelResponseListenerRemovesItself()
+ {
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
+
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $request->expects($this->any())
+ ->method('hasSession')
+ ->will($this->returnValue(true));
+
+ $event->expects($this->any())
+ ->method('isMasterRequest')
+ ->will($this->returnValue(true));
+ $event->expects($this->any())
+ ->method('getRequest')
+ ->will($this->returnValue($request));
+
+ $dispatcher->expects($this->once())
+ ->method('removeListener')
+ ->with(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
+
+ $listener->onKernelResponse($event);
+ }
+
public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -229,7 +259,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($tokenStorage, array(), 'session');
+ $listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
return $session;