Add content type headers
This commit is contained in:
parent
88fd8be833
commit
8d5c16fc29
@ -53,7 +53,9 @@ abstract class Controller
|
||||
*/
|
||||
public function render(string $templateName, array $data = []): Response
|
||||
{
|
||||
return $this->view->render($this->response, $templateName, $data);
|
||||
return $this->view
|
||||
->render($this->response, $templateName, $data)
|
||||
->withHeader('Content-Type', 'text/html');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +67,7 @@ abstract class Controller
|
||||
{
|
||||
$renderedTemplate = $this->view->fetchFromString($html, $data);
|
||||
$this->response->getBody()->write($renderedTemplate);
|
||||
return $this->response;
|
||||
return $this->response->withHeader('Content-Type', 'text/html');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,4 +28,29 @@ class ControllerTest extends TestCase
|
||||
|
||||
$this->assertEquals('<p>Dave</p>', $response->getBody());
|
||||
}
|
||||
|
||||
public function testHtmlInlineResponseCodes(): void
|
||||
{
|
||||
$testController = new class extends Controller {
|
||||
public function respond(): Response
|
||||
{
|
||||
$response = $this->renderInline(
|
||||
'<p>{{ name }}</p>',
|
||||
[ 'name' => 'Oh no!' ]
|
||||
);
|
||||
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
};
|
||||
|
||||
$app = $this->getAppInstance();
|
||||
$app->get('/test', $testController);
|
||||
|
||||
$request = $this->createRequest('GET', '/test');
|
||||
$response = $app->handle($request);
|
||||
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
$this->assertEquals('<p>Oh no!</p>', $response->getBody());
|
||||
$this->assertEquals('text/html', $response->getHeaderLine('Content-Type'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user