Projet

Général

Profil

Paste
Télécharger (7,58 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / common_test.module @ cf490feb

1
<?php
2

    
3
/**
4
 * @file
5
 * Helper module for the Common tests.
6
 */
7

    
8
/**
9
 * Implements hook_menu().
10
 */
11
function common_test_menu() {
12
  $items['common-test/drupal_goto'] = array(
13
    'title' => 'Drupal Goto',
14
    'page callback' => 'common_test_drupal_goto_land',
15
    'access arguments' => array('access content'),
16
    'type' => MENU_CALLBACK,
17
  );
18
  $items['common-test/drupal_goto/fail'] = array(
19
    'title' => 'Drupal Goto',
20
    'page callback' => 'common_test_drupal_goto_land_fail',
21
    'access arguments' => array('access content'),
22
    'type' => MENU_CALLBACK,
23
  );
24
  $items['common-test/drupal_goto/redirect'] = array(
25
    'title' => 'Drupal Goto',
26
    'page callback' => 'common_test_drupal_goto_redirect',
27
    'access arguments' => array('access content'),
28
    'type' => MENU_CALLBACK,
29
  );
30
  $items['common-test/drupal_goto/redirect_advanced'] = array(
31
    'title' => 'Drupal Goto',
32
    'page callback' => 'common_test_drupal_goto_redirect_advanced',
33
    'access arguments' => array('access content'),
34
    'type' => MENU_CALLBACK,
35
  );
36
  $items['common-test/drupal_goto/redirect_fail'] = array(
37
    'title' => 'Drupal Goto Failure',
38
    'page callback' => 'drupal_goto',
39
    'page arguments' => array('common-test/drupal_goto/fail'),
40
    'access arguments' => array('access content'),
41
    'type' => MENU_CALLBACK,
42
  );
43
  $items['common-test/destination'] = array(
44
    'title' => 'Drupal Get Destination',
45
    'page callback' => 'common_test_destination',
46
    'access arguments' => array('access content'),
47
    'type' => MENU_CALLBACK,
48
  );
49
  $items['common-test/query-string'] = array(
50
    'title' => 'Test querystring',
51
    'page callback' => 'common_test_js_and_css_querystring',
52
    'access arguments' => array('access content'),
53
    'type' => MENU_CALLBACK,
54
  );
55
  return $items;
56
}
57

    
58
/**
59
 * Redirect using drupal_goto().
60
 */
61
function common_test_drupal_goto_redirect() {
62
  drupal_goto('common-test/drupal_goto');
63
}
64

    
65
/**
66
 * Redirect using drupal_goto().
67
 */
68
function common_test_drupal_goto_redirect_advanced() {
69
  drupal_goto('common-test/drupal_goto', array('query' => array('foo' => '123')), 301);
70
}
71

    
72
/**
73
 * Landing page for drupal_goto().
74
 */
75
function common_test_drupal_goto_land() {
76
  print "drupal_goto";
77
}
78

    
79
/**
80
 * Fail landing page for drupal_goto().
81
 */
82
function common_test_drupal_goto_land_fail() {
83
  print "drupal_goto_fail";
84
}
85

    
86
/**
87
 * Implements hook_drupal_goto_alter().
88
 */
89
function common_test_drupal_goto_alter(&$path, &$options, &$http_response_code) {
90
  if ($path == 'common-test/drupal_goto/fail') {
91
    $path = 'common-test/drupal_goto/redirect';
92
  }
93
}
94

    
95
/**
96
 * Implements hook_init().
97
 */
98
function common_test_init() {
99
  if (variable_get('common_test_redirect_current_path', FALSE)) {
100
    drupal_goto(current_path());
101
  }
102
  if (variable_get('common_test_link_to_current_path', FALSE)) {
103
    drupal_set_message(l('link which should point to the current path', current_path()));
104
  }
105
}
106

    
107
/**
108
 * Print destination query parameter.
109
 */
110
function common_test_destination() {
111
  $destination = drupal_get_destination();
112
  print "The destination: " . check_plain($destination['destination']);
113
}
114

    
115
/**
116
 * Applies #printed to an element to help test #pre_render.
117
 */
118
function common_test_drupal_render_printing_pre_render($elements) {
119
  $elements['#printed'] = TRUE;
120
  return $elements;
121
}
122

    
123
/**
124
 * Implements hook_TYPE_alter().
125
 */
126
function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
127
  // Alter first argument.
128
  if (is_array($data)) {
129
    $data['foo'] = 'Drupal';
130
  }
131
  elseif (is_object($data)) {
132
    $data->foo = 'Drupal';
133
  }
134
  // Alter second argument, if present.
135
  if (isset($arg2)) {
136
    if (is_array($arg2)) {
137
      $arg2['foo'] = 'Drupal';
138
    }
139
    elseif (is_object($arg2)) {
140
      $arg2->foo = 'Drupal';
141
    }
142
  }
143
  // Try to alter third argument, if present.
144
  if (isset($arg3)) {
145
    if (is_array($arg3)) {
146
      $arg3['foo'] = 'Drupal';
147
    }
148
    elseif (is_object($arg3)) {
149
      $arg3->foo = 'Drupal';
150
    }
151
  }
152
}
153

    
154
/**
155
 * Implements hook_TYPE_alter() on behalf of Bartik theme.
156
 *
157
 * Same as common_test_drupal_alter_alter(), but here, we verify that themes
158
 * can also alter and come last.
159
 */
