@@ -56,7 +56,7 @@ public function testSessionIsSet()
56
56
$ this ->assertSame ($ session , $ request ->getSession ());
57
57
}
58
58
59
- public function testResponseIsPrivate ()
59
+ public function testResponseIsPrivateIfSessionStarted ()
60
60
{
61
61
$ session = $ this ->getMockBuilder (Session::class)->disableOriginalConstructor ()->getMock ();
62
62
$ session ->expects ($ this ->exactly (2 ))->method ('isStarted ' )->willReturn (false );
@@ -74,6 +74,31 @@ public function testResponseIsPrivate()
74
74
$ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('private ' ));
75
75
$ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('must-revalidate ' ));
76
76
$ this ->assertSame ('0 ' , $ response ->headers ->getCacheControlDirective ('max-age ' ));
77
+ $ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
78
+ }
79
+
80
+ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent ()
81
+ {
82
+ $ session = $ this ->getMockBuilder (Session::class)->disableOriginalConstructor ()->getMock ();
83
+ $ session ->expects ($ this ->exactly (2 ))->method ('isStarted ' )->willReturn (false );
84
+ $ session ->expects ($ this ->once ())->method ('hasBeenStarted ' )->willReturn (true );
85
+
86
+ $ container = new Container ();
87
+ $ container ->set ('initialized_session ' , $ session );
88
+
89
+ $ listener = new SessionListener ($ container );
90
+ $ kernel = $ this ->getMockBuilder (HttpKernelInterface::class)->disableOriginalConstructor ()->getMock ();
91
+
92
+ $ response = new Response ();
93
+ $ response ->setSharedMaxAge (60 );
94
+ $ response ->headers ->set (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER , 'true ' );
95
+ $ listener ->onKernelResponse (new FilterResponseEvent ($ kernel , new Request (), HttpKernelInterface::MASTER_REQUEST , $ response ));
96
+
97
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('public ' ));
98
+ $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('private ' ));
99
+ $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('must-revalidate ' ));
100
+ $ this ->assertSame ('60 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
101
+ $ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
77
102
}
78
103
79
104
public function testUninitilizedSession ()
0 commit comments