Commit 880f697a authored by alexpott's avatar alexpott
Browse files

Issue #2093173 by longwave, Cyberschorsch, forbesgraham, sandipmkhairnar,...

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().
parent 2252ba8e
......@@ -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 @@ public function testBlockContextualLinks() {
$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>');
}
......
......@@ -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 @@ public function testCommentNewCommentsIndicator() {
$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')),
......
......@@ -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));
}
}
......
......@@ -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 @@ function testDifferentPermissions() {
$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 @@ function testDifferentPermissions() {
$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]], '');
......
......@@ -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 @@ public function testAutocompleteEdit() {
$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 @@ public function testAutocompleteEdit() {
// 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 @@ public function testAutocompleteEdit() {
$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
......
......@@ -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 @@ public function testUserWithPermission() {
'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 @@ public function testUserWithPermission() {
// 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 @@ public function testUserWithPermission() {
$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 @@ public function testUserWithPermission() {
// 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 @@ public function testUserWithPermission() {
$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 @@ public function testUserWithPermission() {
$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 @@ public function testUserWithPermission() {
// @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 @@ public function testTitleBaseField() {
'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 @@ public function testTitleBaseField() {
$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 @@ public function testTitleBaseField() {
// 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 @@ public function testTitleBaseField() {
$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 @@ public function testCustomPipeline() {
// 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 @@ public function testCustomPipeline() {
// 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 @@ public function testConcurrentEdit() {
$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 @@ public function testConcurrentEdit() {
// 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.');
......
......@@ -7,6 +7,7 @@
namespace Drupal\editor\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
......@@ -113,7 +114,7 @@ public function testUserWithPermission() {
$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.');
......
......@@ -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 @@ function testSwitchingSecurity() {
);
$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.');
}
}
......
......@@ -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 @@ protected function getAutocompleteResult($type, $input) {
$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);
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\history\Tests;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
......@@ -117,7 +118,7 @@ function testHistory() {
// 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 @@ function testHistory() {
// 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.
......
......@@ -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 @@ public function testBlockContextualLinks() {
$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>');
}
......
......@@ -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 @@ public function testCreate() {
$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.
......
......@@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
......@@ -53,7 +54,7 @@ public function testWatchdog() {
$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 @@ public function testWatchdog() {
// 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.');
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
......@@ -61,7 +62,7 @@ public function testDelete() {
// 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.
......
......@@ -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 @@ public function testRead() {
$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 @@ public function testRead() {
// 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 @@ public function testRead() {
$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 @@ public function testRead() {
$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.');
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\Json;
use Drupal\rest\Tests\RESTTestBase;
/**
......@@ -148,7 +149,7 @@ public function testPatchUpdate() {
$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.
......
......@@ -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 @@ protected function drupalGet($path, array $options = array(), array $headers = a
*/
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 @@ protected function drupalGetJSON($path, array $options = array(), array $headers
*/
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 @@ protected function drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_p
}
// 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 @@ protected function drupalSetContent($content, $url = 'internal:') {
$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]);
}
}
......
......@@ -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 @@ function testHeaderSetting() {
$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();
......
......@@ -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 @@ protected function parseDrupalSettings($html) {
$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;
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\Json;
use Drupal\simpletest\WebTestBase;
/**
......@@ -44,14 +45,14 @@ function testFormEmail() {
$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'));
</