summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/menu_test.module
blob: 194fe8006a48de669d550b0536de5eb2f22f9722 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
// $Id$

/**
 * @file
 * Dummy module implementing hook menu.
 */

/**
 * Implements hook_menu().
 */
function menu_test_menu() {
  // The name of the menu changes during the course of the test. Using a $_GET.
  $items['menu_name_test'] = array(
    'title' => 'Test menu_name router item',
    'page callback' => 'node_save',
    'menu_name' => menu_test_menu_name(),
  );
  // Use FALSE as 'title callback' to bypass t().
  $items['menu_no_title_callback'] = array(
    'title' => 'A title with @placeholder',
    'title callback' => FALSE,
    'title arguments' => array('@placeholder' => 'some other text'),
    'page callback' => 'menu_test_callback',
    'access arguments' => array('access content'),
  );

  // Hidden link for menu_link_maintain tests
  $items['menu_test_maintain/%'] = array(
    'title' => 'Menu maintain test',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
   );
  // Hierarchical tests.
  $items['menu-test/hierarchy/parent'] = array(
    'title' => 'Parent menu router',
    'page callback' => 'node_page_default',
  );
  $items['menu-test/hierarchy/parent/child'] = array(
    'title' => 'Child menu router',
    'page callback' => 'node_page_default',
  );
  $items['menu-test/hierarchy/parent/child2/child'] = array(
    'title' => 'Unattached subchild router',
    'page callback' => 'node_page_default',
  );
  // Theme callback tests.
  $items['menu-test/theme-callback/%'] = array(
    'title' => 'Page that displays different themes',
    'page callback' => 'menu_test_theme_page_callback',
    'access arguments' => array('access content'),
    'theme callback' => 'menu_test_theme_callback',
    'theme arguments' => array(2),
  );
  $items['menu-test/theme-callback/%/inheritance'] = array(
    'title' => 'Page that tests theme callback inheritance.',
    'page callback' => 'menu_test_theme_page_callback',
    'page arguments' => array(TRUE),
    'access arguments' => array('access content'),
  );
  // Path containing "exotic" characters.
  $path = "menu-test/ -._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters.
    "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string.
    "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets.
  $items[$path] = array(
    'title' => '"Exotic" path',
    'page callback' => 'menu_test_callback',
    'access arguments' => array('access content'),
  );

  // Hidden tests; base parents.
  // Same structure as in Menu and Block modules. Since those structures can
  // change, we need to simulate our own in here.
  $items['menu-test'] = array(
    'title' => 'Menu test root',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
  );
  $items['menu-test/hidden'] = array(
    'title' => 'Menu test parent',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
  );

  // Hidden tests; one dynamic argument.
  $items['menu-test/hidden/menu'] = array(
    'title' => 'Menus',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
  );
  $items['menu-test/hidden/menu/list'] = array(
    'title' => 'List menus',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['menu-test/hidden/menu/add'] = array(
    'title' => 'Add menu',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_ACTION,
  );
  $items['menu-test/hidden/menu/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 5,
  );
  $items['menu-test/hidden/menu/manage/%menu'] = array(
    'title' => 'Customize menu',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['menu-test/hidden/menu/manage/%menu/list'] = array(
    'title' => 'List links',
    'weight' => -10,
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['menu-test/hidden/menu/manage/%menu/add'] = array(
    'title' => 'Add link',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_ACTION,
  );
  $items['menu-test/hidden/menu/manage/%menu/edit'] = array(
    'title' => 'Edit menu',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['menu-test/hidden/menu/manage/%menu/delete'] = array(
    'title' => 'Delete menu',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  // Hidden tests; two dynamic arguments.
  $items['menu-test/hidden/block'] = array(
    'title' => 'Blocks',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
  );
  $items['menu-test/hidden/block/list'] = array(
    'title' => 'List',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['menu-test/hidden/block/add'] = array(
    'title' => 'Add block',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_ACTION,
  );
  $items['menu-test/hidden/block/manage/%/%'] = array(
    'title' => 'Configure block',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
  );
  $items['menu-test/hidden/block/manage/%/%/configure'] = array(
    'title' => 'Configure block',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,
  );
  $items['menu-test/hidden/block/manage/%/%/delete'] = array(
    'title' => 'Delete block',
    'page callback' => 'node_page_default',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_NONE,
  );

  return $items;
}

/**
 * Dummy callback for hook_menu() to point to.
 *
 * @return
 *  A random string.
 */
function menu_test_callback() {
  return 'This is menu_test_callback().';
}

/**
 * Page callback to use when testing the theme callback functionality.
 *
 * @param $inherited
 *   An optional boolean to set to TRUE when the requested page is intended to
 *   inherit the theme of its parent.
 * @return
 *   A string describing the requested custom theme and actual theme being used
 *   for the current page request.
 */
function menu_test_theme_page_callback($inherited = FALSE) {
  global $theme_key;
  // Initialize the theme system so that $theme_key will be populated.
  drupal_theme_initialize();
  // Now check both the requested custom theme and the actual theme being used.
  $custom_theme = menu_get_custom_theme();
  $requested_theme = empty($custom_theme) ? 'NONE' : $custom_theme;
  $output = "Requested theme: $requested_theme. Actual theme: $theme_key.";
  if ($inherited) {
    $output .= ' Theme callback inheritance is being tested.';
  }
  return $output;
}

/**
 * Theme callback to use when testing the theme callback functionality.
 *
 * @param $argument
 *   The argument passed in from the URL.
 * @return
 *   The name of the custom theme to request for the current page.
 */
function menu_test_theme_callback($argument) {
  // Test using the variable administrative theme.
  if ($argument == 'use-admin-theme') {
    return variable_get('admin_theme');
  }
  // Test using a theme that exists, but may or may not be enabled.
  elseif ($argument == 'use-stark-theme') {
    return 'stark';
  }
  // Test using a theme that does not exist.
  elseif ($argument == 'use-fake-theme') {
    return 'fake_theme';
  }
  // For any other value of the URL argument, do not return anything. This
  // allows us to test that returning nothing from a theme callback function
  // causes the page to correctly fall back on using the main site theme.
}

/**
 * Helper function for the testMenuName() test. Used to change the menu_name
 * parameter of a menu.
 *
 * @param $new_name
 *   If set, will change the menu_name value.
 * @return
 *   The menu_name value to use.
 */
function menu_test_menu_name($new_name = '') {
  static $name = 'original';
  if ($new_name) {
    $name = $new_name;
  }
  return $name;
}

/**
 * Implements hook_menu_link_insert().
 *
 * @return
 *  A random string.
 */
function menu_test_menu_link_insert($item) {
  menu_test_static_variable('insert');
}

/**
 * Implements hook_menu_link_update().
 *
 * @return
 *  A random string.
 */
function menu_test_menu_link_update($item) {
  menu_test_static_variable('update');
}

/**
 * Implements hook_menu_link_delete().
 *
 * @return
 *  A random string.
 */
function menu_test_menu_link_delete($item) {
  menu_test_static_variable('delete');
}

/**
 * Static function for testing hook results.
 *
 * @param $value
 *   The value to set or NULL to return the current value.
 * @return
 *   A text string for comparison to test assertions.
 */
function menu_test_static_variable($value = NULL) {
  static $variable;
  if (!empty($value)) {
    $variable = $value;
  }
  return $variable;
}