1 error.test | BackdropErrorHandlerUnitTest::testExceptionHandler() |
Test the exception handler.
File
- core/
modules/ simpletest/ tests/ error.test, line 63
Class
- BackdropErrorHandlerUnitTest
- Tests Backdrop error and exception handlers.
Code
function testExceptionHandler() {
$config = config('system.core');
$error_exception = array(
'%type' => 'Exception',
'!message' => 'Backdrop is awesome',
'%function' => 'error_test_trigger_exception()',
'%line' => 57,
'%file' => backdrop_realpath('core/modules/simpletest/tests/error_test.module'),
);
$error_pdo_exception = array(
'%type' => 'PDOException',
'!message' => 'SELECT * FROM bananas_are_awesome',
'%function' => 'error_test_trigger_pdo_exception()',
'%line' => 65,
'%file' => backdrop_realpath('core/modules/simpletest/tests/error_test.module'),
);
// Set error reporting to collect notices as assumed in the module.
$config->set('error_level', ERROR_REPORTING_DISPLAY_ALL)->save();
$this->backdropGet('error-test/trigger-exception');
$this->assertTrue(strpos($this->backdropGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
$this->assertErrorMessage($error_exception);
$this->backdropGet('error-test/trigger-pdo-exception');
$this->assertTrue(strpos($this->backdropGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
// We cannot use assertErrorMessage() since the exact error reported
// varies from database to database. Check that the SQL string is displayed.
$this->assertText($error_pdo_exception['%type'], format_string('Found %type in error page.', $error_pdo_exception));
$this->assertText($error_pdo_exception['!message'], format_string('Found !message in error page.', $error_pdo_exception));
$error_details = format_string('in %function (line ', $error_pdo_exception);
$this->assertRaw($error_details, format_string("Found '!message' in error page.", array('!message' => $error_details)));
}