function ErrorHandlerTest::testExceptionHandler

Test the exception handler.

File

drupal/core/modules/system/lib/Drupal/system/Tests/System/ErrorHandlerTest.php, line 96
Definition of Drupal\system\Tests\System\ErrorHandlerTest.

Class

ErrorHandlerTest
Tests error and exception handlers.

Namespace

Drupal\system\Tests\System

Code

function testExceptionHandler() {
  $error_exception = array(
    '%type' => 'Exception',
    '!message' => 'Drupal is awesome',
    '%function' => 'error_test_trigger_exception()',
    '%line' => 56,
    '%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
  );
  $error_pdo_exception = array(
    '%type' => 'DatabaseExceptionWrapper',
    '!message' => 'SELECT * FROM bananas_are_awesome',
    '%function' => 'error_test_trigger_pdo_exception()',
    '%line' => 64,
    '%file' => drupal_get_path('module', 'error_test') . '/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,
  )));
}