error_test.module 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function error_test_menu() {
  6. $items['error-test/generate-warnings'] = array(
  7. 'title' => 'Generate warnings',
  8. 'page callback' => 'error_test_generate_warnings',
  9. 'access callback' => TRUE,
  10. 'type' => MENU_CALLBACK,
  11. );
  12. $items['error-test/generate-warnings-with-report'] = array(
  13. 'title' => 'Generate warnings with Simpletest reporting',
  14. 'page callback' => 'error_test_generate_warnings',
  15. 'page arguments' => array(TRUE),
  16. 'access callback' => TRUE,
  17. 'type' => MENU_CALLBACK,
  18. );
  19. $items['error-test/trigger-exception'] = array(
  20. 'title' => 'Trigger an exception',
  21. 'page callback' => 'error_test_trigger_exception',
  22. 'access callback' => TRUE,
  23. 'type' => MENU_CALLBACK,
  24. );
  25. $items['error-test/trigger-pdo-exception'] = array(
  26. 'title' => 'Trigger a PDO exception',
  27. 'page callback' => 'error_test_trigger_pdo_exception',
  28. 'access callback' => TRUE,
  29. 'type' => MENU_CALLBACK,
  30. );
  31. return $items;
  32. }
  33. /**
  34. * Menu callback; generate warnings to test the error handler.
  35. */
  36. function error_test_generate_warnings($collect_errors = FALSE) {
  37. // Tell Drupal error reporter to send errors to Simpletest or not.
  38. define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
  39. // This will generate a notice.
  40. $notice = new \stdClass();
  41. $notice == 1 ? 1 : 0;
  42. // This will generate a warning.
  43. $a = '';
  44. foreach ($a as $b) {
  45. }
  46. // This will generate a user error.
  47. trigger_error("Drupal is awesome", E_USER_WARNING);
  48. return "";
  49. }
  50. /**
  51. * Menu callback; trigger an exception to test the exception handler.
  52. */
  53. function error_test_trigger_exception() {
  54. define('SIMPLETEST_COLLECT_ERRORS', FALSE);
  55. throw new Exception("Drupal is awesome");
  56. }
  57. /**
  58. * Menu callback; trigger an exception to test the exception handler.
  59. */
  60. function error_test_trigger_pdo_exception() {
  61. define('SIMPLETEST_COLLECT_ERRORS', FALSE);
  62. db_query('SELECT * FROM bananas_are_awesome');
  63. }