You are here

js_test.module in JS Callback Handler 6

Same filename and directory in other branches
  1. 7 tests/js_test.module

JavaScript callback handler tests.

File

tests/js_test.module
View source
<?php

/**
 * @file
 * JavaScript callback handler tests.
 */

/**
 * Implements hook_js().
 */
function js_test_js() {
  $items = array();
  $items['test_basic'] = array(
    'callback' => 'js_test_basic',
  );
  $items['test_arguments'] = array(
    'callback' => 'js_test_arguments',
    'page arguments' => array(
      1,
      3,
    ),
  );
  $items['test_file'] = array(
    'callback' => 'js_test_file',
    'file' => 'js_test.callbacks.inc',
  );
  return $items;
}

/**
 * Implements hook_init().
 */
function js_test_init() {
  global $js_test_init;

  // Set a global variable to indicate the hook init has been called.
  $js_test_init = TRUE;
}

/**
 * Test callback for the js module.
 */
function js_test_basic() {
  return js_test_response('ok');
}

/**
 * Test callback for the js module.
 */
function js_test_arguments($argument_1, $argument_2) {
  return js_test_response(array(
    'argument_1' => $argument_1,
    'argument_2' => $argument_2,
  ));
}

/**
 * Create a generic response with various data.
 * 
 * @param mixed $response
 * 
 * @return array
 */
function js_test_response($response) {
  global $language, $js_test_init;
  return array(
    'filename' => pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_BASENAME),
    'response' => $response,
    'language' => $language,
    'hook_init' => $js_test_init,
  );
}

Functions

Namesort descending Description
js_test_arguments Test callback for the js module.
js_test_basic Test callback for the js module.
js_test_init Implements hook_init().
js_test_js Implements hook_js().
js_test_response Create a generic response with various data.