function RedirectResponseSubscriberTest::testDestinationRedirectToExternalUrl

Tests destination redirect to external url.

Attributes

#[DataProvider('providerTestDestinationRedirectToExternalUrl')]

File

core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php, line 134

Class

RedirectResponseSubscriberTest
Tests Drupal\Core\EventSubscriber\RedirectResponseSubscriber.

Namespace

Drupal\Tests\Core\EventSubscriber

Code

public function testDestinationRedirectToExternalUrl($request, $expected) : void {
  $dispatcher = new EventDispatcher();
  $kernel = $this->createMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
  $response = new RedirectResponse('http://other-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);
  $this->assertSame(400, $event->getResponse()
    ->getStatusCode());
}

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