@@ -148,12 +148,25 @@ public function testNoCache(): void
148148 $ this ->assertSame ('private, no-transform, no-store, must-revalidate ' , $ response ->getHeaderLine ('Cache-control ' ));
149149 }
150150
151- public function testCantSetCache (): void
151+ public function testSetCache (): void
152152 {
153153 $ response = new DownloadResponse ('unit-test.txt ' , true );
154154
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 ' ));
157170 }
158171
159172 public function testWhenFilepathIsSetBinaryCanNotBeSet (): void
@@ -200,30 +213,53 @@ public function testCanGetContentLength(): void
200213 $ this ->assertSame ($ size , $ response ->getContentLength ());
201214 }
202215
203- public function testIsSetDownloadableHeadlersFromBinary (): void
216+ public function testIsSetDownloadableHeadersFromBinary (): void
204217 {
205218 $ response = new DownloadResponse ('unit test.txt ' , false );
206219
207220 $ response ->setBinary ('test ' );
208221 $ response ->buildHeaders ();
209222
223+ $ this ->assertSame ('private, no-transform, no-store, must-revalidate ' , $ response ->getHeaderLine ('Cache-Control ' ));
210224 $ this ->assertSame ('application/octet-stream ' , $ response ->getHeaderLine ('Content-Type ' ));
211225 $ 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 ' ));
213226 $ this ->assertSame ('binary ' , $ response ->getHeaderLine ('Content-Transfer-Encoding ' ));
214227 $ this ->assertSame ('4 ' , $ response ->getHeaderLine ('Content-Length ' ));
215228 }
216229
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
218245 {
219246 $ response = new DownloadResponse ('unit-test.php ' , false );
220247
221248 $ 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 ' );
222255 $ response ->buildHeaders ();
223256
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 ' ));
224261 $ this ->assertSame ('application/octet-stream ' , $ response ->getHeaderLine ('Content-Type ' ));
225262 $ 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 ' ));
227263 $ this ->assertSame ('binary ' , $ response ->getHeaderLine ('Content-Transfer-Encoding ' ));
228264 $ this ->assertSame (filesize (__FILE__ ), (int ) $ response ->getHeaderLine ('Content-Length ' ));
229265 }
0 commit comments