You are here

function DrupalErrorHandlerUnitTest::testErrorHandler in SimpleTest 7

Test the error handler.

File

tests/error.test, line 22

Class

DrupalErrorHandlerUnitTest
Tests Drupal error and exception handlers.

Code

function testErrorHandler() {
  $error_notice = array(
    '%type' => 'Notice',
    '%message' => 'Undefined variable: bananas',
    '%function' => 'error_test_generate_warnings()',
    '%line' => 44,
    '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
  );
  $error_warning = array(
    '%type' => 'Warning',
    '%message' => 'Division by zero',
    '%function' => 'error_test_generate_warnings()',
    '%line' => 46,
    '%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()',
    '%line' => 48,
    '%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, t('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, t('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, t('Received expected HTTP status code.'));
  $this
    ->assertNoErrorMessage($error_notice);
  $this
    ->assertNoErrorMessage($error_warning);
  $this
    ->assertNoErrorMessage($error_user_notice);
}