diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php index 16c62fc..5ae7e7f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php @@ -46,11 +46,12 @@ function testErrorCollect() { $this->collectedErrors = array(); $this->drupalGet('error-test/generate-warnings-with-report'); $this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected'); + $this->verbose(print_r($this->collectedErrors, TRUE)); if (count($this->collectedErrors) == 3) { - $this->assertError($this->collectedErrors[0], 'Notice', 'error_test_generate_warnings()', 'error_test.module', 'Undefined variable: bananas'); - $this->assertError($this->collectedErrors[1], 'Warning', 'error_test_generate_warnings()', 'error_test.module', 'Division by zero'); - $this->assertError($this->collectedErrors[2], 'User warning', 'error_test_generate_warnings()', 'error_test.module', 'Drupal is awesome'); + $this->assertError($this->collectedErrors[0], 'Notice', 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Undefined variable: bananas'); + $this->assertError($this->collectedErrors[1], 'Warning', 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Division by zero'); + $this->assertError($this->collectedErrors[2], 'User warning', 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Drupal is awesome'); } else { // Give back the errors to the log report. @@ -94,6 +95,7 @@ protected function error($message = '', $group = 'Other', array $caller = NULL) * Asserts that a collected error matches what we are expecting. */ function assertError($error, $group, $function, $file, $message = NULL) { + $this->verbose(print_r($error,TRUE)); $this->assertEqual($error['group'], $group, format_string("Group was %group", array('%group' => $group))); $this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", array('%function' => $function))); $this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", array('%file' => $file))); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ErrorHandlerTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ErrorHandlerTest.php index 3ecb0e5..7b133dc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/ErrorHandlerTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/ErrorHandlerTest.php @@ -37,19 +37,19 @@ function testErrorHandler() { $error_notice = array( '%type' => 'Notice', '!message' => 'Undefined variable: bananas', - '%function' => 'error_test_generate_warnings()', + '%function' => 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', ); $error_warning = array( '%type' => 'Warning', '!message' => 'Division by zero', - '%function' => 'error_test_generate_warnings()', + '%function' => 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', ); $error_user_notice = array( '%type' => 'User warning', '!message' => 'Drupal is awesome', - '%function' => 'error_test_generate_warnings()', + '%function' => 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', ); @@ -97,14 +97,14 @@ function testExceptionHandler() { $error_exception = array( '%type' => 'Exception', '!message' => 'Drupal is awesome', - '%function' => 'error_test_trigger_exception()', + '%function' => 'Drupal\error_test\Controllers\ErrorTestController->triggerException()', '%line' => 56, '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', ); $error_pdo_exception = array( '%type' => 'DatabaseExceptionWrapper', '!message' => 'SELECT * FROM bananas_are_awesome', - '%function' => 'error_test_trigger_pdo_exception()', + '%function' => 'Drupal\error_test\Controllers\ErrorTestController->triggerPDOException()', '%line' => 64, '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', ); diff --git a/core/modules/system/tests/modules/error_test/error_test.module b/core/modules/system/tests/modules/error_test/error_test.module index d062cb0..b3d9bbc 100644 --- a/core/modules/system/tests/modules/error_test/error_test.module +++ b/core/modules/system/tests/modules/error_test/error_test.module @@ -1,65 +1 @@ 'Generate warnings', - 'page callback' => 'error_test_generate_warnings', - 'access callback' => TRUE, - 'type' => MENU_CALLBACK, - ); - $items['error-test/generate-warnings-with-report'] = array( - 'title' => 'Generate warnings with Simpletest reporting', - 'page callback' => 'error_test_generate_warnings', - 'page arguments' => array(TRUE), - 'access callback' => TRUE, - 'type' => MENU_CALLBACK, - ); - $items['error-test/trigger-exception'] = array( - 'title' => 'Trigger an exception', - 'page callback' => 'error_test_trigger_exception', - 'access callback' => TRUE, - 'type' => MENU_CALLBACK, - ); - $items['error-test/trigger-pdo-exception'] = array( - 'title' => 'Trigger a PDO exception', - 'page callback' => 'error_test_trigger_pdo_exception', - 'access callback' => TRUE, - 'type' => MENU_CALLBACK, - ); - - return $items; -} - -/** - * Menu callback; generate warnings to test the error handler. - */ -function error_test_generate_warnings($collect_errors = FALSE) { - // Tell Drupal error reporter to send errors to Simpletest or not. - define('SIMPLETEST_COLLECT_ERRORS', $collect_errors); - // This will generate a notice. - $monkey_love = $bananas; - // This will generate a warning. - $awesomely_big = 1/0; - // This will generate a user error. - trigger_error("Drupal is awesome", E_USER_WARNING); - return ""; -} - -/** - * Menu callback; trigger an exception to test the exception handler. - */ -function error_test_trigger_exception() { - define('SIMPLETEST_COLLECT_ERRORS', FALSE); - throw new Exception("Drupal is awesome"); -} - -/** - * Menu callback; trigger an exception to test the exception handler. - */ -function error_test_trigger_pdo_exception() { - define('SIMPLETEST_COLLECT_ERRORS', FALSE); - db_query('SELECT * FROM bananas_are_awesome'); -} diff --git a/core/modules/system/tests/modules/error_test/error_test.routing.yml b/core/modules/system/tests/modules/error_test/error_test.routing.yml new file mode 100644 index 0000000..3766321 --- /dev/null +++ b/core/modules/system/tests/modules/error_test/error_test.routing.yml @@ -0,0 +1,28 @@ +error_test_generate_warnings: + pattern: '/error-test/generate-warnings' + defaults: + _content: '\Drupal\error_test\Controller\ErrorTestController::generateWarnings' + requirements: + _access: 'TRUE' + +error_test_generate_warnings_with_report: + pattern: '/error-test/generate-warnings-with-report' + defaults: + _content: '\Drupal\error_test\Controller\ErrorTestController::generateWarnings' + collect_errors: TRUE + requirements: + _access: 'TRUE' + +error_test_trigger_exception: + pattern: '/error-test/trigger-exception' + defaults: + _content: '\Drupal\error_test\Controller\ErrorTestController::triggerException' + requirements: + _access: 'TRUE' + +error_test_trigger_pdo_exception: + pattern: '/error-test/trigger-pdo-exception' + defaults: + _content: '\Drupal\error_test\Controller\ErrorTestController::triggerPDOException' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controller/ErrorTestController.php b/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controller/ErrorTestController.php new file mode 100644 index 0000000..9fcaf92 --- /dev/null +++ b/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controller/ErrorTestController.php @@ -0,0 +1,48 @@ +container->get('database')->query('SELECT * FROM bananas_are_awesome'); + } + +}