You are here

function DrupalErrorHandlerUnitTest::testExceptionHandler in SimpleTest 7

Test the exception handler.

File

tests/error.test, line 73

Class

DrupalErrorHandlerUnitTest
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)'), t('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)'), t('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'], 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,
  )));
}