summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-01-21 14:22:33 +0000
committerDries Buytaert <dries@buytaert.net>2009-01-21 14:22:33 +0000
commit60c06921ce37fae8604b83e0ccd149f3ee3eab1e (patch)
tree6d088ab18e590b7a11b9acd6dc9962faa220d1e3 /modules/simpletest/tests
parent18e62bf8c5c8612f1e2bfc10cd8192e97d7eebee (diff)
downloadbrdo-60c06921ce37fae8604b83e0ccd149f3ee3eab1e.tar.gz
brdo-60c06921ce37fae8604b83e0ccd149f3ee3eab1e.tar.bz2
- Patch #291026 by Dave Reid et al: further (usability) improvements to the E_NOTICE handling.
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/common.test88
1 files changed, 75 insertions, 13 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index e6ebfa16c..8f0ede290 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -492,33 +492,95 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
* Test the error handler.
*/
function testErrorHandler() {
+ $error_notice = array(
+ '%type' => 'Notice',
+ '%message' => 'Undefined variable: bananas',
+ '%function' => 'system_test_generate_warnings()',
+ '%line' => 184,
+ '%file' => realpath('modules/simpletest/tests/system_test.module'),
+ );
+ $error_warning = array(
+ '%type' => 'Warning',
+ '%message' => 'Division by zero',
+ '%function' => 'system_test_generate_warnings()',
+ '%line' => 186,
+ '%file' => realpath('modules/simpletest/tests/system_test.module'),
+ );
+ $error_user_notice = array(
+ '%type' => 'User notice',
+ '%message' => 'Drupal is awesome',
+ '%function' => 'system_test_generate_warnings()',
+ '%line' => 188,
+ '%file' => realpath('modules/simpletest/tests/system_test.module'),
+ );
+
+ // Set error reporting to collect notices.
+ variable_set('error_level', 2);
$this->drupalGet('system-test/generate-warnings');
+ $this->assertErrorMessage($error_notice);
+ $this->assertErrorMessage($error_warning);
+ $this->assertErrorMessage($error_user_notice);
- $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');
+ // Set error reporting to not collect notices.
+ variable_set('error_level', 1);
+ $this->drupalGet('system-test/generate-warnings');
+ $this->assertNoErrorMessage($error_notice);
+ $this->assertErrorMessage($error_warning);
+ $this->assertErrorMessage($error_user_notice);
+
+ // Set error reporting to not show any errors.
+ variable_set('error_level', 0);
+ $this->drupalGet('system-test/generate-warnings');
+ $this->assertNoErrorMessage($error_notice);
+ $this->assertNoErrorMessage($error_warning);
+ $this->assertNoErrorMessage($error_user_notice);
}
/**
* Test the exception handler.
*/
function testExceptionHandler() {
+ $error_exception = array(
+ '%type' => 'Exception',
+ '%message' => 'Drupal is awesome',
+ '%function' => 'system_test_trigger_exception()',
+ '%line' => 197,
+ '%file' => realpath('modules/simpletest/tests/system_test.module'),
+ );
+ $error_pdo_exception = array(
+ '%type' => 'PDOException',
+ '%message' => 'SQLSTATE',
+ '%function' => 'system_test_trigger_pdo_exception()',
+ '%line' => 205,
+ '%file' => realpath('modules/simpletest/tests/system_test.module'),
+ );
+
$this->drupalGet('system-test/trigger-exception');
- $this->assertErrorMessage('Exception', 'system_test.module', 'system_test_trigger_exception()', 'Drupal is awesome');
+ $this->assertErrorMessage($error_exception);
$this->drupalGet('system-test/trigger-pdo-exception');
- // We only check for SQLSTATE because the exact error reported varies from database to database.
- $this->assertErrorMessage('PDOException', 'system_test.module', 'system_test_trigger_pdo_exception()', 'SQLSTATE');
+ // We cannot use assertErrorMessage() since the extact error reported
+ // varies from database to database. Check for the error keyword 'SQLSTATE'.
+ $this->assertText($error_pdo_exception['%type'], t('Found %type in error page.', $error_pdo_exception));
+ $this->assertText($error_pdo_exception['%message'], t('Found %message in error page.', $error_pdo_exception));
+ $error_details = t('in %function (line %line of %file)', $error_pdo_exception);
+ $this->assertRaw($error_details, t("Found '!message' in error page.", array('!message' => $error_details)));
}
/**
- * Helper function: assert that the logged message is correct.
+ * Helper function: assert that the error message is found.
*/
- 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)));
+ function assertErrorMessage(array $error) {
+ $message = t('%type: %message in %function (line %line of %file).', $error);
+ $this->assertRaw($message, t('Error !message found.', array('!message' => $message)));
+ }
+
+ /**
+ * Helper function: assert that the error message is not found.
+ */
+ function assertNoErrorMessage(array $error) {
+ $message = t('%type: %message in %function (line %line of %file).', $error);
+ $this->assertNoRaw($message, t('Error !message not found.', array('!message' => $message)));
}
}
@@ -700,4 +762,4 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase {
$this->assertEqual($error['message'], $message, t("Message was %message", array('%message' => $message)));
}
}
-} \ No newline at end of file
+}