@@ -148,12 +148,25 @@ public function testNoCache(): void
148
148
$ this ->assertSame ('private, no-transform, no-store, must-revalidate ' , $ response ->getHeaderLine ('Cache-control ' ));
149
149
}
150
150
151
- public function testCantSetCache (): void
151
+ public function testSetCache (): void
152
152
{
153
153
$ response = new DownloadResponse ('unit-test.txt ' , true );
154
154
155
- $ this ->expectException (DownloadException::class);
156
- $ response ->setCache ();
155
+ $ date = date ('r ' );
156
+
157
+ $ options = [
158
+ 'etag ' => '12345678 ' ,
159
+ 'last-modified ' => $ date ,
160
+ 'max-age ' => 300 ,
161
+ 'must-revalidate ' ,
162
+ ];
163
+
164
+ $ response ->setCache ($ options );
165
+ $ response ->buildHeaders ();
166
+
167
+ $ this ->assertSame ('12345678 ' , $ response ->getHeaderLine ('ETag ' ));
168
+ $ this ->assertSame ($ date , $ response ->getHeaderLine ('Last-Modified ' ));
169
+ $ this ->assertSame ('max-age=300, must-revalidate ' , $ response ->getHeaderLine ('Cache-Control ' ));
157
170
}
158
171
159
172
public function testWhenFilepathIsSetBinaryCanNotBeSet (): void
@@ -200,30 +213,53 @@ public function testCanGetContentLength(): void
200
213
$ this ->assertSame ($ size , $ response ->getContentLength ());
201
214
}
202
215
203
- public function testIsSetDownloadableHeadlersFromBinary (): void
216
+ public function testIsSetDownloadableHeadersFromBinary (): void
204
217
{
205
218
$ response = new DownloadResponse ('unit test.txt ' , false );
206
219
207
220
$ response ->setBinary ('test ' );
208
221
$ response ->buildHeaders ();
209
222
223
+ $ this ->assertSame ('private, no-transform, no-store, must-revalidate ' , $ response ->getHeaderLine ('Cache-Control ' ));
210
224
$ this ->assertSame ('application/octet-stream ' , $ response ->getHeaderLine ('Content-Type ' ));
211
225
$ this ->assertSame ('attachment; filename="unit test.txt"; filename*=UTF-8 \'\'unit%20test.txt ' , $ response ->getHeaderLine ('Content-Disposition ' ));
212
- $ this ->assertSame ('0 ' , $ response ->getHeaderLine ('Expires-Disposition ' ));
213
226
$ this ->assertSame ('binary ' , $ response ->getHeaderLine ('Content-Transfer-Encoding ' ));
214
227
$ this ->assertSame ('4 ' , $ response ->getHeaderLine ('Content-Length ' ));
215
228
}
216
229
217
- public function testIsSetDownloadableHeadlersFromFile (): void
230
+ public function testIsSetDownloadableHeadersFromFile (): void
231
+ {
232
+ $ response = new DownloadResponse ('unit-test.php ' , false );
233
+
234
+ $ response ->setFilePath (__FILE__ );
235
+ $ response ->buildHeaders ();
236
+
237
+ $ this ->assertSame ('private, no-transform, no-store, must-revalidate ' , $ response ->getHeaderLine ('Cache-Control ' ));
238
+ $ this ->assertSame ('application/octet-stream ' , $ response ->getHeaderLine ('Content-Type ' ));
239
+ $ this ->assertSame ('attachment; filename="unit-test.php"; filename*=UTF-8 \'\'unit-test.php ' , $ response ->getHeaderLine ('Content-Disposition ' ));
240
+ $ this ->assertSame ('binary ' , $ response ->getHeaderLine ('Content-Transfer-Encoding ' ));
241
+ $ this ->assertSame (filesize (__FILE__ ), (int ) $ response ->getHeaderLine ('Content-Length ' ));
242
+ }
243
+
244
+ public function testCustomHeaders (): void
218
245
{
219
246
$ response = new DownloadResponse ('unit-test.php ' , false );
220
247
221
248
$ response ->setFilePath (__FILE__ );
249
+
250
+ $ response ->setHeader ('Last-Modified ' , 'Fri, 18 Oct 2024 13:17:37 GMT ' );
251
+ $ response ->setHeader ('Expires ' , 'Sun, 17 Nov 2024 14:17:37 GMT ' );
252
+ $ response ->setHeader ('Pragma ' , 'public ' );
253
+ $ response ->removeHeader ('Cache-Control ' );
254
+ $ response ->setHeader ('Cache-Control ' , 'public ' );
222
255
$ response ->buildHeaders ();
223
256
257
+ $ this ->assertSame ('Fri, 18 Oct 2024 13:17:37 GMT ' , $ response ->getHeaderLine ('Last-Modified ' ));
258
+ $ this ->assertSame ('Sun, 17 Nov 2024 14:17:37 GMT ' , $ response ->getHeaderLine ('Expires ' ));
259
+ $ this ->assertSame ('public ' , $ response ->getHeaderLine ('Pragma ' ));
260
+ $ this ->assertSame ('public ' , $ response ->getHeaderLine ('Cache-Control ' ));
224
261
$ this ->assertSame ('application/octet-stream ' , $ response ->getHeaderLine ('Content-Type ' ));
225
262
$ this ->assertSame ('attachment; filename="unit-test.php"; filename*=UTF-8 \'\'unit-test.php ' , $ response ->getHeaderLine ('Content-Disposition ' ));
226
- $ this ->assertSame ('0 ' , $ response ->getHeaderLine ('Expires-Disposition ' ));
227
263
$ this ->assertSame ('binary ' , $ response ->getHeaderLine ('Content-Transfer-Encoding ' ));
228
264
$ this ->assertSame (filesize (__FILE__ ), (int ) $ response ->getHeaderLine ('Content-Length ' ));
229
265
}
0 commit comments