function RedirectResponseSubscriberTest::testDestinationRedirectToExternalUrl

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

@dataProvider providerTestDestinationRedirectToExternalUrl

File

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

Class

RedirectResponseSubscriberTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21EventSubscriber%21RedirectResponseSubscriber.php/class/RedirectResponseSubscriber/11.x" title="Allows manipulation of the response object when performing a redirect." class="local">\Drupal\Core\EventSubscriber\RedirectResponseSubscriber</a> @group EventSubscriber

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.