1. 8.2.x core/modules/system/tests/modules/common_test/common_test.module
  2. 8.0.x core/modules/system/tests/modules/common_test/common_test.module
  3. 8.1.x core/modules/system/tests/modules/common_test/common_test.module
  4. 7.x modules/simpletest/tests/common_test.module

Helper module for the Common tests.

File

modules/simpletest/tests/common_test.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for the Common tests.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function common_test_menu() {
  10. $items['common-test/drupal_goto'] = array(
  11. 'title' => 'Drupal Goto',
  12. 'page callback' => 'common_test_drupal_goto_land',
  13. 'access arguments' => array('access content'),
  14. 'type' => MENU_CALLBACK,
  15. );
  16. $items['common-test/drupal_goto/fail'] = array(
  17. 'title' => 'Drupal Goto',
  18. 'page callback' => 'common_test_drupal_goto_land_fail',
  19. 'access arguments' => array('access content'),
  20. 'type' => MENU_CALLBACK,
  21. );
  22. $items['common-test/drupal_goto/redirect'] = array(
  23. 'title' => 'Drupal Goto',
  24. 'page callback' => 'common_test_drupal_goto_redirect',
  25. 'access arguments' => array('access content'),
  26. 'type' => MENU_CALLBACK,
  27. );
  28. $items['common-test/drupal_goto/redirect_advanced'] = array(
  29. 'title' => 'Drupal Goto',
  30. 'page callback' => 'common_test_drupal_goto_redirect_advanced',
  31. 'access arguments' => array('access content'),
  32. 'type' => MENU_CALLBACK,
  33. );
  34. $items['common-test/drupal_goto/redirect_fail'] = array(
  35. 'title' => 'Drupal Goto Failure',
  36. 'page callback' => 'drupal_goto',
  37. 'page arguments' => array('common-test/drupal_goto/fail'),
  38. 'access arguments' => array('access content'),
  39. 'type' => MENU_CALLBACK,
  40. );
  41. $items['common-test/destination'] = array(
  42. 'title' => 'Drupal Get Destination',
  43. 'page callback' => 'common_test_destination',
  44. 'access arguments' => array('access content'),
  45. 'type' => MENU_CALLBACK,
  46. );
  47. $items['common-test/query-string'] = array(
  48. 'title' => 'Test querystring',
  49. 'page callback' => 'common_test_js_and_css_querystring',
  50. 'access arguments' => array('access content'),
  51. 'type' => MENU_CALLBACK,
  52. );
  53. return $items;
  54. }
  55. /**
  56. * Redirect using drupal_goto().
  57. */
  58. function common_test_drupal_goto_redirect() {
  59. drupal_goto('common-test/drupal_goto');
  60. }
  61. /**
  62. * Redirect using drupal_goto().
  63. */
  64. function common_test_drupal_goto_redirect_advanced() {
  65. drupal_goto('common-test/drupal_goto', array('query' => array('foo' => '123')), 301);
  66. }
  67. /**
  68. * Landing page for drupal_goto().
  69. */
  70. function common_test_drupal_goto_land() {
  71. print "drupal_goto";
  72. }
  73. /**
  74. * Fail landing page for drupal_goto().
  75. */
  76. function common_test_drupal_goto_land_fail() {
  77. print "drupal_goto_fail";
  78. }
  79. /**
  80. * Implements hook_drupal_goto_alter().
  81. */
  82. function common_test_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  83. if ($path == 'common-test/drupal_goto/fail') {
  84. $path = 'common-test/drupal_goto/redirect';
  85. }
  86. }
  87. /**
  88. * Implements hook_init().
  89. */
  90. function common_test_init() {
  91. if (variable_get('common_test_redirect_current_path', FALSE)) {
  92. drupal_goto(current_path());
  93. }
  94. }
  95. /**
  96. * Print destination query parameter.
  97. */
  98. function common_test_destination() {
  99. $destination = drupal_get_destination();
  100. print "The destination: " . check_plain($destination['destination']);
  101. }
  102. /**
  103. * Applies #printed to an element to help test #pre_render.
  104. */
  105. function common_test_drupal_render_printing_pre_render($elements) {
  106. $elements['#printed'] = TRUE;
  107. return $elements;
  108. }
  109. /**
  110. * Implements hook_TYPE_alter().
  111. */
  112. function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
  113. // Alter first argument.
  114. if (is_array($data)) {
  115. $data['foo'] = 'Drupal';
  116. }
  117. elseif (is_object($data)) {
  118. $data->foo = 'Drupal';
  119. }
  120. // Alter second argument, if present.
  121. if (isset($arg2)) {
  122. if (is_array($arg2)) {
  123. $arg2['foo'] = 'Drupal';
  124. }
  125. elseif (is_object($arg2)) {
  126. $arg2->foo = 'Drupal';
  127. }
  128. }
  129. // Try to alter third argument, if present.
  130. if (isset($arg3)) {
  131. if (is_array($arg3)) {
  132. $arg3['foo'] = 'Drupal';
  133. }
  134. elseif (is_object($arg3)) {
  135. $arg3->foo = 'Drupal';
  136. }
  137. }
  138. }
  139. /**
  140. * Implements hook_TYPE_alter() on behalf of Bartik theme.
  141. *
  142. * Same as common_test_drupal_alter_alter(), but here, we verify that themes
  143. * can also alter and come last.
  144. */
  145. function bartik_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
  146. // Alter first argument.
  147. if (is_array($data)) {
  148. $data['foo'] .= ' theme';
  149. }
  150. elseif (is_object($data)) {
  151. $data->foo .= ' theme';
  152. }
  153. // Alter second argument, if present.
  154. if (isset($arg2)) {
  155. if (is_array($arg2)) {
  156. $arg2['foo'] .= ' theme';
  157. }
  158. elseif (is_object($arg2)) {
  159. $arg2->foo .= ' theme';
  160. }
  161. }
  162. // Try to alter third argument, if present.
  163. if (isset($arg3)) {
  164. if (is_array($arg3)) {
  165. $arg3['foo'] .= ' theme';
  166. }
  167. elseif (is_object($arg3)) {
  168. $arg3->foo .= ' theme';
  169. }
  170. }
  171. }
  172. /**
  173. * Implements hook_TYPE_alter() on behalf of block module.
  174. *
  175. * This is for verifying that drupal_alter(array(TYPE1, TYPE2), ...) allows
  176. * hook_module_implements_alter() to affect the order in which module
  177. * implementations are executed.
  178. */
  179. function block_drupal_alter_foo_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
  180. $data['foo'] .= ' block';
  181. }
  182. /**
  183. * Implements hook_module_implements_alter().
  184. *
  185. * @see block_drupal_alter_foo_alter()
  186. */
  187. function common_test_module_implements_alter(&$implementations, $hook) {
  188. // For drupal_alter(array('drupal_alter', 'drupal_alter_foo'), ...), make the
  189. // block module implementations run after all the other modules. Note that
  190. // when drupal_alter() is called with an array of types, the first type is
  191. // considered primary and controls the module order.
  192. if ($hook == 'drupal_alter_alter' && isset($implementations['block'])) {
  193. $group = $implementations['block'];
  194. unset($implementations['block']);
  195. $implementations['block'] = $group;
  196. }
  197. }
  198. /**
  199. * Implements hook_theme().
  200. */
  201. function common_test_theme() {
  202. return array(
  203. 'common_test_foo' => array(
  204. 'variables' => array('foo' => 'foo', 'bar' => 'bar'),
  205. ),
  206. );
  207. }
  208. /**
  209. * Theme function for testing drupal_render() theming.
  210. */
  211. function theme_common_test_foo($variables) {
  212. return $variables['foo'] . $variables['bar'];
  213. }
  214. /**
  215. * Implements hook_library_alter().
  216. */
  217. function common_test_library_alter(&$libraries, $module) {
  218. if ($module == 'system' && isset($libraries['farbtastic'])) {
  219. // Change the title of Farbtastic to "Farbtastic: Altered Library".
  220. $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
  221. // Make Farbtastic depend on jQuery Form to test library dependencies.
  222. $libraries['farbtastic']['dependencies'][] = array('system', 'form');
  223. }
  224. }
  225. /**
  226. * Implements hook_library().
  227. *
  228. * Adds Farbtastic in a different version.
  229. */
  230. function common_test_library() {
  231. $libraries['farbtastic'] = array(
  232. 'title' => 'Custom Farbtastic Library',
  233. 'website' => 'http://code.google.com/p/farbtastic/',
  234. 'version' => '5.3',
  235. 'js' => array(
  236. 'misc/farbtastic/farbtastic.js' => array(),
  237. ),
  238. 'css' => array(
  239. 'misc/farbtastic/farbtastic.css' => array(),
  240. ),
  241. );
  242. return $libraries;
  243. }
  244. /**
  245. * Adds a JavaScript file and a CSS file with a query string appended.
  246. */
  247. function common_test_js_and_css_querystring() {
  248. drupal_add_js(drupal_get_path('module', 'node') . '/node.js');
  249. drupal_add_css(drupal_get_path('module', 'node') . '/node.css');
  250. // A relative URI may have a query string.
  251. drupal_add_css('/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
  252. return '';
  253. }
  254. /**
  255. * Implements hook_cron().
  256. *
  257. * System module should handle if a module does not catch an exception and keep
  258. * cron going.
  259. *
  260. * @see common_test_cron_helper()
  261. *
  262. */
  263. function common_test_cron() {
  264. throw new Exception(t('Uncaught exception'));
  265. }

Functions

Namesort descending Description
bartik_drupal_alter_alter Implements hook_TYPE_alter() on behalf of Bartik theme.
block_drupal_alter_foo_alter Implements hook_TYPE_alter() on behalf of block module.
common_test_cron Implements hook_cron().
common_test_destination Print destination query parameter.
common_test_drupal_alter_alter Implements hook_TYPE_alter().
common_test_drupal_goto_alter Implements hook_drupal_goto_alter().
common_test_drupal_goto_land Landing page for drupal_goto().
common_test_drupal_goto_land_fail Fail landing page for drupal_goto().
common_test_drupal_goto_redirect Redirect using drupal_goto().
common_test_drupal_goto_redirect_advanced Redirect using drupal_goto().
common_test_drupal_render_printing_pre_render Applies #printed to an element to help test #pre_render.
common_test_init Implements hook_init().
common_test_js_and_css_querystring Adds a JavaScript file and a CSS file with a query string appended.
common_test_library Implements hook_library().
common_test_library_alter Implements hook_library_alter().
common_test_menu Implements hook_menu().
common_test_module_implements_alter Implements hook_module_implements_alter().
common_test_theme Implements hook_theme().
theme_common_test_foo Theme function for testing drupal_render() theming.