function DrupalErrorHandlerTestCase::testErrorHandler

Test the error handler.

File

drupal/modules/simpletest/tests/error.test, line 22

Class

DrupalErrorHandlerTestCase
Tests Drupal error and exception handlers.

Code

function testErrorHandler() {
  $error_notice = array(
    '%type' => 'Notice',
    '!message' => 'Undefined variable: bananas',
    '%function' => 'error_test_generate_warnings()',
    '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
  );
  $error_warning = array(
    '%type' => 'Warning',
    '!message' => 'Division by zero',
    '%function' => 'error_test_generate_warnings()',
    '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
  );
  $error_user_notice = array(
    '%type' => 'User warning',
    '!message' => 'Drupal is awesome',
    '%function' => 'error_test_generate_warnings()',
    '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
  );

  // Set error reporting to collect notices.
  variable_set('error_level', ERROR_REPORTING_DISPLAY_ALL);
  $this
    ->drupalGet('error-test/generate-warnings');
  $this
    ->assertResponse(200, 'Received expected HTTP status code.');
  $this
    ->assertErrorMessage($error_notice);
  $this
    ->assertErrorMessage($error_warning);
  $this
    ->assertErrorMessage($error_user_notice);

  // Set error reporting to not collect notices.
  variable_set('error_level', ERROR_REPORTING_DISPLAY_SOME);
  $this
    ->drupalGet('error-test/generate-warnings');
  $this
    ->assertResponse(200, 'Received expected HTTP status code.');
  $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', ERROR_REPORTING_HIDE);
  $this
    ->drupalGet('error-test/generate-warnings');
  $this
    ->assertResponse(200, 'Received expected HTTP status code.');
  $this
    ->assertNoErrorMessage($error_notice);
  $this
    ->assertNoErrorMessage($error_warning);
  $this
    ->assertNoErrorMessage($error_user_notice);
}