function ErrorHandlerTest::testErrorHandler
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php \Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler()
- 10 core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php \Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler()
- 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()
Tests the error handler.
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ ErrorHandlerTest.php, line 31
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 = '<em class="placeholder">Notice</em>: Object of class stdClass could not be converted to int in <em class="placeholder">Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()</em> (line';
$error_warning = '<em class="placeholder">Warning</em>: var_export does not handle circular references in <em class="placeholder">Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()</em> (line';
$error_user_notice = '<em class="placeholder">User warning</em>: Drupal & awesome in <em class="placeholder">Drupal\\error_test\\Controller\\ErrorTestController->generateWarnings()</em> (line';
// 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->assertSession()
->responseContains($error_notice);
$this->assertSession()
->responseContains($error_warning);
$this->assertSession()
->responseContains($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->assertSession()
->responseContains($error_notice);
$this->assertSession()
->responseContains($error_warning);
$this->assertSession()
->responseContains($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->assertSession()
->responseNotContains($error_notice);
$this->assertSession()
->responseContains($error_warning);
$this->assertSession()
->responseContains($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->assertSession()
->responseNotContains($error_notice);
$this->assertSession()
->responseNotContains($error_warning);
$this->assertSession()
->responseNotContains($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.