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..d67056b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/SimpleTestErrorCollectorTest.php @@ -48,9 +48,9 @@ function testErrorCollect() { $this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected'); 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()', 'error_test.module', 'Undefined variable: bananas'); + $this->assertError($this->collectedErrors[1], 'Warning', 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', 'error_test.module', 'Division by zero'); + $this->assertError($this->collectedErrors[2], 'User warning', 'Drupal\error_test\Controllers\ErrorTestController->generateWarnings()', 'error_test.module', 'Drupal is awesome'); } else { // Give back the errors to the log report. 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..e47ba9d --- /dev/null +++ b/core/modules/system/tests/modules/error_test/error_test.routing.yml @@ -0,0 +1,27 @@ +error_test_generate_warnings: + pattern: '/error-test/generate-warnings' + defaults: + _content: '\Drupal\error_test\Controllers\ErrorTestController::generateWarnings' + requirements: + _access: 'TRUE' + +error_test_generate_warnings_with_report: + pattern: '/error-test/generate-warnings-with-report' + defaults: + _content: '\Drupal\error_test\Controllers\ErrorTestController::generateWarnings' + requirements: + _access: 'TRUE' + +error_test_trigger_exception: + pattern: '/error-test/trigger-exception' + defaults: + _content: '\Drupal\error_test\Controllers\ErrorTestController::triggerException' + requirements: + _access: 'TRUE' + +error_test_trigger_pdo_exception: + pattern: '/error-test/trigger-pdo-exception' + defaults: + _content: '\Drupal\error_test\Controllers\ErrorTestController::triggerPDOException' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controllers/ErrorTestController.php b/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controllers/ErrorTestController.php new file mode 100644 index 0000000..9b7a91e --- /dev/null +++ b/core/modules/system/tests/modules/error_test/lib/Drupal/error_test/Controllers/ErrorTestController.php @@ -0,0 +1,68 @@ +get('database')); + } + + /** + * Constructs a UpdateTestController object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + */ + public function __construct(Connection $database) { + $this->database = $database; + } + /** + * Generate warnings to test the error handler. + */ + public function generateWarnings($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 ""; + } + + /** + * Trigger an exception to test the exception handler. + */ + public function triggerException() { + define('SIMPLETEST_COLLECT_ERRORS', FALSE); + throw new \Exception("Drupal is awesome"); + } + + /** + * Trigger an exception to test the PDO exception handler. + */ + public function triggerPDOException() { + define('SIMPLETEST_COLLECT_ERRORS', FALSE); + $this->database->query('SELECT * FROM bananas_are_awesome'); + } + +}