summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/ajax_test.module
blob: 27bf3bf169183d62607b3a7ededfcecd8063b678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// $Id$

/**
 * @file
 * Helper module for AJAX framework tests.
 */

/**
 * Implement hook_menu().
 */
function ajax_test_menu() {
  $items['ajax-test/render'] = array(
    'title' => 'ajax_render',
    'page callback' => 'ajax_test_render',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['ajax-test/render-error'] = array(
    'title' => 'ajax_render_error',
    'page callback' => 'ajax_test_render_error',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Menu callback; Copies $_GET['commands'] into $commands and ajax_render()s that.
 *
 * Additionally ensures that ajax_render() incorporates JavaScript settings
 * by invoking drupal_add_js() with a dummy setting.
 */
function ajax_test_render() {
  // Prepare AJAX commands.
  $commands = array();
  if (!empty($_GET['commands'])) {
    $commands = $_GET['commands'];
  }
  // Add a dummy JS setting.
  drupal_add_js(array('ajax' => 'test'), 'setting');

  // Output AJAX commands and end the request.
  ajax_render($commands);
}

/**
 * Menu callback; Invokes ajax_render_error().
 *
 * Optionally passes $_GET['message'] to ajax_render_error().
 */
function ajax_test_render_error() {
  $message = '';
  if (!empty($_GET['message'])) {
    $message = $_GET['message'];
  }
  ajax_render_error($message);
}