@@ -281,9 +281,51 @@ public function testToPsrCookieAttributes()
281
281
public function testToPsrContentType ()
282
282
{
283
283
$ cake = new CakeResponse ();
284
- $ cake ->type ('js ' );
284
+ $ cake ->type ('html ' );
285
+ $ cake ->charset ('utf-8 ' );
285
286
$ result = ResponseTransformer::toPsr ($ cake );
286
- $ this ->assertSame ('application/javascript ' , $ result ->getHeaderLine ('Content-Type ' ));
287
+ $ this ->assertSame ('text/html; charset=utf-8 ' , $ result ->getHeaderLine ('Content-Type ' ));
288
+ }
289
+
290
+ /**
291
+ * Test conversion omitting content-type on 304 and 204 status codes
292
+ *
293
+ * @return void
294
+ */
295
+ public function testToPsrContentTypeStatusOmission ()
296
+ {
297
+ $ cake = new CakeResponse ();
298
+ $ cake ->type ('html ' );
299
+ $ cake ->statusCode (304 );
300
+ $ result = ResponseTransformer::toPsr ($ cake );
301
+ $ this ->assertSame ('' , $ result ->getHeaderLine ('Content-Type ' ));
302
+
303
+ $ cake ->statusCode (204 );
304
+ $ result = ResponseTransformer::toPsr ($ cake );
305
+ $ this ->assertSame ('' , $ result ->getHeaderLine ('Content-Type ' ));
306
+ }
307
+
308
+ /**
309
+ * Test conversion omitting content-type on 304 and 204 status codes
310
+ *
311
+ * @return void
312
+ */
313
+ public function testToPsrContentTypeCharsetIsTypeSpecific ()
314
+ {
315
+ $ cake = new CakeResponse ();
316
+ $ cake ->charset ('utf-8 ' );
317
+
318
+ $ cake ->type ('text/html ' );
319
+ $ result = ResponseTransformer::toPsr ($ cake );
320
+ $ this ->assertSame ('text/html; charset=utf-8 ' , $ result ->getHeaderLine ('Content-Type ' ));
321
+
322
+ $ cake ->type ('application/octet-stream ' );
323
+ $ result = ResponseTransformer::toPsr ($ cake );
324
+ $ this ->assertSame ('application/octet-stream ' , $ result ->getHeaderLine ('Content-Type ' ));
325
+
326
+ $ cake ->type ('application/json ' );
327
+ $ result = ResponseTransformer::toPsr ($ cake );
328
+ $ this ->assertSame ('application/json; charset=utf-8 ' , $ result ->getHeaderLine ('Content-Type ' ));
287
329
}
288
330
289
331
/**
@@ -302,7 +344,7 @@ public function testToPsrHeaders()
302
344
$ expected = [
303
345
'X-testing ' => ['one ' , 'two ' ],
304
346
'Location ' => ['http://example.com/testing ' ],
305
- 'Content-Type ' => ['text/html ' ],
347
+ 'Content-Type ' => ['text/html; charset=UTF-8 ' ],
306
348
];
307
349
$ this ->assertSame ($ expected , $ result ->getHeaders ());
308
350
}
0 commit comments