You are here

public function BrowserTestBaseTest::testDeprecationHeaders in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testDeprecationHeaders()
  2. 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testDeprecationHeaders()

Tests that deprecation headers do not get duplicated.

@group legacy

See also

\Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware::__invoke()

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 912

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

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) {
        $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);
}