function ErrorHandlerTest::testErrorHandler
Same name in other branches
- 9 core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php \Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler()
- 8.9.x core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php \Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler()
- 11.x core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php \Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler()
Tests the error handler.
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ ErrorHandlerTest.php, line 30
Class
- ErrorHandlerTest
- Performs tests on the Drupal error and exception handler.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testErrorHandler() : void {
$config = $this->config('system.logging');
$error_notice = [
'%type' => 'Notice',
'@message' => 'Object of class stdClass could not be converted to int',
'%function' => 'Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()',
'%file' => $this->getModulePath('error_test') . '/error_test.module',
];
$error_warning = [
'%type' => 'Warning',
'@message' => 'var_export does not handle circular references',
'%function' => 'Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()',
'%file' => $this->getModulePath('error_test') . '/error_test.module',
];
$error_user_notice = [
'%type' => 'User warning',
'@message' => 'Drupal & awesome',
'%function' => 'Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()',
'%file' => $this->getModulePath('error_test') . '/error_test.module',
];
// Set error reporting to display verbose notices.
$this->config('system.logging')
->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)
->save();
$this->drupalGet('error-test/generate-warnings');
$this->assertSession()
->statusCodeEquals(200);
$this->assertErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
$this->assertSession()
->responseContains('<pre class="backtrace">');
// Ensure we are escaping but not double escaping.
$this->assertSession()
->responseContains('&');
$this->assertSession()
->responseNotContains('&amp;');
// Set error reporting to display verbose notices.
$this->config('system.logging')
->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)
->save();
// Set error reporting to collect notices.
$config->set('error_level', ERROR_REPORTING_DISPLAY_ALL)
->save();
$this->drupalGet('error-test/generate-warnings');
$this->assertSession()
->statusCodeEquals(200);
$this->assertErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
$this->assertSession()
->responseNotContains('<pre class="backtrace">');
// Set error reporting to not collect notices.
$config->set('error_level', ERROR_REPORTING_DISPLAY_SOME)
->save();
$this->drupalGet('error-test/generate-warnings');
$this->assertSession()
->statusCodeEquals(200);
$this->assertNoErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
$this->assertSession()
->responseNotContains('<pre class="backtrace">');
// Set error reporting to not show any errors.
$config->set('error_level', ERROR_REPORTING_HIDE)
->save();
$this->drupalGet('error-test/generate-warnings');
$this->assertSession()
->statusCodeEquals(200);
$this->assertNoErrorMessage($error_notice);
$this->assertNoErrorMessage($error_warning);
$this->assertNoErrorMessage($error_user_notice);
$this->assertNoMessages();
$this->assertSession()
->responseNotContains('<pre class="backtrace">');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.