You are here

function DrupalErrorHandlerTestCase::testExceptionHandler in Drupal 7

Test the exception handler.

File

modules/simpletest/tests/error.test, line 70

Class

DrupalErrorHandlerTestCase
Tests Drupal error and exception handlers.

Code

function testExceptionHandler() {
  $error_exception = array(
    '%type' => 'Exception',
    '!message' => 'Drupal is awesome',
    '%function' => 'error_test_trigger_exception()',
    '%line' => 57,
    '%file' => drupal_realpath('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' => drupal_realpath('modules/simpletest/tests/error_test.module'),
  );
  $this
    ->drupalGet('error-test/trigger-exception');
  $this
    ->assertTrue(strpos($this
    ->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
  $this
    ->assertErrorMessage($error_exception);
  $this
    ->drupalGet('error-test/trigger-pdo-exception');
  $this
    ->assertTrue(strpos($this
    ->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');

  // We cannot use assertErrorMessage() since the extact 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,
  )));
}