You are here

function BoxesAjaxTestCase::parseJSON in Boxes 7

Same name and namespace in other branches
  1. 6 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_spaces.test

File

tests/boxes.test, line 64

Class

BoxesAjaxTestCase

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);

  // JSON_ERROR_NONE == 0 in PHP 5.3
  $error = function_exists('json_last_error') ? json_last_error() : $json == NULL ? 1 : 0;
  if ($error === 0) {
    $this
      ->pass("Parsed JSON response");
  }
  else {
    $this
      ->fail("Failed to parse JSON response");
  }
  return $json;
}