setCompleteBaseUrl example

$redirect_response = new TrustedRedirectResponse('/example');
    $redirect_response->setTargetUrl('/example2');

    $this->assertEquals('/example2', $redirect_response->getTargetUrl());
  }

  /** * @covers ::setTargetUrl */
  public function testSetTargetUrlWithUntrustedUrl() {
    $request_context = new RequestContext();
    $request_context->setCompleteBaseUrl('https://www.drupal.org');
    $container = new ContainerBuilder();
    $container->set('router.request_context', $request_context);
    \Drupal::setContainer($container);

    $redirect_response = new TrustedRedirectResponse('/example');

    $this->expectException(\InvalidArgumentException::class);
    $redirect_response->setTargetUrl('http://evil-url.com/example');
  }

  /** * @covers ::setTargetUrl */
public function fromRequestStack(RequestStack $request_stack) {
    $this->fromRequest($request_stack->getCurrentRequest());
  }

  /** * {@inheritdoc} */
  public function fromRequest(Request $request)static {
    // @todo Extract the code in DrupalKernel::initializeRequestGlobals.     // See https://www.drupal.org/node/2404601     if (isset($GLOBALS['base_url'])) {
      $this->setCompleteBaseUrl($GLOBALS['base_url']);
    }

    return parent::fromRequest($request);
  }

  /** * Gets the scheme, host and base path. * * For example, in an installation in a subdirectory "d8", it should be * "https://example.com/d8". */
  
    $request_stack = \Drupal::requestStack();
    // Test request with subdirectory on homepage.     $server = [
      'SCRIPT_NAME' => '/subdir/index.php',
      'SCRIPT_FILENAME' => $this->root . '/subdir/index.php',
      'SERVER_NAME' => 'http://localhost',
    ];
    $request = Request::create('/subdir/', 'GET', [][][]$server);
    $request->server->add($server);
    $request_stack->push($request);
    $bubbleable_metadata = new BubbleableMetadata();
    $this->container->get('router.request_context')->setCompleteBaseUrl('http://localhost/subdir');
    $this->assertEquals('http://localhost/subdir', $this->tokenService->replace('[site:base-url]', []['langcode' => $this->interfaceLanguage->getId()]$bubbleable_metadata));
    $this->assertEquals((new BubbleableMetadata())->addCacheContexts(['url.site'])$bubbleable_metadata);
    $bubbleable_metadata = new BubbleableMetadata();
    $this->assertEquals('/subdir', $this->tokenService->replace('[site:base-path]', []['langcode' => $this->interfaceLanguage->getId()]$bubbleable_metadata));
    $this->assertEquals((new BubbleableMetadata())->addCacheContexts(['url.site'])$bubbleable_metadata);
  }

  /** * Tests the generation of all system date tokens. */
  public function testSystemDateTokenReplacement() {
    
Home | Imprint | This part of the site doesn't use cookies.