Loading core/includes/errors.inc +15 −9 Original line number Diff line number Diff line Loading @@ -87,6 +87,11 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c // If the site is a test site then fail for user deprecations so they can be // caught by the deprecation error handler. elseif (DRUPAL_TEST_IN_CHILD_SITE && $error_level === E_USER_DEPRECATED) { static $seen = []; if (array_search($message, $seen, TRUE) === FALSE) { // Only report each deprecation once. Too many headers can break some // Chrome and web driver testing. $seen[] = $message; $backtrace = debug_backtrace(); $caller = Error::getLastCaller($backtrace); _drupal_error_header( Loading @@ -98,6 +103,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c ); } } } /** * Determines whether an error should be displayed. Loading core/modules/system/tests/modules/test_page_test/src/Controller/Test.php +13 −0 Original line number Diff line number Diff line Loading @@ -155,4 +155,17 @@ public function metaRefresh() { return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString(), 302); } /** * Returns a page while triggering deprecation notices. */ public function deprecations() { // Create 2 identical deprecation messages. This should only trigger a // single response header. @trigger_error('Test deprecation message', E_USER_DEPRECATED); @trigger_error('Test deprecation message', E_USER_DEPRECATED); return [ '#markup' => 'Content that triggers deprecation messages', ]; } } core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +8 −0 Original line number Diff line number Diff line Loading @@ -114,3 +114,11 @@ test_page_test.meta_refresh: _controller: '\Drupal\test_page_test\Controller\Test::metaRefresh' requirements: _access: 'TRUE' test_page_test.deprecations: path: '/test-deprecations' defaults: _title: 'Page with deprecation notices' _controller: '\Drupal\test_page_test\Controller\Test::deprecations' requirements: _access: 'TRUE' core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +33 −0 Original line number Diff line number Diff line Loading @@ -743,4 +743,37 @@ public function testEscapingAssertions() { $assert->assertNoEscaped("<script>alert('Marked safe');alert(\"Marked safe\");</script>"); } /** * Tests that deprecation headers do not get duplicated. * * @group legacy * * @see \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware::__invoke() */ public function testDeprecationHeaders() { $this->drupalGet('/test-deprecations'); $deprecation_messages = []; foreach ($this->getSession()->getResponseHeaders() as $name => $values) { if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $name, $matches)) { foreach ($values as $value) { // Call \Drupal\simpletest\WebTestBase::error() with the parameters from // the header. $parameters = unserialize(urldecode($value)); if (count($parameters) === 3) { if ($parameters[1] === 'User deprecated function') { $deprecation_messages[] = (string) $parameters[0]; } } } } } $this->assertContains('Test deprecation message', $deprecation_messages); $test_deprecation_messages = array_filter($deprecation_messages, function ($message) { return $message === 'Test deprecation message'; }); $this->assertCount(1, $test_deprecation_messages); } } Loading
core/includes/errors.inc +15 −9 Original line number Diff line number Diff line Loading @@ -87,6 +87,11 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c // If the site is a test site then fail for user deprecations so they can be // caught by the deprecation error handler. elseif (DRUPAL_TEST_IN_CHILD_SITE && $error_level === E_USER_DEPRECATED) { static $seen = []; if (array_search($message, $seen, TRUE) === FALSE) { // Only report each deprecation once. Too many headers can break some // Chrome and web driver testing. $seen[] = $message; $backtrace = debug_backtrace(); $caller = Error::getLastCaller($backtrace); _drupal_error_header( Loading @@ -98,6 +103,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c ); } } } /** * Determines whether an error should be displayed. Loading
core/modules/system/tests/modules/test_page_test/src/Controller/Test.php +13 −0 Original line number Diff line number Diff line Loading @@ -155,4 +155,17 @@ public function metaRefresh() { return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString(), 302); } /** * Returns a page while triggering deprecation notices. */ public function deprecations() { // Create 2 identical deprecation messages. This should only trigger a // single response header. @trigger_error('Test deprecation message', E_USER_DEPRECATED); @trigger_error('Test deprecation message', E_USER_DEPRECATED); return [ '#markup' => 'Content that triggers deprecation messages', ]; } }
core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +8 −0 Original line number Diff line number Diff line Loading @@ -114,3 +114,11 @@ test_page_test.meta_refresh: _controller: '\Drupal\test_page_test\Controller\Test::metaRefresh' requirements: _access: 'TRUE' test_page_test.deprecations: path: '/test-deprecations' defaults: _title: 'Page with deprecation notices' _controller: '\Drupal\test_page_test\Controller\Test::deprecations' requirements: _access: 'TRUE'
core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +33 −0 Original line number Diff line number Diff line Loading @@ -743,4 +743,37 @@ public function testEscapingAssertions() { $assert->assertNoEscaped("<script>alert('Marked safe');alert(\"Marked safe\");</script>"); } /** * Tests that deprecation headers do not get duplicated. * * @group legacy * * @see \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware::__invoke() */ public function testDeprecationHeaders() { $this->drupalGet('/test-deprecations'); $deprecation_messages = []; foreach ($this->getSession()->getResponseHeaders() as $name => $values) { if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $name, $matches)) { foreach ($values as $value) { // Call \Drupal\simpletest\WebTestBase::error() with the parameters from // the header. $parameters = unserialize(urldecode($value)); if (count($parameters) === 3) { if ($parameters[1] === 'User deprecated function') { $deprecation_messages[] = (string) $parameters[0]; } } } } } $this->assertContains('Test deprecation message', $deprecation_messages); $test_deprecation_messages = array_filter($deprecation_messages, function ($message) { return $message === 'Test deprecation message'; }); $this->assertCount(1, $test_deprecation_messages); } }