160
function bartik_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
161
  // Alter first argument.
162
  if (is_array($data)) {
163
    $data['foo'] .= ' theme';
164
  }
165
  elseif (is_object($data)) {
166
    $data->foo .= ' theme';
167
  }
168
  // Alter second argument, if present.
169
  if (isset($arg2)) {
170
    if (is_array($arg2)) {
171
      $arg2['foo'] .= ' theme';
172
    }
173
    elseif (is_object($arg2)) {
174
      $arg2->foo .= ' theme';
175
    }
176
  }
177
  // Try to alter third argument, if present.
178
  if (isset($arg3)) {
179
    if (is_array($arg3)) {
180
      $arg3['foo'] .= ' theme';
181
    }
182
    elseif (is_object($arg3)) {
183
      $arg3->foo .= ' theme';
184
    }
185
  }
186
}
187

    
188
/**
189
 * Implements hook_TYPE_alter() on behalf of block module.
190
 *
191
 * This is for verifying that drupal_alter(array(TYPE1, TYPE2), ...) allows
192
 * hook_module_implements_alter() to affect the order in which module
193
 * implementations are executed.
194
 */
195
function block_drupal_alter_foo_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
196
  $data['foo'] .= ' block';
197
}
198

    
199
/**
200
 * Implements hook_module_implements_alter().
201
 *
202
 * @see block_drupal_alter_foo_alter()
203
 */
204
function common_test_module_implements_alter(&$implementations, $hook) {
205
  // For drupal_alter(array('drupal_alter', 'drupal_alter_foo'), ...), make the
206
  // block module implementations run after all the other modules. Note that
207
  // when drupal_alter() is called with an array of types, the first type is
208
  // considered primary and controls the module order.
209
  if ($hook == 'drupal_alter_alter' && isset($implementations['block'])) {
210
    $group = $implementations['block'];
211
    unset($implementations['block']);
212
    $implementations['block'] = $group;
213
  }
214
}
215

    
216
/**
217
 * Implements hook_theme().
218
 */
219
function common_test_theme() {
220
  return array(
221
    'common_test_foo' => array(
222
      'variables' => array('foo' => 'foo', 'bar' => 'bar'),
223
    ),
224
  );
225
}
226

    
227
/**
228
 * Theme function for testing drupal_render() theming.
229
 */
230
function theme_common_test_foo($variables) {
231
  return $variables['foo'] . $variables['bar'];
232
}
233

    
234
/**
235
 * Implements hook_library_alter().
236
 */
237
function common_test_library_alter(&$libraries, $module) {
238
  if ($module == 'system' && isset($libraries['farbtastic'])) {
239
    // Change the title of Farbtastic to "Farbtastic: Altered Library".
240
    $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
241
    // Make Farbtastic depend on jQuery Form to test library dependencies.
242
    $libraries['farbtastic']['dependencies'][] = array('system', 'form');
243
  }
244
}
245

    
246
/**
247
 * Implements hook_library().
248
 *
249
 * Adds Farbtastic in a different version.
250
 */
251
function common_test_library() {
252
  $libraries['farbtastic'] = array(
253
    'title' => 'Custom Farbtastic Library',
254
    'website' => 'http://code.google.com/p/farbtastic/',
255
    'version' => '5.3',
256
    'js' => array(
257
      'misc/farbtastic/farbtastic.js' => array(),
258
    ),
259
    'css' => array(
260
      'misc/farbtastic/farbtastic.css' => array(),
261
    ),
262
  );
263
  return $libraries;
264
}
265

    
266
/**
267
 * Adds a JavaScript file and a CSS file with a query string appended.
268
 */
269
function common_test_js_and_css_querystring() {
270
   drupal_add_js(drupal_get_path('module', 'node') . '/node.js');
271
   drupal_add_css(drupal_get_path('module', 'node') . '/node.css');
272
   // A relative URI may have a query string.
273
   drupal_add_css('/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
274
   return '';
275
}
276

    
277
/**
278
 * Implements hook_cron().
279
 *
280
 * System module should handle if a module does not catch an exception and keep
281
 * cron going.
282
 *
283
 * @see common_test_cron_helper()
284
 *
285
 */
286
function common_test_cron() {
287
  throw new Exception(t('Uncaught exception'));
288
}