RedirectResponseSubscriber example


  public function testDestinationRedirect(Request $request$expected) {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new RedirectResponse('http://example.com/drupal');
    $request->headers->set('HOST', 'example.com');

    $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
    $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();
    if ($expected) {
      $this->assertEquals($expected$target_url);
    }
    else {
      $this->assertEquals('http://example.com/drupal', $target_url);
    }
  }
Home | Imprint | This part of the site doesn't use cookies.