@@ -38,6 +38,7 @@ class SessionListenerTest extends TestCase
38
38
{
39
39
/**
40
40
* @dataProvider provideSessionOptions
41
+ *
41
42
* @runInSeparateProcess
42
43
*/
43
44
public function testSessionCookieOptions (array $ phpSessionOptions , array $ sessionOptions , array $ expectedSessionOptions )
@@ -554,6 +555,64 @@ public function testUninitializedSessionWithoutInitializedSession()
554
555
$ this ->assertSame ('60 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
555
556
}
556
557
558
+ public function testResponseHeadersMaxAgeAndExpiresNotBeOverridenIfSessionStarted ()
559
+ {
560
+ $ session = $ this ->createMock (Session::class);
561
+ $ session ->expects ($ this ->exactly (2 ))->method ('getUsageIndex ' )->will ($ this ->onConsecutiveCalls (0 , 1 ));
562
+
563
+ $ container = new Container ();
564
+ $ container ->set ('initialized_session ' , $ session );
565
+
566
+ $ listener = new SessionListener ($ container );
567
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
568
+
569
+ $ request = new Request ();
570
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
571
+
572
+ $ response = new Response ();
573
+ $ response ->setPrivate ();
574
+ $ expiresHeader = gmdate ('D, d M Y H:i:s ' , time () + 600 ).' GMT ' ;
575
+ $ response ->setMaxAge (600 );
576
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , new Request (), HttpKernelInterface::MAIN_REQUEST , $ response ));
577
+
578
+ $ this ->assertTrue ($ response ->headers ->has ('expires ' ));
579
+ $ this ->assertSame ($ expiresHeader , $ response ->headers ->get ('expires ' ));
580
+ $ this ->assertFalse ($ response ->headers ->has ('max-age ' ));
581
+ $ this ->assertSame ('600 ' , $ response ->headers ->getCacheControlDirective ('max-age ' ));
582
+ $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('public ' ));
583
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('private ' ));
584
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('must-revalidate ' ));
585
+ $ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
586
+ }
587
+
588
+ public function testResponseHeadersMaxAgeAndExpiresDefaultValuesIfSessionStarted ()
589
+ {
590
+ $ session = $ this ->createMock (Session::class);
591
+ $ session ->expects ($ this ->exactly (2 ))->method ('getUsageIndex ' )->will ($ this ->onConsecutiveCalls (0 , 1 ));
592
+
593
+ $ container = new Container ();
594
+ $ container ->set ('initialized_session ' , $ session );
595
+
596
+ $ listener = new SessionListener ($ container );
597
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
598
+
599
+ $ request = new Request ();
600
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
601
+
602
+ $ response = new Response ();
603
+ $ expiresHeader = gmdate ('D, d M Y H:i:s ' , time ()).' GMT ' ;
604
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , new Request (), HttpKernelInterface::MAIN_REQUEST , $ response ));
605
+
606
+ $ this ->assertTrue ($ response ->headers ->has ('expires ' ));
607
+ $ this ->assertSame ($ expiresHeader , $ response ->headers ->get ('expires ' ));
608
+ $ this ->assertFalse ($ response ->headers ->has ('max-age ' ));
609
+ $ this ->assertSame ('0 ' , $ response ->headers ->getCacheControlDirective ('max-age ' ));
610
+ $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('public ' ));
611
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('private ' ));
612
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('must-revalidate ' ));
613
+ $ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
614
+ }
615
+
557
616
public function testSurrogateMainRequestIsPublic ()
558
617
{
559
618
$ session = $ this ->createMock (Session::class);
0 commit comments