function TrustedRedirectResponseTest::testCreateFromRedirectResponse

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php \Drupal\Tests\Core\Routing\TrustedRedirectResponseTest::testCreateFromRedirectResponse()
  2. 8.9.x core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php \Drupal\Tests\Core\Routing\TrustedRedirectResponseTest::testCreateFromRedirectResponse()
  3. 10 core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php \Drupal\Tests\Core\Routing\TrustedRedirectResponseTest::testCreateFromRedirectResponse()

@covers ::createFromRedirectResponse
@dataProvider providerCreateFromRedirectResponse

File

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

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

public function testCreateFromRedirectResponse($redirect_response) : void {
  $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.