diff --git a/composer.json b/composer.json index 02f4ff21db..1ba49841a5 100644 --- a/composer.json +++ b/composer.json @@ -75,7 +75,7 @@ "symfony/css-selector": "^4.4", "symfony/filesystem": "^4.4", "symfony/maker-bundle": "^1.17", - "symfony/phpunit-bridge": "^5.1", + "symfony/phpunit-bridge": "^5.1.1", "symfony/yaml": "^4.4" }, "suggest": { diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 4e03dd1038..d8fc679ea7 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1563,8 +1563,8 @@ private function setFormTheme(FormView $formView, ?array $theme = null): void private function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse { - if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { - @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED); + if (empty(array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes()))) { + @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` or `Accept: */*`', E_USER_DEPRECATED); return null; } @@ -1585,8 +1585,8 @@ private function handleXmlHttpRequestErrorResponse(Request $request, FormInterfa */ private function handleXmlHttpRequestSuccessResponse(Request $request, $object): JsonResponse { - if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) { - @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`', E_USER_DEPRECATED); + if (empty(array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes()))) { + @trigger_error('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` or `Accept: */*`', E_USER_DEPRECATED); } return $this->renderJson([ diff --git a/src/Resources/views/CRUD/Association/edit_many_script.html.twig b/src/Resources/views/CRUD/Association/edit_many_script.html.twig index b6d354dd37..c6c709c169 100644 --- a/src/Resources/views/CRUD/Association/edit_many_script.html.twig +++ b/src/Resources/views/CRUD/Association/edit_many_script.html.twig @@ -279,6 +279,9 @@ This code manages the many-to-[one|many] association field popup jQuery(form).ajaxSubmit({ url: url, type: type, + headers: { + Accept: 'application/json' + }, data: data, success: function(data) { Admin.log('[{{ id }}|field_dialog_form_action] ajax success'); diff --git a/tests/Controller/CRUDControllerTest.php b/tests/Controller/CRUDControllerTest.php index 279d6e3bef..c1e33c30db 100644 --- a/tests/Controller/CRUDControllerTest.php +++ b/tests/Controller/CRUDControllerTest.php @@ -40,6 +40,7 @@ use Sonata\Exporter\Exporter; use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Exporter\Writer\JsonWriter; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine; use Symfony\Component\DependencyInjection\Container; @@ -74,6 +75,8 @@ */ class CRUDControllerTest extends TestCase { + use ExpectDeprecationTrait; + /** * @var CRUDController */ @@ -1665,7 +1668,6 @@ public function testEditActionAjaxError(): void /** * @legacy - * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` */ public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void { @@ -1706,6 +1708,7 @@ public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void ->method('trans') ->willReturn('flash message'); + $this->expectDeprecation('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` or `Accept: */*`'); $this->assertInstanceOf(Response::class, $response = $this->controller->editAction(null)); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']); @@ -2363,7 +2366,6 @@ public function testCreateActionAjaxError(): void /** * @legacy - * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` */ public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void { @@ -2408,6 +2410,7 @@ public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void ->method('trans') ->willReturn('flash message'); + $this->expectDeprecation('In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json` or `Accept: */*`'); $this->assertInstanceOf(Response::class, $response = $this->controller->createAction()); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);