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