From 967d8f67ac957924b9cb6855cb650f8f67d58cdc Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 15 Oct 2008 16:05:51 +0000 Subject: - Patch #304924 by Damien Tournoud: extend error handler to manage exceptions. I have one exception and one fail. --- modules/simpletest/tests/common.test | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'modules/simpletest/tests/common.test') diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 43e7b0216..0d7ad985c 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -251,3 +251,52 @@ class DrupalSetContentTestCase extends DrupalWebTestCase { } } } + +/** + * Tests Drupal error and exception handlers. + */ +class DrupalErrorHandlerUnitTest extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Drupal error handlers'), + 'description' => t("Performs tests on the Drupal error and exception handler."), + 'group' => t('System'), + ); + } + + function setUp() { + parent::setUp('system_test'); + } + + /** + * Test the error handler. + */ + function testErrorHandler() { + $this->drupalGet('system-test/generate-warnings'); + + $this->assertErrorMessage('Notice', 'system_test.module', 'system_test_generate_warnings() ', 'Undefined variable'); + $this->assertErrorMessage('Warning', 'system_test.module', 'system_test_generate_warnings() ', 'Division by zero'); + $this->assertErrorMessage('User notice', 'system_test.module', 'system_test_generate_warnings() ', 'Drupal is awesome'); + } + + /** + * Test the exception handler. + */ + function testExceptionHandler() { + $this->drupalGet('system-test/trigger-exception'); + $this->assertErrorMessage('Exception', 'system_test.module', 'system_test_trigger_exception()', 'Drupal is awesome'); + + $this->drupalGet('system-test/trigger-pdo-exception'); + $this->assertErrorMessage('PDOException', 'system_test.module', 'system_test_trigger_pdo_exception()', 'Base table or view not found'); + } + + /** + * Helper function: assert that the logged message is correct. + */ + function assertErrorMessage($type, $file, $function, $message) { + $this->assertText($type, t("Found '%type' in error page.", array('%type' => $type))); + $this->assertText($file, t("Found '%file' in error page.", array('%file' => $file))); + $this->assertText($function, t("Found '%function' in error page.", array('%function' => $function))); + $this->assertText($message, t("Found '%message' in error page.", array('%message' => $message))); + } +} -- cgit v1.2.3