class BoxesAjaxTestCase

  1. nittany7 modules/contrib/boxes/tests/boxes.test BoxesAjaxTestCase
  2. cis7 modules/contrib/boxes/tests/boxes.test BoxesAjaxTestCase
  3. mooc7 modules/contrib/boxes/tests/boxes.test BoxesAjaxTestCase

Hierarchy

Expanded class hierarchy of BoxesAjaxTestCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
BoxesAjaxTestCase::ajaxLoadBoxesBlock function Load a block via the context ajax callback and set the payload as the content for simpletest.
BoxesAjaxTestCase::parseJSON function Parse JSON that was generated by drupal_to_js

File

modules/contrib/boxes/tests/boxes.test, line 57

View source
class BoxesAjaxTestCase extends DrupalWebTestCase {
  /**
   * Parse JSON that was generated by drupal_to_js
   *
   * Because of peculiarities of drupal_to_js we need to prepare our json
   * for parsing.
   */
  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("\x27"), $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;
  }

  /**
   * Load a block via the context ajax callback and set the payload as the
   * content for simpletest.
   */
  function ajaxLoadBoxesBlock($delta, $path = 'node') {
    $this->drupalGet($path, array('query' => array('boxes_delta' => $delta)));
    $response = $this->parseJSON();
    $block = NULL;
    foreach ($response as $command) {
      if (($command->command == 'insert') && ($command->method == 'replaceWith')) {
        $block = $command->data;
        break;
      }
    }

    if ($block) {
      $this->pass("Loaded block");

      // Replace contents of the reponse with the decoded JSON
      $this->content = $block;
    }
    else {
      $this->fail('Failed to load block');
    }
  }
}