function BrowserTestBaseTest::testDeprecationHeaders

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testDeprecationHeaders()
  2. 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testDeprecationHeaders()
  3. 11.x 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 766

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.