summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/common_test.module
blob: e8c6602c23ee79c2fa62a22456118b761e78ab1c (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
// $Id$

/**
 * @file
 * Helper module for the Common tests.
 */

/**
 * Implement hook_menu().
 */
function common_test_menu() {
  $items['common-test/drupal_goto'] = array(
    'title' => 'Drupal Goto',
    'page callback' => 'common_test_drupal_goto_land',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['common-test/drupal_goto/fail'] = array(
    'title' => 'Drupal Goto',
    'page callback' => 'common_test_drupal_goto_land_fail',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['common-test/drupal_goto/redirect'] = array(
    'title' => 'Drupal Goto',
    'page callback' => 'common_test_drupal_goto_redirect',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['common-test/drupal_goto/redirect_fail'] = array(
    'title' => 'Drupal Goto Failure',
    'page callback' => 'drupal_goto',
    'page arguments' => array('common-test/drupal_goto/fail'),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Check that drupal_goto() exits once called.
 */
function common_test_drupal_goto_redirect() {
  drupal_goto('common-test/drupal_goto');
  print t("Drupal goto failed to stop program");
}

/**
 * Landing page for drupal_goto().
 */
function common_test_drupal_goto_land() {
  print "drupal_goto";
}

/**
 * Fail landing page for drupal_goto().
 */
function common_test_drupal_goto_land_fail() {
  print "drupal_goto_fail";
}

/**
 * Implement hook_drupal_goto_alter().
 */
function common_test_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  if ($path == 'common-test/drupal_goto/fail') {
    $path = 'common-test/drupal_goto/redirect';
  }
}

/**
 * Implement hook_TYPE_alter().
 */
function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
  // Alter first argument.
  if (is_array($data)) {
    $data['foo'] = 'Drupal';
  }
  elseif (is_object($data)) {
    $data->foo = 'Drupal';
  }
  // Alter second argument, if present.
  if (isset($arg2)) {
    if (is_array($arg2)) {
      $arg2['foo'] = 'Drupal';
    }
    elseif (is_object($arg2)) {
      $arg2->foo = 'Drupal';
    }
  }
  // Try to alter third argument, if present.
  if (isset($arg3)) {
    if (is_array($arg3)) {
      $arg3['foo'] = 'Drupal';
    }
    elseif (is_object($arg3)) {
      $arg3->foo = 'Drupal';
    }
  }
}

/**
 * Implement hook_TYPE_alter() on behalf of Garland theme.
 *
 * Same as common_test_drupal_alter_alter(), but here, we verify that themes
 * can also alter and come last.
 */
function garland_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
  // Alter first argument.
  if (is_array($data)) {
    $data['foo'] .= ' theme';
  }
  elseif (is_object($data)) {
    $data->foo .= ' theme';
  }
  // Alter second argument, if present.
  if (isset($arg2)) {
    if (is_array($arg2)) {
      $arg2['foo'] .= ' theme';
    }
    elseif (is_object($arg2)) {
      $arg2->foo .= ' theme';
    }
  }
  // Try to alter third argument, if present.
  if (isset($arg3)) {
    if (is_array($arg3)) {
      $arg3['foo'] .= ' theme';
    }
    elseif (is_object($arg3)) {
      $arg3->foo .= ' theme';
    }
  }
}

/**
 * Implement hook_theme().
 */
function common_test_theme() {
  return array(
    'common_test_foo' => array(
      'variables' => array('foo' => 'foo', 'bar' => 'bar'),
    ),
  );
}

/**
 * Theme function for testing drupal_render() theming.
 */
function theme_common_test_foo($variables) {
  return $variables['foo'] . $variables['bar'];
}

/**
 * Implementation of hook_library_alter().
 */
function common_test_library_alter(&$libraries, $module) {
  if ($module == 'system' && isset($libraries['farbtastic'])) {
    // Change the title of Farbtastic to "Farbtastic: Altered Library".
    $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
    // Make Farbtastic depend on jQuery Form to test library dependencies.
    $libraries['farbtastic']['dependencies'][] = array('system', 'form');
  }
}

/**
 * Implementation of hook_library().
 *
 * Adds Farbtastic in a different version.
 */
function common_test_library() {
  $libraries['farbtastic'] = array(
    'title' => 'Custom Farbtastic Library',
    'website' => 'http://code.google.com/p/farbtastic/',
    'version' => '5.3',
    'js' => array(
      'misc/farbtastic/farbtastic.js' => array(),
    ),
    'css' => array(
      'misc/farbtastic/farbtastic.css' => array(),
    ),
  );
  return $libraries;
}