@@ -181,6 +181,71 @@ public function testOnCoreSecurity()
181
181
$ listener ->handle ($ event );
182
182
}
183
183
184
+ public function testSessionStrategy ()
185
+ {
186
+ list ($ listener , $ tokenStorage , $ service , $ manager , , $ dispatcher , $ sessionStrategy ) = $ this ->getListener (false , true , true );
187
+
188
+ $ tokenStorage
189
+ ->expects ($ this ->once ())
190
+ ->method ('getToken ' )
191
+ ->will ($ this ->returnValue (null ))
192
+ ;
193
+
194
+ $ token = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' );
195
+ $ service
196
+ ->expects ($ this ->once ())
197
+ ->method ('autoLogin ' )
198
+ ->will ($ this ->returnValue ($ token ))
199
+ ;
200
+
201
+ $ tokenStorage
202
+ ->expects ($ this ->once ())
203
+ ->method ('setToken ' )
204
+ ->with ($ this ->equalTo ($ token ))
205
+ ;
206
+
207
+ $ manager
208
+ ->expects ($ this ->once ())
209
+ ->method ('authenticate ' )
210
+ ->will ($ this ->returnValue ($ token ))
211
+ ;
212
+
213
+ $ session = $ this ->getMock ('\Symfony\Component\HttpFoundation\Session\SessionInterface ' );
214
+ $ session
215
+ ->expects ($ this ->once ())
216
+ ->method ('isStarted ' )
217
+ ->will ($ this ->returnValue (true ))
218
+ ;
219
+
220
+ $ request = $ this ->getMock ('\Symfony\Component\HttpFoundation\Request ' );
221
+ $ request
222
+ ->expects ($ this ->once ())
223
+ ->method ('hasSession ' )
224
+ ->will ($ this ->returnValue (true ))
225
+ ;
226
+
227
+ $ request
228
+ ->expects ($ this ->once ())
229
+ ->method ('getSession ' )
230
+ ->will ($ this ->returnValue ($ session ))
231
+ ;
232
+
233
+ $ event = $ this ->getGetResponseEvent ();
234
+ $ event
235
+ ->expects ($ this ->once ())
236
+ ->method ('getRequest ' )
237
+ ->will ($ this ->returnValue ($ request ))
238
+ ;
239
+
240
+ $ sessionStrategy
241
+ ->expects ($ this ->once ())
242
+ ->method ('onAuthentication ' )
243
+ ->will ($ this ->returnValue (null ))
244
+ ;
245
+
246
+ $ listener ->handle ($ event );
247
+ }
248
+
184
249
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent ()
185
250
{
186
251
list ($ listener , $ tokenStorage , $ service , $ manager , , $ dispatcher ) = $ this ->getListener (true );
@@ -240,18 +305,19 @@ protected function getFilterResponseEvent()
240
305
return $ this ->getMock ('Symfony\Component\HttpKernel\Event\FilterResponseEvent ' , array (), array (), '' , false );
241
306
}
242
307
243
- protected function getListener ($ withDispatcher = false , $ catchExceptions = true )
308
+ protected function getListener ($ withDispatcher = false , $ catchExceptions = true , $ withSessionStrategy = false )
244
309
{
245
310
$ listener = new RememberMeListener (
246
311
$ tokenStorage = $ this ->getTokenStorage (),
247
312
$ service = $ this ->getService (),
248
313
$ manager = $ this ->getManager (),
249
314
$ logger = $ this ->getLogger (),
250
315
$ dispatcher = ($ withDispatcher ? $ this ->getDispatcher () : null ),
251
- $ catchExceptions
316
+ $ catchExceptions ,
317
+ $ sessionStrategy = ($ withSessionStrategy ? $ this ->getSessionStrategy () : null )
252
318
);
253
319
254
- return array ($ listener , $ tokenStorage , $ service , $ manager , $ logger , $ dispatcher );
320
+ return array ($ listener , $ tokenStorage , $ service , $ manager , $ logger , $ dispatcher, $ sessionStrategy );
255
321
}
256
322
257
323
protected function getLogger ()
@@ -278,4 +344,9 @@ protected function getDispatcher()
278
344
{
279
345
return $ this ->getMock ('Symfony\Component\EventDispatcher\EventDispatcherInterface ' );
280
346
}
347
+
348
+ private function getSessionStrategy ()
349
+ {
350
+ return $ this ->getMock ('\Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface ' );
351
+ }
281
352
}
0 commit comments