@@ -207,6 +207,60 @@ public function testReadMedia()
207207 $ emitter ->emit ();
208208 }
209209
210+ public function testReadThumbnail ()
211+ {
212+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
213+ App::$ App ->Path = new Path ('/thumbnail/1 ' );
214+ $ controller = new MediaRequestHandler ();
215+ $ response = $ controller ->handle (ServerRequest::fromGlobals ());
216+ $ media = Media::getByID (1 );
217+ $ this ->expectOutputString (file_get_contents ($ media ->getFilesystemPath ('100x100 ' )));
218+ $ emitter = new Emitter ($ response );
219+ $ this ->assertEquals ('image/png ' , $ response ->getHeader ('Content-Type ' )[0 ]);
220+ $ this ->assertEquals ('public, max-age= 31536000 ' , $ response ->getHeader ('Cache-Control ' )[0 ]);
221+ $ this ->assertEquals (gmdate ('D, d M Y H:i:s \G\M\T ' , time ()+60 *60 *24 *365 ), $ response ->getHeader ('Expires ' )[0 ]);
222+ $ this ->assertEquals ('public ' , $ response ->getHeader ('Pragma ' )[0 ]);
223+ $ emitter ->emit ();
224+ $ size = getimagesizefromstring (file_get_contents ($ media ->getFilesystemPath ('100x100 ' )));
225+ $ this ->assertEquals ([100 ,100 ,3 ,'width="100" height="100" ' ,"bits " =>8 ,"mime " =>"image/png " ], $ size );
226+ }
227+
228+ public function testReadThumbnail10x10 ()
229+ {
230+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
231+ App::$ App ->Path = new Path ('/thumbnail/1/10x10 ' );
232+ $ controller = new MediaRequestHandler ();
233+ $ response = $ controller ->handle (ServerRequest::fromGlobals ());
234+ $ media = Media::getByID (1 );
235+ $ this ->expectOutputString (file_get_contents ($ media ->getFilesystemPath ('10x10 ' )));
236+ $ emitter = new Emitter ($ response );
237+ $ this ->assertEquals ('image/png ' , $ response ->getHeader ('Content-Type ' )[0 ]);
238+ $ this ->assertEquals ('public, max-age= 31536000 ' , $ response ->getHeader ('Cache-Control ' )[0 ]);
239+ $ this ->assertEquals (gmdate ('D, d M Y H:i:s \G\M\T ' , time ()+60 *60 *24 *365 ), $ response ->getHeader ('Expires ' )[0 ]);
240+ $ this ->assertEquals ('public ' , $ response ->getHeader ('Pragma ' )[0 ]);
241+ $ emitter ->emit ();
242+ $ size = getimagesizefromstring (file_get_contents ($ media ->getFilesystemPath ('10x10 ' )));
243+ $ this ->assertEquals ([10 ,10 ,3 ,'width="10" height="10" ' ,"bits " =>8 ,"mime " =>"image/png " ], $ size );
244+ }
245+
246+ public function testReadThumbnail25 ()
247+ {
248+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
249+ App::$ App ->Path = new Path ('/thumbnail/1/25x25 ' );
250+ $ controller = new MediaRequestHandler ();
251+ $ response = $ controller ->handle (ServerRequest::fromGlobals ());
252+ $ media = Media::getByID (1 );
253+ $ this ->expectOutputString (file_get_contents ($ media ->getFilesystemPath ('25x25 ' )));
254+ $ emitter = new Emitter ($ response );
255+ $ this ->assertEquals ('image/png ' , $ response ->getHeader ('Content-Type ' )[0 ]);
256+ $ this ->assertEquals ('public, max-age= 31536000 ' , $ response ->getHeader ('Cache-Control ' )[0 ]);
257+ $ this ->assertEquals (gmdate ('D, d M Y H:i:s \G\M\T ' , time ()+60 *60 *24 *365 ), $ response ->getHeader ('Expires ' )[0 ]);
258+ $ this ->assertEquals ('public ' , $ response ->getHeader ('Pragma ' )[0 ]);
259+ $ emitter ->emit ();
260+ $ size = getimagesizefromstring (file_get_contents ($ media ->getFilesystemPath ('25x25 ' )));
261+ $ this ->assertEquals ([25 ,25 ,3 ,'width="25" height="25" ' ,"bits " =>8 ,"mime " =>"image/png " ], $ size );
262+ }
263+
210264 public function testHttpConditional ()
211265 {
212266 $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
@@ -449,10 +503,6 @@ public function testHTTPRangeMultiPart()
449503 $ this ->assertEquals (416 , $ response ->getStatusCode ());
450504 }
451505
452- /**
453- * @see https://www.zeng.dev/post/2023-http-range-and-play-mp4-in-browser/
454- *
455- */
456506 public function testNotFound ()
457507 {
458508 $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
0 commit comments