[CORE][Controller][TESTS] Fix issue that arrises in tests where the Accept header is not specified

This commit is contained in:
Hugo Sales 2021-07-28 21:29:27 +00:00
parent 6deac21960
commit 2e3ec15827
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -100,8 +100,9 @@ class Controller extends AbstractController implements EventSubscriberInterface
$template = $this->vars['_template'];
unset($this->vars['_template'], $this->vars['request']);
// Respond in the most preferred acceptable content type
$format = $request->getFormat($request->getAcceptableContentTypes()[0]);
// Respond in the the most preffered acceptable content type
$accept = $request->getAcceptableContentTypes() ?: ['text/html'];
$format = $request->getFormat($accept[0]);
switch ($format) {
case 'html':
$event->setResponse($this->render($template, $this->vars));