Issue #2093173 by longwave, Cyberschorsch, forbesgraham, sandipmkhairnar, damiankloip, rbayliss, grom358, harijari, InternetDevels, dawehner: Remove all calls to drupal_json_decode(), use \Drupal\Component\Utility\Json::decode().

8.0.x
Alex Pott 2014-03-20 16:06:41 +00:00
parent 2252ba8e80
commit 880f697abb
27 changed files with 88 additions and 59 deletions

View File

@ -7,6 +7,7 @@
namespace Drupal\block\Tests\Views;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\String;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
@ -293,7 +294,7 @@ class DisplayBlockTest extends ViewTestBase {
$post = array('ids[0]' => $id);
$response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-page')));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="views-uiedit"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
}

View File

@ -7,6 +7,7 @@
namespace Drupal\comment\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Core\Language\Language;
use Drupal\comment\CommentInterface;
@ -116,7 +117,7 @@ class CommentNewIndicatorTest extends CommentTestBase {
$this->assertIdentical(1, count($this->xpath('//*[@data-history-node-field-name="comment"]')), 'data-history-node-field-name attribute is set to the correct value.');
$response = $this->renderNewCommentsNodeLinks(array($this->node->id()));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$expected = array($this->node->id() => array(
'new_comment_count' => 1,
'first_new_comment_link' => url('node/' . $this->node->id(), array('fragment' => 'new')),

View File

@ -5,6 +5,7 @@
* Adds contextual links to perform actions related to elements on a page.
*/
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Template\Attribute;
@ -240,7 +241,7 @@ function contextual_pre_render_links($element) {
function contextual_contextual_links_view_alter(&$element, $items) {
if (isset($element['#contextual_links']['contextual'])) {
$encoded_links = $element['#contextual_links']['contextual']['metadata']['contextual-views-field-links'];
$element['#links'] = drupal_json_decode(rawurldecode($encoded_links));
$element['#links'] = Json::decode(rawurldecode($encoded_links));
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\contextual\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Template\Attribute;
@ -77,7 +78,7 @@ class ContextualDynamicContextTest extends WebTestBase {
$this->assertRaw('No contextual ids specified.');
$response = $this->renderContextualLinks($ids, 'node');
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json[$ids[0]], '<ul class="contextual-links"><li class="nodepage-edit"><a href="' . base_path() . 'node/1/edit">Edit</a></li></ul>');
$this->assertIdentical($json[$ids[1]], '');
$this->assertIdentical($json[$ids[2]], '<ul class="contextual-links"><li class="nodepage-edit"><a href="' . base_path() . 'node/3/edit">Edit</a></li></ul>');
@ -94,7 +95,7 @@ class ContextualDynamicContextTest extends WebTestBase {
$this->assertRaw('No contextual ids specified.');
$response = $this->renderContextualLinks($ids, 'node');
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json[$ids[0]], '');
$this->assertIdentical($json[$ids[1]], '');
$this->assertIdentical($json[$ids[2]], '');

View File

@ -7,6 +7,7 @@
namespace Drupal\edit\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
@ -142,7 +143,7 @@ class EditAutocompleteTermTest extends WebTestBase {
$edit_uri = 'edit/form/node/'. $this->node->id() . '/' . $this->field_name . '/und/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($edit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
// handling pages with JSON responses, so we need our own solution here.
@ -161,7 +162,7 @@ class EditAutocompleteTermTest extends WebTestBase {
// Submit field form and check response. Should render back all the terms.
$response = $this->drupalPost($edit_uri, 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
$this->drupalSetContent($ajax_commands[0]['data']);
$this->assertLink($this->term1->getName());
$this->assertLink($this->term2->getName());
@ -172,7 +173,7 @@ class EditAutocompleteTermTest extends WebTestBase {
$edit_uri = 'edit/form/node/'. $this->node->id() . '/' . $this->field_name . '/und/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($edit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
// The AjaxResponse's first command is an InsertCommand which contains
// the form to edit the taxonomy term field, it should contain all three

View File

@ -7,6 +7,7 @@
namespace Drupal\edit\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
use Drupal\edit\Ajax\MetadataCommand;
use Drupal\Core\Ajax\AppendCommand;
@ -159,7 +160,7 @@ class EditLoadingTest extends WebTestBase {
'aria' => 'Entity node 1, field Body',
)
);
$this->assertIdentical(drupal_json_decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
$this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
// Restore drupalSettings to build the next requests; simpletest wipes them
// after a JSON response.
$this->drupalSettings = $htmlPageDrupalSettings;
@ -169,7 +170,7 @@ class EditLoadingTest extends WebTestBase {
// 2. an insert command that loads the required in-place editors
$post = array('editors[0]' => 'form') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('edit/attachments', 'application/vnd.drupal-ajax', $post);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
$this->assertIdentical(2, count($ajax_commands), 'The attachments HTTP request results in two AJAX commands.');
// First command: settings.
$this->assertIdentical('settings', $ajax_commands[0]['command'], 'The first AJAX command is a settings command.');
@ -183,7 +184,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('edit/form/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldForm command.');
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The editFieldForm command contains a form.');
@ -211,7 +212,7 @@ class EditLoadingTest extends WebTestBase {
// entity in TempStore on the server.
$response = $this->drupalPost('edit/form/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'Fine thanks.'), 'Form value saved and printed back.');
@ -225,7 +226,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true');
$response = $this->drupalPost('edit/entity/' . 'node/1', 'application/json', $post);
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The entity submission HTTP request results in one AJAX command.');
$this->assertIdentical('editEntitySaved', $ajax_commands[0]['command'], 'The first AJAX command is an editEntitySaved command.');
$this->assertIdentical($ajax_commands[0]['data']['entity_type'], 'node', 'Saved entity is of type node.');
@ -252,7 +253,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true', 'reset' => 'true');
$response = $this->drupalPost('edit/form/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldForm command.');
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The editFieldForm command contains a form.');
@ -271,7 +272,7 @@ class EditLoadingTest extends WebTestBase {
// @todo Uncomment the below once https://drupal.org/node/2063303 is fixed.
// $this->assertIdentical('[]', $response);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'kthxbye'), 'Form value saved and printed back.');
@ -311,7 +312,7 @@ class EditLoadingTest extends WebTestBase {
'aria' => 'Entity node 1, field Title',
)
);
$this->assertIdentical(drupal_json_decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
$this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
// Restore drupalSettings to build the next requests; simpletest wipes them
// after a JSON response.
$this->drupalSettings = $htmlPageDrupalSettings;
@ -321,7 +322,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('edit/form/' . 'node/1/title/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldForm command.');
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The editFieldForm command contains a form.');
@ -348,7 +349,7 @@ class EditLoadingTest extends WebTestBase {
// updated entity in TempStore on the server.
$response = $this->drupalPost('edit/form/' . 'node/1/title/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'Obligatory question'), 'Form value saved and printed back.');
@ -361,7 +362,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true');
$response = $this->drupalPost('edit/entity/' . 'node/1', 'application/json', $post);
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The entity submission HTTP request results in one AJAX command.');
$this->assertIdentical('editEntitySaved', $ajax_commands[0]['command'], 'The first AJAX command is an editEntitySaved command.');
$this->assertIdentical($ajax_commands[0]['data']['entity_type'], 'node', 'Saved entity is of type node.');
@ -411,7 +412,7 @@ class EditLoadingTest extends WebTestBase {
// Request editing to render results with the custom render pipeline.
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
// handling pages with JSON responses, so we need our own solution here.
@ -436,7 +437,7 @@ class EditLoadingTest extends WebTestBase {
// render pipeline.
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'Fine thanks.'), 'Form value saved and printed back.');
@ -455,7 +456,7 @@ class EditLoadingTest extends WebTestBase {
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('edit/form/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
// handling pages with JSON responses, so we need our own solution here.
@ -482,7 +483,7 @@ class EditLoadingTest extends WebTestBase {
// because the node was changed in the meantime.
$response = $this->drupalPost('edit/form/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = drupal_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('editFieldFormValidationErrors', $ajax_commands[1]['command'], 'The second AJAX command is an editFieldFormValidationErrors command.');
$this->assertTrue(strpos($ajax_commands[1]['data'], t('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.')), 'Error message returned to user.');

View File

@ -7,6 +7,7 @@
namespace Drupal\editor\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
@ -113,7 +114,7 @@ class EditIntegrationLoadingTest extends WebTestBase {
$response = $this->drupalPost('editor/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', array());
$this->assertResponse(200);
$ajax_commands = drupal_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('editorGetUntransformedText', $ajax_commands[0]['command'], 'The first AJAX command is an editorGetUntransformedText command.');
$this->assertIdentical('<p>Do you also love Drupal?</p><img src="druplicon.png" data-caption="Druplicon" />', $ajax_commands[0]['data'], 'The editorGetUntransformedText command contains the expected data.');

View File

@ -7,6 +7,7 @@
namespace Drupal\editor\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\String;
@ -387,7 +388,7 @@ class EditorSecurityTest extends WebTestBase {
);
$response = $this->drupalPost('editor/filter_xss/' . $format, 'application/json', $post);
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json, $expected_filtered_value, 'The value was correctly filtered for XSS attack vectors.');
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\entity_reference\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\Tags;
use Drupal\entity_reference\EntityReferenceController;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
@ -130,6 +131,6 @@ class EntityReferenceAutocompleteTest extends EntityUnitTestBase {
$entity_reference_controller = EntityReferenceController::create($this->container);
$result = $entity_reference_controller->handleAutocomplete($request, $type, $this->fieldName, $this->entityType, $this->bundle, 'NULL')->getContent();
return drupal_json_decode($result);
return Json::decode($result);
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\history\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
@ -117,7 +118,7 @@ class HistoryTest extends WebTestBase {
// Retrieve "last read" timestamp for test node, for the current user.
$response = $this->getNodeReadTimestamps(array($nid));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical(array(1 => 0), $json, 'The node has not yet been read.');
// View the node.
@ -130,13 +131,13 @@ class HistoryTest extends WebTestBase {
// Simulate JavaScript: perform HTTP request to mark node as read.
$response = $this->markNodeAsRead($nid);
$this->assertResponse(200);
$timestamp = drupal_json_decode($response);
$timestamp = Json::decode($response);
$this->assertTrue(is_numeric($timestamp), 'Node has been marked as read. Timestamp received.');
// Retrieve "last read" timestamp for test node, for the current user.
$response = $this->getNodeReadTimestamps(array($nid));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical(array(1 => $timestamp), $json, 'The node has been read.');
// Failing to specify node IDs for the first endpoint should return a 404.

View File

@ -7,6 +7,8 @@
namespace Drupal\menu\Tests;
use Drupal\Component\Utility\Json;
/**
* Defines a test class for testing menu and menu link functionality.
*/
@ -474,7 +476,7 @@ class MenuTest extends MenuWebTestBase {
$post = array('ids[0]' => $id);
$response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-page')));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="menu-edit"><a href="' . base_path() . 'admin/structure/menu/manage/tools">Edit menu</a></li></ul>');
}

View File

@ -7,6 +7,8 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
/**
* Tests resource creation on user, node and test entities.
*/
@ -105,7 +107,7 @@ class CreateTest extends RESTTestBase {
$invalid_serialized = $serializer->serialize($entity, $this->defaultFormat);
$response = $this->httpRequest('entity/' . $entity_type, 'POST', $invalid_serialized, $this->defaultMimeType);
$this->assertResponse(422);
$error = drupal_json_decode($response);
$error = Json::decode($response);
$this->assertEqual($error['error'], "Unprocessable Entity: validation failed.\nuuid.0.value: <em class=\"placeholder\">UUID</em>: may not be longer than 128 characters.\n");
// Try to create an entity without proper permissions.

View File

@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
@ -53,7 +54,7 @@ class DBLogTest extends RESTTestBase {
$response = $this->httpRequest("dblog/$id", 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200);
$this->assertHeader('content-type', $this->defaultMimeType);
$log = drupal_json_decode($response);
$log = Json::decode($response);
$this->assertEqual($log['wid'], $id, 'Log ID is correct.');
$this->assertEqual($log['type'], 'rest_test', 'Type of log message is correct.');
$this->assertEqual($log['message'], 'Test message', 'Log message text is correct.');
@ -61,7 +62,7 @@ class DBLogTest extends RESTTestBase {
// Request an unknown log entry.
$response = $this->httpRequest("dblog/9999", 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(404);
$decoded = drupal_json_decode($response);
$decoded = Json::decode($response);
$this->assertEqual($decoded['error'], 'Log entry with ID 9999 was not found', 'Response message is correct.');
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
@ -61,7 +62,7 @@ class DeleteTest extends RESTTestBase {
// Try to delete an entity that does not exist.
$response = $this->httpRequest('entity/' . $entity_type . '/9999', 'DELETE');
$this->assertResponse(404);
$decoded = drupal_json_decode($response);
$decoded = Json::decode($response);
$this->assertEqual($decoded['error'], 'Entity with ID 9999 not found', 'Response message is correct.');
// Try to delete an entity without proper permissions.

View File

@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Core\Language\Language;
use Drupal\rest\Tests\RESTTestBase;
@ -53,7 +54,7 @@ class ReadTest extends RESTTestBase {
$response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse('200', 'HTTP response code is correct.');
$this->assertHeader('content-type', $this->defaultMimeType);
$data = drupal_json_decode($response);
$data = Json::decode($response);
// Only assert one example property here, other properties should be
// checked in serialization tests.
$this->assertEqual($data['uuid'][0]['value'], $entity->uuid(), 'Entity UUID is correct');
@ -65,7 +66,7 @@ class ReadTest extends RESTTestBase {
// Try to read an entity that does not exist.
$response = $this->httpRequest('entity/' . $entity_type . '/9999', 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(404);
$decoded = drupal_json_decode($response);
$decoded = Json::decode($response);
$this->assertEqual($decoded['error'], 'Entity with ID 9999 not found', 'Response message is correct.');
// Make sure that field level access works and that the according field is
@ -77,7 +78,7 @@ class ReadTest extends RESTTestBase {
$response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200);
$this->assertHeader('content-type', $this->defaultMimeType);
$data = drupal_json_decode($response);
$data = Json::decode($response);
$this->assertFalse(isset($data['field_test_text']), 'Field access protected field is not visible in the response.');
}
@ -85,14 +86,14 @@ class ReadTest extends RESTTestBase {
$this->drupalLogout();
$response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(403);
$this->assertNull(drupal_json_decode($response), 'No valid JSON found.');
$this->assertNull(Json::decode($response), 'No valid JSON found.');
}
// Try to read a resource which is not REST API enabled.
$account = $this->drupalCreateUser();
$this->drupalLogin($account);
$response = $this->httpRequest('entity/user/' . $account->id(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(404);
$this->assertNull(drupal_json_decode($response), 'No valid JSON found.');
$this->assertNull(Json::decode($response), 'No valid JSON found.');
}
/**

View File

@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
@ -148,7 +149,7 @@ class UpdateTest extends RESTTestBase {
$invalid_serialized = $serializer->serialize($entity, $this->defaultFormat);
$response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PATCH', $invalid_serialized, $this->defaultMimeType);
$this->assertResponse(422);
$error = drupal_json_decode($response);
$error = Json::decode($response);
$this->assertEqual($error['error'], "Unprocessable Entity: validation failed.\nuuid.0.value: <em class=\"placeholder\">UUID</em>: may not be longer than 128 characters.\n");
// Try to update an entity without proper permissions.

View File

@ -8,6 +8,7 @@
namespace Drupal\simpletest;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\String;
use Drupal\Core\DrupalKernel;
@ -1422,7 +1423,7 @@ abstract class WebTestBase extends TestBase {
*/
protected function drupalGetJSON($path, array $options = array(), array $headers = array()) {
$headers[] = 'Accept: application/json';
return drupal_json_decode($this->drupalGet($path, $options, $headers));
return Json::decode($this->drupalGet($path, $options, $headers));
}
/**
@ -1430,7 +1431,7 @@ abstract class WebTestBase extends TestBase {
*/
protected function drupalGetAJAX($path, array $options = array(), array $headers = array()) {
$headers[] = 'Accept: application/vnd.drupal-ajax';
return drupal_json_decode($this->drupalGet($path, $options, $headers));
return Json::decode($this->drupalGet($path, $options, $headers));
}
/**
@ -1703,7 +1704,7 @@ abstract class WebTestBase extends TestBase {
}
// Submit the POST request.
$return = drupal_json_decode($this->drupalPostForm(NULL, $edit, array('path' => $ajax_path, 'triggering_element' => $triggering_element), $options, $headers, $form_html_id, $extra_post));
$return = Json::decode($this->drupalPostForm(NULL, $edit, array('path' => $ajax_path, 'triggering_element' => $triggering_element), $options, $headers, $form_html_id, $extra_post));
// Change the page content by applying the returned commands.
if (!empty($ajax_settings) && !empty($return)) {
@ -2583,7 +2584,7 @@ abstract class WebTestBase extends TestBase {
$this->elements = FALSE;
$this->drupalSettings = array();
if (preg_match('/var drupalSettings = (.*?);$/m', $content, $matches)) {
$this->drupalSettings = drupal_json_decode($matches[1]);
$this->drupalSettings = Json::decode($matches[1]);
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\Component\Utility\Crypt;
@ -242,7 +243,7 @@ class JavaScriptTest extends DrupalUnitTestBase {
$start = strpos($javascript, $startToken) + strlen($startToken);
$end = strrpos($javascript, $endToken);
$json = drupal_substr($javascript, $start, $end - $start + 1);
$parsed_settings = drupal_json_decode($json);
$parsed_settings = Json::decode($json);
// Test whether the two real world cases are handled correctly.
$settings_two['moduleName']['thingiesOnPage']['id1'] = array();

View File

@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\DrupalUnitTestBase;
/**
@ -1008,7 +1009,7 @@ class RenderTest extends DrupalUnitTestBase {
$start = strpos($html, $startToken) + strlen($startToken);
$end = strrpos($html, $endToken);
$json = drupal_substr($html, $start, $end - $start + 1);
$parsed_settings = drupal_json_decode($json);
$parsed_settings = Json::decode($json);
return $parsed_settings;
}

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
@ -44,14 +45,14 @@ class EmailTest extends WebTestBase {
$edit = array();
$edit['email_required'] = ' foo.bar@example.com ';
$values = drupal_json_decode($this->drupalPostForm('form-test/email', $edit, 'Submit'));
$values = Json::decode($this->drupalPostForm('form-test/email', $edit, 'Submit'));
$this->assertIdentical($values['email'], '');
$this->assertEqual($values['email_required'], 'foo.bar@example.com');
$edit = array();
$edit['email'] = 'foo@example.com';
$edit['email_required'] = 'example@drupal.org';
$values = drupal_json_decode($this->drupalPostForm('form-test/email', $edit, 'Submit'));
$values = Json::decode($this->drupalPostForm('form-test/email', $edit, 'Submit'));
$this->assertEqual($values['email'], 'foo@example.com');
$this->assertEqual($values['email_required'], 'example@drupal.org');
}

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\String;
use Drupal\simpletest\WebTestBase;
@ -273,7 +274,7 @@ class FormTest extends WebTestBase {
$this->assertRaw(t('!name field is required.', array('!name' => 'required_checkbox')), 'A required checkbox is actually mandatory');
// Now try to submit the form correctly.
$values = drupal_json_decode($this->drupalPostForm(NULL, array('required_checkbox' => 1), t('Submit')));
$values = Json::decode($this->drupalPostForm(NULL, array('required_checkbox' => 1), t('Submit')));
$expected_values = array(
'disabled_checkbox_on' => 'disabled_checkbox_on',
'disabled_checkbox_off' => '',
@ -327,7 +328,7 @@ class FormTest extends WebTestBase {
'multiple_no_default_required[]' => 'three',
);
$this->drupalPostForm(NULL, $edit, 'Submit');
$values = drupal_json_decode($this->drupalGetContent());
$values = Json::decode($this->drupalGetContent());
// Verify expected values.
$expected = array(
@ -507,7 +508,7 @@ class FormTest extends WebTestBase {
// Submit the form with no input, as the browser does for disabled elements,
// and fetch the $form_state['values'] that is passed to the submit handler.
$this->drupalPostForm('form-test/disabled-elements', array(), t('Submit'));
$returned_values['normal'] = drupal_json_decode($this->content);
$returned_values['normal'] = Json::decode($this->content);
// Do the same with input, as could happen if JavaScript un-disables an
// element. drupalPostForm() emulates a browser by not submitting input for
@ -529,7 +530,7 @@ class FormTest extends WebTestBase {
)));
$this->drupalPostForm(NULL, $edit, t('Submit'));
$returned_values['hijacked'] = drupal_json_decode($this->content);
$returned_values['hijacked'] = Json::decode($this->content);
// Ensure that the returned values match the form's default values in both
// cases.

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
@ -89,7 +90,7 @@ class LanguageSelectElementTest extends WebTestBase {
// field elements.
$edit = array();
$this->drupalPostForm(NULL, $edit, t('Submit'));
$values = drupal_json_decode($this->drupalGetContent());
$values = Json::decode($this->drupalGetContent());
$this->assertEqual($values['languages_all'], 'xx');
$this->assertEqual($values['languages_configurable'], 'en');
$this->assertEqual($values['languages_locked'], Language::LANGCODE_NOT_SPECIFIED);

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
@ -33,7 +34,7 @@ class StateValuesCleanTest extends WebTestBase {
* Tests form_state_values_clean().
*/
function testFormStateValuesClean() {
$values = drupal_json_decode($this->drupalPostForm('form_test/form-state-values-clean', array(), t('Submit')));
$values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', array(), t('Submit')));
// Setup the expected result.
$result = array(

View File

@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
@ -45,14 +46,14 @@ class UrlTest extends WebTestBase {
$edit = array();
$edit['url'] = "\n";
$edit['url_required'] = 'http://example.com/ ';
$values = drupal_json_decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
$values = Json::decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
$this->assertIdentical($values['url'], '');
$this->assertEqual($values['url_required'], 'http://example.com/');
$edit = array();
$edit['url'] = 'http://foo.bar.example.com/';
$edit['url_required'] = 'http://drupal.org/node/1174630?page=0&foo=bar#new';
$values = drupal_json_decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
$values = Json::decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
$this->assertEqual($values['url'], $edit['url']);
$this->assertEqual($values['url_required'], $edit['url_required']);
}

View File

@ -263,7 +263,7 @@ class TermTest extends TaxonomyTestBase {
$path = 'taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id();
// The result order is not guaranteed, so check each term separately.
$result = $this->drupalGet($path, array('query' => array('q' => $input)));
$data = drupal_json_decode($result);
$data = Json::decode($result);
$this->assertEqual($data[0]['label'], String::checkPlain($first_term->getName()), 'Autocomplete returned the first matching term');
$this->assertEqual($data[1]['label'], String::checkPlain($second_term->getName()), 'Autocomplete returned the second matching term');

View File

@ -7,6 +7,7 @@
namespace Drupal\views_ui\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\String;
use Drupal\views\Views;
@ -188,7 +189,7 @@ class DisplayTest extends UITestBase {
$post = array('ids[0]' => $id);
$response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-display')));
$this->assertResponse(200);
$json = drupal_json_decode($response);
$json = Json::decode($response);
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="views-uiedit"><a href="' . base_path() . 'admin/structure/views/view/test_display/edit/page_1">Edit view</a></li></ul>');
}

View File

@ -7,6 +7,8 @@
namespace Drupal\views_ui\Tests;
use Drupal\Component\Utility\Json;
/**
* Tests the preview form in the UI.
*/
@ -235,7 +237,7 @@ class PreviewTest extends UITestBase {
);
$url = $this->getAbsoluteUrl($url);
$post = array('js' => 'true') + $this->getAjaxPageStatePostData();
$result = drupal_json_decode($this->drupalPost($url, 'application/vnd.drupal-ajax', $post));
$result = Json::decode($this->drupalPost($url, 'application/vnd.drupal-ajax', $post));
if (!empty($result)) {
$this->drupalProcessAjaxResponse($content, $result, $ajax_settings, $drupal_settings);
}