function RedirectResponseSubscriberTest::testRedirectWithOptInExternalUrl
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::testRedirectWithOptInExternalUrl()
- 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::testRedirectWithOptInExternalUrl()
- 10 core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::testRedirectWithOptInExternalUrl()
@covers ::checkRedirectUrl
File
-
core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ RedirectResponseSubscriberTest.php, line 145
Class
- RedirectResponseSubscriberTest
- @coversDefaultClass \Drupal\Core\EventSubscriber\RedirectResponseSubscriber @group EventSubscriber
Namespace
Drupal\Tests\Core\EventSubscriberCode
public function testRedirectWithOptInExternalUrl() : void {
$dispatcher = new EventDispatcher();
$kernel = $this->createMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$response = new TrustedRedirectResponse('http://external-url.com');
$request = Request::create('');
$request->headers
->set('HOST', 'example.com');
$listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext, $this->loggerClosure);
$dispatcher->addListener(KernelEvents::RESPONSE, [
$listener,
'checkRedirectUrl',
]);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$target_url = $event->getResponse()
->getTargetUrl();
$this->assertEquals('http://external-url.com', $target_url);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.