@@ -91,6 +91,50 @@ public function testResponseIsPrivateIfConfigurationIsPublicFalse()
91
91
$ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
92
92
}
93
93
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
+
94
138
public function testResponseVary ()
95
139
{
96
140
$ vary = ['foobar ' ];
@@ -132,6 +176,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
132
176
$ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('max-stale ' ));
133
177
$ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('stale-while-revalidate ' ));
134
178
$ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('stale-if-error ' ));
179
+ $ this ->assertFalse ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
135
180
136
181
$ this ->request ->attributes ->set ('_cache ' , [new Cache (
137
182
expires: 'tomorrow ' ,
@@ -140,6 +185,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
140
185
maxStale: '5 ' ,
141
186
staleWhileRevalidate: '6 ' ,
142
187
staleIfError: '7 ' ,
188
+ noStore: true ,
143
189
)]);
144
190
145
191
$ this ->listener ->onKernelResponse ($ this ->event );
@@ -149,6 +195,7 @@ public function testAttributeConfigurationsAreSetOnResponse()
149
195
$ this ->assertSame ('5 ' , $ this ->response ->headers ->getCacheControlDirective ('max-stale ' ));
150
196
$ this ->assertSame ('6 ' , $ this ->response ->headers ->getCacheControlDirective ('stale-while-revalidate ' ));
151
197
$ this ->assertSame ('7 ' , $ this ->response ->headers ->getCacheControlDirective ('stale-if-error ' ));
198
+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-store ' ));
152
199
$ this ->assertInstanceOf (\DateTimeInterface::class, $ this ->response ->getExpires ());
153
200
}
154
201
0 commit comments