Commit 22c915f3 authored by catch's avatar catch

Issue #2502865 by claudiu.cristea: Remove all remaining usages of the drupal_ajax accept header

parent d1ae9b77
...@@ -102,7 +102,7 @@ public function testUserWithPermission() { ...@@ -102,7 +102,7 @@ public function testUserWithPermission() {
// Ensure the text is transformed. // Ensure the text is transformed.
$this->assertRaw('<p>Do you also love Drupal?</p><figure role="group" class="caption caption-img"><img src="druplicon.png" /><figcaption>Druplicon</figcaption></figure>'); $this->assertRaw('<p>Do you also love Drupal?</p><figure role="group" class="caption caption-img"><img src="druplicon.png" /><figcaption>Druplicon</figcaption></figure>');
$response = $this->drupalPost('editor/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', array()); $response = $this->drupalPost('editor/' . 'node/1/body/en/full', '', [], ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The untransformed text POST request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The untransformed text POST request results in one AJAX command.');
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\quickedit\Tests; namespace Drupal\quickedit\Tests;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
...@@ -130,7 +131,7 @@ public function testAutocompleteQuickEdit() { ...@@ -130,7 +131,7 @@ public function testAutocompleteQuickEdit() {
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full'; $quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for // Prepare form values for submission. drupalPostAJAX() is not suitable for
...@@ -148,7 +149,7 @@ public function testAutocompleteQuickEdit() { ...@@ -148,7 +149,7 @@ public function testAutocompleteQuickEdit() {
); );
// Submit field form and check response. Should render back all the terms. // Submit field form and check response. Should render back all the terms.
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->setRawContent($ajax_commands[0]['data']); $this->setRawContent($ajax_commands[0]['data']);
...@@ -161,7 +162,7 @@ public function testAutocompleteQuickEdit() { ...@@ -161,7 +162,7 @@ public function testAutocompleteQuickEdit() {
// PrivateTempStore. // PrivateTempStore.
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full'; $quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
// The AjaxResponse's first command is an InsertCommand which contains // The AjaxResponse's first command is an InsertCommand which contains
......
...@@ -188,7 +188,7 @@ public function testUserWithPermission() { ...@@ -188,7 +188,7 @@ public function testUserWithPermission() {
// 1. a settings command with useless metadata: AjaxController is dumb // 1. a settings command with useless metadata: AjaxController is dumb
// 2. an insert command that loads the required in-place editors // 2. an insert command that loads the required in-place editors
$post = array('editors[0]' => 'form') + $this->getAjaxPageStatePostData(); $post = array('editors[0]' => 'form') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/attachments', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/attachments', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(2, count($ajax_commands), 'The attachments HTTP request results in two AJAX commands.'); $this->assertIdentical(2, count($ajax_commands), 'The attachments HTTP request results in two AJAX commands.');
// First command: settings. // First command: settings.
...@@ -200,7 +200,7 @@ public function testUserWithPermission() { ...@@ -200,7 +200,7 @@ public function testUserWithPermission() {
// Retrieving the form for this field should result in a 200 response, // Retrieving the form for this field should result in a 200 response,
// containing only a quickeditFieldForm command. // containing only a quickeditFieldForm command.
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -228,7 +228,7 @@ public function testUserWithPermission() { ...@@ -228,7 +228,7 @@ public function testUserWithPermission() {
// Submit field form and check response. This should store the updated // Submit field form and check response. This should store the updated
// entity in PrivateTempStore on the server. // entity in PrivateTempStore on the server.
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -270,7 +270,7 @@ public function testUserWithPermission() { ...@@ -270,7 +270,7 @@ public function testUserWithPermission() {
// Retrieve field form. // Retrieve field form.
$post = array('nocssjs' => 'true', 'reset' => 'true'); $post = array('nocssjs' => 'true', 'reset' => 'true');
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -287,7 +287,7 @@ public function testUserWithPermission() { ...@@ -287,7 +287,7 @@ public function testUserWithPermission() {
'form_build_id' => $build_id_match[1], 'form_build_id' => $build_id_match[1],
); );
$post += $edit + $this->getAjaxPageStatePostData(); $post += $edit + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -345,7 +345,7 @@ public function testTitleBaseField() { ...@@ -345,7 +345,7 @@ public function testTitleBaseField() {
// Retrieving the form for this field should result in a 200 response, // Retrieving the form for this field should result in a 200 response,
// containing only a quickeditFieldForm command. // containing only a quickeditFieldForm command.
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -372,7 +372,7 @@ public function testTitleBaseField() { ...@@ -372,7 +372,7 @@ public function testTitleBaseField() {
// Submit field form and check response. This should store the // Submit field form and check response. This should store the
// updated entity in PrivateTempStore on the server. // updated entity in PrivateTempStore on the server.
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -424,7 +424,7 @@ public function testCustomPipeline() { ...@@ -424,7 +424,7 @@ public function testCustomPipeline() {
// Request editing to render results with the custom render pipeline. // Request editing to render results with the custom render pipeline.
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost($custom_render_url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for // Prepare form values for submission. drupalPostAJAX() is not suitable for
...@@ -448,7 +448,7 @@ public function testCustomPipeline() { ...@@ -448,7 +448,7 @@ public function testCustomPipeline() {
// Submit field form and check response. Should render with the custom // Submit field form and check response. Should render with the custom
// render pipeline. // render pipeline.
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost($custom_render_url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
...@@ -468,7 +468,7 @@ public function testConcurrentEdit() { ...@@ -468,7 +468,7 @@ public function testConcurrentEdit() {
$this->drupalLogin($this->editorUser); $this->drupalLogin($this->editorUser);
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
...@@ -496,7 +496,7 @@ public function testConcurrentEdit() { ...@@ -496,7 +496,7 @@ public function testConcurrentEdit() {
// Submit field form and check response. Should throw a validation error // Submit field form and check response. Should throw a validation error
// because the node was changed in the meantime. // because the node was changed in the meantime.
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical(2, count($ajax_commands), 'The field form HTTP request results in two AJAX commands.'); $this->assertIdentical(2, count($ajax_commands), 'The field form HTTP request results in two AJAX commands.');
...@@ -560,7 +560,7 @@ public function testImageField() { ...@@ -560,7 +560,7 @@ public function testImageField() {
], t('Save')); ], t('Save'));
// The image field form should load normally. // The image field form should load normally.
$response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', 'application/vnd.drupal-ajax', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData()); $response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', '', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData(), ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200); $this->assertResponse(200);
$ajax_commands = Json::decode($response); $ajax_commands = Json::decode($response);
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.'); $this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.');
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\rest\Tests\Views; namespace Drupal\rest\Tests\Views;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
...@@ -500,8 +501,7 @@ public function testFieldRawOutput() { ...@@ -500,8 +501,7 @@ public function testFieldRawOutput() {
public function testLivePreview() { public function testLivePreview() {
// We set up a request so it looks like an request in the live preview. // We set up a request so it looks like an request in the live preview.
$request = new Request(); $request = new Request();
$request->setFormat('drupal_ajax', 'application/vnd.drupal-ajax'); $request->query->add([MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']);
$request->headers->set('Accept', 'application/vnd.drupal-ajax');
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */ /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
$request_stack = \Drupal::service('request_stack'); $request_stack = \Drupal::service('request_stack');
$request_stack->push($request); $request_stack->push($request);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\views\Tests; namespace Drupal\views\Tests;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
/** /**
* Tests the ajax view functionality. * Tests the ajax view functionality.
...@@ -46,7 +47,7 @@ public function testAjaxView() { ...@@ -46,7 +47,7 @@ public function testAjaxView() {
'view_display_id' => 'page_1', 'view_display_id' => 'page_1',
); );
$post += $this->getAjaxPageStatePostData(); $post += $this->getAjaxPageStatePostData();
$response = $this->drupalPost('views/ajax', 'application/vnd.drupal-ajax', $post); $response = $this->drupalPost('views/ajax', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$data = Json::decode($response); $data = Json::decode($response);
$this->assertTrue(isset($data[0]['settings']['views']['ajaxViews'])); $this->assertTrue(isset($data[0]['settings']['views']['ajaxViews']));
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\views_ui\Tests; namespace Drupal\views_ui\Tests;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
/** /**
* Tests the UI preview functionality. * Tests the UI preview functionality.
...@@ -324,7 +325,7 @@ protected function clickPreviewLinkAJAX($url, $row_count) { ...@@ -324,7 +325,7 @@ protected function clickPreviewLinkAJAX($url, $row_count) {
); );
$url = $this->getAbsoluteUrl($url); $url = $this->getAbsoluteUrl($url);
$post = array('js' => 'true') + $this->getAjaxPageStatePostData(); $post = array('js' => 'true') + $this->getAjaxPageStatePostData();
$result = Json::decode($this->drupalPost($url, 'application/vnd.drupal-ajax', $post)); $result = Json::decode($this->drupalPost($url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]));
if (!empty($result)) { if (!empty($result)) {
$this->drupalProcessAjaxResponse($content, $result, $ajax_settings, $drupal_settings); $this->drupalProcessAjaxResponse($content, $result, $ajax_settings, $drupal_settings);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment