summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlex Pott2018-12-18 20:53:03 (GMT)
committerAlex Pott2018-12-18 20:53:10 (GMT)
commit0512a4c023c48e8cfbe8f354e0cfaf77018a6a71 (patch)
tree58906fefcc6aa67b2d3f49a91a6c3ac0a2d9acf5 /core
parent5b4fe974de636bf5a5e8cd8781bf26c148da64cb (diff)
Issue #2984072 by vijaycs85, Lendude, ApacheEx, dawehner: System: Convert ErrorHandlerTest to phpunit
(cherry picked from commit bda5967ecab9efc707b09a4570cc20bd8d61a0c3)
Diffstat (limited to 'core')
-rw-r--r--core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php (renamed from core/modules/system/src/Tests/System/ErrorHandlerTest.php)52
-rw-r--r--core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php28
2 files changed, 34 insertions, 46 deletions
diff --git a/core/modules/system/src/Tests/System/ErrorHandlerTest.php b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php
index dc661fe..3ab502e 100644
--- a/core/modules/system/src/Tests/System/ErrorHandlerTest.php
+++ b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php
@@ -1,16 +1,16 @@
<?php
-namespace Drupal\system\Tests\System;
+namespace Drupal\Tests\system\Functional\System;
use Drupal\Component\Render\FormattableMarkup;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Performs tests on the Drupal error and exception handler.
*
* @group system
*/
-class ErrorHandlerTest extends WebTestBase {
+class ErrorHandlerTest extends BrowserTestBase {
/**
* Modules to enable.
@@ -42,17 +42,6 @@ class ErrorHandlerTest extends WebTestBase {
'%function' => 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()',
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
];
- $fatal_error = [
- '%type' => 'Recoverable fatal error',
- '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()',
- '@message' => 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 62 and defined',
- ];
- if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
- // In PHP 7, instead of a recoverable fatal error we get a TypeError.
- $fatal_error['%type'] = 'TypeError';
- // The error message also changes in PHP 7.
- $fatal_error['@message'] = 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 62';
- }
// Set error reporting to display verbose notices.
$this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save();
@@ -68,25 +57,6 @@ class ErrorHandlerTest extends WebTestBase {
// Set error reporting to display verbose notices.
$this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save();
- $this->drupalGet('error-test/generate-fatals');
- $this->assertResponse(500, 'Received expected HTTP status code.');
- $this->assertErrorMessage($fatal_error);
- $this->assertRaw('<pre class="backtrace">', 'Found pre element with backtrace class.');
- // Ensure we are escaping but not double escaping.
- $this->assertRaw('&#039;');
- $this->assertNoRaw('&amp;#039;');
-
- // Remove the recoverable fatal error from the assertions, it's wanted here.
- // Ensure that we just remove this one recoverable fatal error (in PHP 7 this
- // is a TypeError).
- foreach ($this->assertions as $key => $assertion) {
- if (in_array($assertion['message_group'], ['Recoverable fatal error', 'TypeError']) && strpos($assertion['message'], 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in') !== FALSE) {
- unset($this->assertions[$key]);
- $this->deleteAssert($assertion['message_id']);
- }
- }
- // Drop the single exception.
- $this->results['#exception']--;
// Set error reporting to collect notices.
$config->set('error_level', ERROR_REPORTING_DISPLAY_ALL)->save();
@@ -96,7 +66,6 @@ class ErrorHandlerTest extends WebTestBase {
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
$this->assertNoRaw('<pre class="backtrace">', 'Did not find pre element with backtrace class.');
- $this->assertErrorLogged($fatal_error['@message']);
// Set error reporting to not collect notices.
$config->set('error_level', ERROR_REPORTING_DISPLAY_SOME)->save();
@@ -122,9 +91,6 @@ class ErrorHandlerTest extends WebTestBase {
* Test the exception handler.
*/
public function testExceptionHandler() {
- // Ensure the test error log is empty before these tests.
- $this->assertNoErrorsLogged();
-
$error_exception = [
'%type' => 'Exception',
'@message' => 'Drupal & awesome',
@@ -148,11 +114,11 @@ class ErrorHandlerTest extends WebTestBase {
];
$this->drupalGet('error-test/trigger-exception');
- $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
+ $this->assertSession()->statusCodeEquals(500);
$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.');
+ $this->assertSession()->statusCodeEquals(500);
// We cannot use assertErrorMessage() since the exact 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));
@@ -161,7 +127,7 @@ class ErrorHandlerTest extends WebTestBase {
$this->assertRaw($error_details, format_string("Found '@message' in error page.", ['@message' => $error_details]));
$this->drupalGet('error-test/trigger-renderer-exception');
- $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
+ $this->assertSession()->statusCodeEquals(500);
$this->assertErrorMessage($error_renderer_exception);
// Disable error reporting, ensure that 5xx responses are not cached.
@@ -172,12 +138,8 @@ class ErrorHandlerTest extends WebTestBase {
$this->drupalGet('error-test/trigger-exception');
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Received expected HTTP status line.');
- $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
+ $this->assertSession()->statusCodeEquals(500);
$this->assertNoErrorMessage($error_exception);
-
- // The exceptions are expected. Do not interpret them as a test failure.
- // Not using File API; a potential error must trigger a PHP warning.
- unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
}
/**
diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
index 9885200..1bc789c 100644
--- a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
+++ b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
@@ -2,6 +2,7 @@
namespace Drupal\FunctionalTests\Bootstrap;
+use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
/**
@@ -37,7 +38,7 @@ class UncaughtExceptionTest extends BrowserTestBase {
*
* @var array
*/
- public static $modules = ['error_service_test'];
+ public static $modules = ['error_service_test', 'error_test'];
/**
* {@inheritdoc}
@@ -100,6 +101,31 @@ class UncaughtExceptionTest extends BrowserTestBase {
}
/**
+ * Tests displaying an uncaught fatal error.
+ */
+ public function testUncaughtFatalError() {
+ $fatal_error = [
+ '%type' => 'Recoverable fatal error',
+ '@message' => 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 62 and defined',
+ '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()',
+ ];
+ if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
+ // In PHP 7, instead of a recoverable fatal error we get a TypeError.
+ $fatal_error['%type'] = 'TypeError';
+ // The error message also changes in PHP 7.
+ $fatal_error['@message'] = 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 62';
+ }
+ $this->drupalGet('error-test/generate-fatals');
+ $this->assertResponse(500, 'Received expected HTTP status code.');
+ $message = new FormattableMarkup('%type: @message in %function (line ', $fatal_error);
+ $this->assertRaw((string) $message);
+ $this->assertRaw('<pre class="backtrace">');
+ // Ensure we are escaping but not double escaping.
+ $this->assertRaw('&#039;');
+ $this->assertNoRaw('&amp;#039;');
+ }
+
+ /**
* Tests uncaught exception handling with custom exception handler.
*/
public function testUncaughtExceptionCustomExceptionHandler() {