public function Domain301RedirectTest::testRedirectCacheability in Domain 301 Redirect 8
Test the cacheability of the redirect response.
File
- tests/
src/ Functional/ Domain301RedirectTest.php, line 96
Class
- Domain301RedirectTest
- Test the redirection of a domain using the DomainRedirectEventSubscriber.
Namespace
Drupal\Tests\domain_301_redirect\FunctionalCode
public function testRedirectCacheability() {
$this
->enableRedirect($this->redirectDomain);
list($statusCode, $headers) = $this
->getRedirect($this->domain);
$xDrupalCache = $headers['X-Drupal-Cache'][0] ?? NULL;
if (!isset($xDrupalCache)) {
$this
->markTestSkipped('Missing X-Drupal-Cache header');
}
$this
->assertEquals(301, $statusCode, 'The domain is redirecting.');
$this
->assertEquals('MISS', $xDrupalCache, 'The first redirect is a cache miss.');
list($statusCode, $headers) = $this
->getRedirect($this->domain);
$xDrupalCache = $headers['X-Drupal-Cache'][0] ?? NULL;
$this
->assertEquals(301, $statusCode);
$this
->assertEquals('HIT', $xDrupalCache, 'The second redirect is a cache hit.');
}