function BoxesAjaxTestCase::parseJSON in Boxes 6
Same name and namespace in other branches
- 7 tests/boxes.test \BoxesAjaxTestCase::parseJSON()
Parse JSON that was generated by drupal_to_js
Because of peculiarities of drupal_to_js we need to prepare our json for parsing.
3 calls to BoxesAjaxTestCase::parseJSON()
- BoxesAjaxTestCase::ajaxLoadBoxesBlock in tests/
boxes.test - Load a block via the context ajax callback and set the payload as the content for simpletest.
- BoxesBasicAjaxTestCase::testAjaxBoxes in tests/
boxes.test - Test creating and deleting a box.
- BoxesSpacesTestCase::runTest in tests/
boxes.test
File
- tests/
boxes.test, line 61
Class
Code
function parseJSON() {
// Step one; undo the "HTML escaping" that drupal does.
$json = str_replace(array(
'\\x3c',
'\\x3e',
'\\x26',
), array(
"<",
">",
"&",
), $this->content);
// Step two; handle our escaped single quotes with extreme care,
$json = str_replace(array(
"\\'",
), array(
"'",
), $json);
// Step three; parse!
$json = json_decode($json);
if (json_last_error() == JSON_ERROR_NONE) {
$this
->pass("Parsed JSON response");
}
else {
$this
->fail("Failed to parse JSON response");
}
return $json;
}