@@ -91,6 +91,50 @@ public function testResponseIsPrivateIfConfigurationIsPublicFalse()
9191 $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
9292 }
9393
94+ public function testResponseIsPublicIfConfigurationIsPublicTrueNoStoreFalse ()
95+ {
96+ $ request = $ this ->createRequest (new Cache (public: true , noStore: false ));
97+
98+ $ this ->listener ->onKernelResponse ($ this ->createEventMock ($ request , $ this ->response ));
99+
100+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('public ' ));
101+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
102+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
103+ }
104+
105+ public function testResponseIsPrivateIfConfigurationIsPublicTrueNoStoreTrue ()
106+ {
107+ $ request = $ this ->createRequest (new Cache (public: true , noStore: true ));
108+
109+ $ this ->listener ->onKernelResponse ($ this ->createEventMock ($ request , $ this ->response ));
110+
111+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('public ' ));
112+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
113+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
114+ }
115+
116+ public function testResponseIsPrivateNoStoreIfConfigurationIsNoStoreTrue ()
117+ {
118+ $ request = $ this ->createRequest (new Cache (noStore: true ));
119+
120+ $ this ->listener ->onKernelResponse ($ this ->createEventMock ($ request , $ this ->response ));
121+
122+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('public ' ));
123+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
124+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
125+ }
126+
127+ public function testResponseIsPrivateIfSharedMaxAgeSetAndNoStoreIsTrue ()
128+ {
129+ $ request = $ this ->createRequest (new Cache (smaxage: 1 , noStore: true ));
130+
131+ $ this ->listener ->onKernelResponse ($ this ->createEventMock ($ request , $ this ->response ));
132+
133+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('public ' ));
134+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
135+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
136+ }
137+
94138 public function testResponseVary ()
95139 {
96140 $ vary = ['foobar ' ];
@@ -132,6 +176,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
132176 $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('max-stale ' ));
133177 $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('stale-while-revalidate ' ));
134178 $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('stale-if-error ' ));
179+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
135180
136181 $ this ->request ->attributes ->set ('_cache ' , [new Cache (
137182 expires: 'tomorrow ' ,
@@ -140,6 +185,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
140185 maxStale: '5 ' ,
141186 staleWhileRevalidate: '6 ' ,
142187 staleIfError: '7 ' ,
188+ noStore: true ,
143189 )]);
144190
145191 $ this ->listener ->onKernelResponse ($ this ->event );
@@ -149,6 +195,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
149195 $ this ->assertSame ('5 ' , $ this ->response ->headers ->getCacheControlDirective ('max-stale ' ));
150196 $ this ->assertSame ('6 ' , $ this ->response ->headers ->getCacheControlDirective ('stale-while-revalidate ' ));
151197 $ this ->assertSame ('7 ' , $ this ->response ->headers ->getCacheControlDirective ('stale-if-error ' ));
198+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
152199 $ this ->assertInstanceOf (\DateTimeInterface::class, $ this ->response ->getExpires ());
153200 }
154201
0 commit comments