diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-18 05:14:39 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-18 05:14:39 +0000 |
commit | 2484439643f86cbc2da3b4f391eb3e23e51fc94d (patch) | |
tree | 97fbddc1ba1f9c1921ea131870acd39ebec7732b /modules/simpletest/tests/ajax_test.module | |
parent | bba83fc6846b1530be180fb56a060fd31d4d13cc (diff) | |
download | brdo-2484439643f86cbc2da3b4f391eb3e23e51fc94d.tar.gz brdo-2484439643f86cbc2da3b4f391eb3e23e51fc94d.tar.bz2 |
#595654 by sun: Fixed AJAX command 'settings' (with tests).
Diffstat (limited to 'modules/simpletest/tests/ajax_test.module')
-rw-r--r-- | modules/simpletest/tests/ajax_test.module | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/modules/simpletest/tests/ajax_test.module b/modules/simpletest/tests/ajax_test.module new file mode 100644 index 000000000..27bf3bf16 --- /dev/null +++ b/modules/simpletest/tests/ajax_test.module @@ -0,0 +1,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); +} + |