14
14
15
15
class ContextListenerTest extends \PHPUnit_Framework_TestCase
16
16
{
17
+ protected function setUp ()
18
+ {
19
+ $ this ->securityContext = new SecurityContext (
20
+ $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface ' ),
21
+ $ this ->getMock ('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface ' )
22
+ );
23
+ }
24
+
25
+ protected function tearDown ()
26
+ {
27
+ unset($ this ->securityContext );
28
+ }
29
+
17
30
public function testOnKernelResponseWillAddSession ()
18
31
{
19
32
$ session = $ this ->runSessionOnKernelResponse (
@@ -56,12 +69,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
56
69
$ session ->set ('_security_session ' , $ original );
57
70
}
58
71
59
-
60
- $ securityContext = new SecurityContext (
61
- $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface ' ),
62
- $ this ->getMock ('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface ' )
63
- );
64
- $ securityContext ->setToken ($ newToken );
72
+ $ this ->securityContext ->setToken ($ newToken );
65
73
66
74
$ request = new Request ();
67
75
$ request ->setSession ($ session );
@@ -73,9 +81,27 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
73
81
new Response ()
74
82
);
75
83
76
- $ listener = new ContextListener ($ securityContext , array (), 'session ' );
84
+ $ listener = new ContextListener ($ this -> securityContext , array (), 'session ' );
77
85
$ listener ->onKernelResponse ($ event );
78
86
79
87
return $ session ;
80
88
}
89
+
90
+ public function testOnKernelResponseWithoutSession ()
91
+ {
92
+ $ this ->securityContext ->setToken (new UsernamePasswordToken ('test1 ' , 'pass1 ' , 'phpunit ' ));
93
+ $ request = new Request ();
94
+
95
+ $ event = new FilterResponseEvent (
96
+ $ this ->getMock ('Symfony\Component\HttpKernel\HttpKernelInterface ' ),
97
+ $ request ,
98
+ HttpKernelInterface::MASTER_REQUEST ,
99
+ new Response ()
100
+ );
101
+
102
+ $ listener = new ContextListener ($ this ->securityContext , array (), 'session ' );
103
+ $ listener ->onKernelResponse ($ event );
104
+
105
+ $ this ->assertFalse ($ request ->hasSession ());
106
+ }
81
107
}
0 commit comments