function TestResponseController::testCacheTagsHeaders

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/http_response_debug_cacheability_headers_test/src/Controller/TestResponseController.php \Drupal\http_response_debug_cacheability_headers_test\Controller\TestResponseController::testCacheTagsHeaders()

Provides a render array response that has a large number of cache tags.

Return value

array Render array.

1 string reference to 'TestResponseController::testCacheTagsHeaders'
http_response_debug_cacheability_headers_test.routing.yml in core/modules/system/tests/modules/http_response_debug_cacheability_headers_test/http_response_debug_cacheability_headers_test.routing.yml
core/modules/system/tests/modules/http_response_debug_cacheability_headers_test/http_response_debug_cacheability_headers_test.routing.yml

File

core/modules/system/tests/modules/http_response_debug_cacheability_headers_test/src/Controller/TestResponseController.php, line 52

Class

TestResponseController
Provides responses for testing debug cacheability headers in HTTP responses.

Namespace

Drupal\http_response_debug_cacheability_headers_test\Controller

Code

public function testCacheTagsHeaders() : array {
  // Create multiple cache tags that add up to more than 8k bytes.
  for ($i = 0; $i < 800; $i++) {
    $tags[] = 'cache-tag:' . str_pad("{$i}", 5, '0', STR_PAD_LEFT);
  }
  $tags_length = strlen(implode(' ', $tags));
  return [
    '#markup' => 'This is a test of a list of cache tags debug headers that exceed ' . $tags_length . ' bytes in total.',
    '#cache' => [
      'tags' => $tags,
    ],
  ];
}

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