function HttpResponseDebugCacheabilityHeadersTest::testCacheDebugHeadersLineLength
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/EventSubscriber/HttpResponseDebugCacheabilityHeadersTest.php \Drupal\KernelTests\Core\EventSubscriber\HttpResponseDebugCacheabilityHeadersTest::testCacheDebugHeadersLineLength()
Tests that cache debug headers do not error from exceeding line limits.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ EventSubscriber/ HttpResponseDebugCacheabilityHeadersTest.php, line 35
Class
- HttpResponseDebugCacheabilityHeadersTest
- Tests that debug cacheability header lines do not exceed Apache limit.
Namespace
Drupal\KernelTests\Core\EventSubscriberCode
public function testCacheDebugHeadersLineLength() : void {
$assertSession = $this->assertSession();
$this->drupalGet('test-cache-contexts-headers');
$assertSession->statusCodeEquals(200);
$assertSession->addressEquals('test-cache-contexts-headers');
$headers = $this->getSession()
->getResponseHeaders();
$this->assertArrayHasKey('x-drupal-cache-contexts', $headers);
$context_lines = (array) $headers['x-drupal-cache-contexts'];
// The payload is engineered to exceed the Apache line limit, so the header
// must have been split across multiple lines, and each individual line must
// stay under the 8190-byte limit that would otherwise trigger a 500.
$this->assertGreaterThan(1, count($context_lines));
foreach ($context_lines as $line) {
$this->assertLessThanOrEqual(8190, strlen($line));
}
// Merge multiple cache contexts headers together if needed.
$contexts = implode(' ', $context_lines);
$this->assertStringContainsString('url.query_args:0000', $contexts);
$this->assertStringContainsString('url.query_args:0699', $contexts);
$this->drupalGet('test-cache-tags-headers');
$assertSession->statusCodeEquals(200);
$assertSession->addressEquals('test-cache-tags-headers');
$headers = $this->getSession()
->getResponseHeaders();
$this->assertArrayHasKey('x-drupal-cache-tags', $headers);
$tag_lines = (array) $headers['x-drupal-cache-tags'];
$this->assertGreaterThan(1, count($tag_lines));
foreach ($tag_lines as $line) {
$this->assertLessThanOrEqual(8190, strlen($line));
}
// Merge multiple cache tags headers together if needed.
$tags = implode(' ', $tag_lines);
$this->assertStringContainsString('cache-tag:00000', $tags);
$this->assertStringContainsString('cache-tag:00799', $tags);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.