- <?php
- * @file
- * Helper module for the Common tests.
- */
-
- * Implements hook_menu().
- */
- function common_test_menu() {
- $items['common-test/backdrop_goto'] = array(
- 'title' => 'Backdrop Goto',
- 'page callback' => 'common_test_backdrop_goto_land',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/backdrop_goto/fail'] = array(
- 'title' => 'Backdrop Goto',
- 'page callback' => 'common_test_backdrop_goto_land_fail',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/backdrop_goto/redirect'] = array(
- 'title' => 'Backdrop Goto',
- 'page callback' => 'common_test_backdrop_goto_redirect',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/backdrop_goto/redirect_advanced'] = array(
- 'title' => 'Backdrop Goto',
- 'page callback' => 'common_test_backdrop_goto_redirect_advanced',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/backdrop_goto/redirect_fail'] = array(
- 'title' => 'Backdrop Goto Failure',
- 'page callback' => 'backdrop_goto',
- 'page arguments' => array('common-test/backdrop_goto/fail'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/destination'] = array(
- 'title' => 'Backdrop Get Destination',
- 'page callback' => 'common_test_destination',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/query-string'] = array(
- 'title' => 'Test querystring',
- 'page callback' => 'common_test_js_and_css_querystring',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/backdrop-render-invalid-keys'] = array(
- 'title' => 'Backdrop Render',
- 'page callback' => 'common_test_backdrop_render_invalid_keys',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['common-test/css-render-inline-full-page'] = array(
- 'title' => 'Test rendering inline stylesheets through a full page request.',
- 'page callback' => 'common_test_render_inline_full_page',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
-
- * Redirect using backdrop_goto().
- */
- function common_test_backdrop_goto_redirect() {
- backdrop_goto('common-test/backdrop_goto');
- }
-
- * Redirect using backdrop_goto().
- */
- function common_test_backdrop_goto_redirect_advanced() {
- backdrop_goto('common-test/backdrop_goto', array('query' => array('foo' => '123')), 301);
- }
-
- * Landing page for backdrop_goto().
- */
- function common_test_backdrop_goto_land() {
- print "backdrop_goto";
- }
-
- * Fail landing page for backdrop_goto().
- */
- function common_test_backdrop_goto_land_fail() {
- print "backdrop_goto_fail";
- }
-
- * Implements hook_backdrop_goto_alter().
- */
- function common_test_backdrop_goto_alter(&$path, &$options, &$http_response_code) {
- if ($path == 'common-test/backdrop_goto/fail') {
- $path = 'common-test/backdrop_goto/redirect';
- }
- }
-
- * Implements hook_init().
- */
- function common_test_init() {
- if (state_get('common_test_redirect_current_path', FALSE)) {
- backdrop_goto(current_path());
- }
- if (state_get('common_test_link_to_current_path', FALSE)) {
- backdrop_set_message(l('link which should point to the current path', current_path()));
- }
- }
-
- * Print destination query parameter.
- */
- function common_test_destination() {
- $destination = backdrop_get_destination();
- print "The destination: " . check_plain($destination['destination']);
- }
-
- * Render an element with an invalid render array key.
- */
- function common_test_backdrop_render_invalid_keys() {
- define('SIMPLETEST_COLLECT_ERRORS', FALSE);
-
-
-
- $key = 'child';
- $value = 'This should be an array.';
- $element = array(
- $key => $value,
- );
- return backdrop_render($element);
- }
-
- * Render a page with inline CSS.
- */
- function common_test_render_inline_full_page() {
- $css = 'body { font-size: 254px; }';
- backdrop_add_css($css, 'inline');
- return 'This tests the inline CSS!';
- }
-
- * Applies #printed to an element to help test #pre_render.
- */
- function common_test_backdrop_render_printing_pre_render($elements) {
- $elements['#printed'] = TRUE;
- return $elements;
- }
-
- * Implements hook_TYPE_alter().
- */
- function common_test_backdrop_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
-
- if (is_array($data)) {
- $data['foo'] = 'Backdrop';
- }
- elseif (is_object($data)) {
- $data->foo = 'Backdrop';
- }
-
- if (isset($arg2)) {
- if (is_array($arg2)) {
- $arg2['foo'] = 'Backdrop';
- }
- elseif (is_object($arg2)) {
- $arg2->foo = 'Backdrop';
- }
- }
-
- if (isset($arg3)) {
- if (is_array($arg3)) {
- $arg3['foo'] = 'Backdrop';
- }
- elseif (is_object($arg3)) {
- $arg3->foo = 'Backdrop';
- }
- }
- }
-
- * Implements hook_TYPE_alter() on behalf of Bartik theme.
- *
- * Same as common_test_backdrop_alter_alter(), but here, we verify that themes
- * can also alter and come last.
- */
- function bartik_backdrop_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
-
- if (is_array($data)) {
- $data['foo'] .= ' theme';
- }
- elseif (is_object($data)) {
- $data->foo .= ' theme';
- }
-
- if (isset($arg2)) {
- if (is_array($arg2)) {
- $arg2['foo'] .= ' theme';
- }
- elseif (is_object($arg2)) {
- $arg2->foo .= ' theme';
- }
- }
-
- if (isset($arg3)) {
- if (is_array($arg3)) {
- $arg3['foo'] .= ' theme';
- }
- elseif (is_object($arg3)) {
- $arg3->foo .= ' theme';
- }
- }
- }
-
- * Implements hook_TYPE_alter() on behalf of block module.
- *
- * This is for verifying that backdrop_alter(array(TYPE1, TYPE2), ...) allows
- * hook_module_implements_alter() to affect the order in which module
- * implementations are executed.
- */
- function block_backdrop_alter_foo_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
- $data['foo'] .= ' block';
- }
-
- * Implements hook_module_implements_alter().
- *
- * @see block_backdrop_alter_foo_alter()
- */
- function common_test_module_implements_alter(&$implementations, $hook) {
-
-
-
-
- if ($hook == 'backdrop_alter_alter' && isset($implementations['block'])) {
- $group = $implementations['block'];
- unset($implementations['block']);
- $implementations['block'] = $group;
- }
- }
-
- * Implements hook_theme().
- */
- function common_test_theme() {
- return array(
- 'common_test_foo' => array(
- 'variables' => array('foo' => 'foo', 'bar' => 'bar'),
- 'file' => 'common_test.theme.inc',
- ),
- );
- }
-
- * Implements hook_library_info_alter().
- */
- function common_test_library_info_alter(&$libraries, $module) {
- if ($module == 'system' && isset($libraries['farbtastic'])) {
-
- $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
-
- $libraries['farbtastic']['dependencies'][] = array('system', 'jquery.form');
- }
- }
-
- * Implements hook_library_info().
- *
- * Adds Farbtastic in a different version.
- */
- function common_test_library_info() {
- $libraries['farbtastic'] = array(
- 'title' => 'Custom Farbtastic Library',
- 'website' => 'http://code.google.com/p/farbtastic/',
- 'version' => '5.3',
- 'js' => array(
- 'core/misc/farbtastic/farbtastic.js' => array(),
- ),
- 'css' => array(
- 'core/misc/farbtastic/farbtastic.css' => array(),
- ),
- );
- return $libraries;
- }
-
- * Adds a JavaScript file and a CSS file with a query string appended.
- */
- function common_test_js_and_css_querystring() {
- backdrop_add_js(backdrop_get_path('module', 'node') . '/js/node.js');
- backdrop_add_css(backdrop_get_path('module', 'node') . '/css/node.admin.css');
-
- backdrop_add_css('/' . backdrop_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
- return '';
- }
-
- * Implements hook_cron().
- *
- * System module should handle if a module does not catch an exception and keep
- * cron going.
- *
- * @see common_test_cron_helper()
- *
- */
- function common_test_cron() {
- throw new Exception(t('Uncaught exception'));
- }