function HtmxRendererCacheTest::testCacheResources
File
-
core/
tests/ Drupal/ FunctionalTests/ Htmx/ HtmxRendererCacheTest.php, line 41
Class
- HtmxRendererCacheTest
- Tests the cache headers set HtmxRenderer responses.
Namespace
Drupal\FunctionalTests\HtmxCode
public function testCacheResources() : void {
$options = [
'query' => [
MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_htmx',
],
];
$this->drupalGet('/htmx-test-attachments/replace', $options);
$this->assertSession()
->responseHeaderExists('X-Drupal-Cache-Tags');
$this->assertSession()
->responseHeaderEquals('X-Drupal-Cache-Tags', '4xx-response config:user.role.anonymous http_response');
$this->assertSession()
->responseHeaderExists('X-Drupal-Cache-Contexts');
$this->assertSession()
->responseHeaderEquals('X-Drupal-Cache-Contexts', 'user.permissions');
$this->assertSession()
->responseHeaderExists('X-Drupal-Cache');
$this->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
// Test that the cache is hit when the same request is made again.
$this->drupalGet('/htmx-test-attachments/replace', $options);
$this->assertSession()
->responseHeaderExists('X-Drupal-Cache');
$this->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'HIT');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.