function TrustedRedirectResponseTest::testCreateFromRedirectResponse

@covers ::createFromRedirectResponse
@dataProvider providerCreateFromRedirectResponse

File

core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php, line 60

Class

TrustedRedirectResponseTest
@coversDefaultClass \Drupal\Core\Routing\TrustedRedirectResponse[[api-linebreak]] @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testCreateFromRedirectResponse($redirect_response) {
  $trusted_redirect_response = TrustedRedirectResponse::createFromRedirectResponse($redirect_response);
  // The trusted redirect response is always a CacheableResponseInterface instance.
  $this->assertInstanceOf(CacheableResponseInterface::class, $trusted_redirect_response);
  // But it is only actually cacheable (non-zero max-age) if the redirect
  // response passed to TrustedRedirectResponse::createFromRedirectResponse()
  // is itself cacheable.
  $expected_cacheability = $redirect_response instanceof CacheableResponseInterface ? $redirect_response->getCacheableMetadata() : (new CacheableMetadata())->setCacheMaxAge(0);
  $this->assertEquals($expected_cacheability, $trusted_redirect_response->getCacheableMetadata());
}

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