processOutbound example

10 => $this->getMockProcessor($route_name$route$parameters),
      5 => $this->getMockProcessor($route_name$route$parameters),
      0 => $this->getMockProcessor($route_name$route$parameters),
    ];

    // Add the processors in reverse order.     foreach ($processors as $priority => $processor) {
      $this->processorManager->addOutbound($processor$priority);
    }

    $bubbleable_metadata = new BubbleableMetadata();
    $this->processorManager->processOutbound($route_name$route$parameters$bubbleable_metadata);
    // Default cacheability is: permanently cacheable, no cache tags/contexts.     $this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT)$bubbleable_metadata);
  }

  /** * Returns a mock Route processor object. * * @param string $route_name * The route name. * @param \Symfony\Component\Routing\Route $route * The Route to use in mock with() expectation. * @param array $parameters * The parameters to use in mock with() expectation. * * @return \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface|\PHPUnit\Framework\MockObject\MockObject */
$generated_url->addCacheContexts(['url.site']);
    }
    $url = $scheme . '://' . $host . $port . $base_url . $path . $query . $fragment;
    return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
  }

  /** * Passes the path to a processor manager to allow alterations. */
  protected function processPath($path, &$options = [], BubbleableMetadata $bubbleable_metadata = NULL) {
    $actual_path = $path === '/' ? $path : rtrim($path, '/');
    return $this->pathProcessor->processOutbound($actual_path$options$this->requestStack->getCurrentRequest()$bubbleable_metadata);
  }

  /** * Passes the route to the processor manager for altering before compilation. * * @param string $name * The route name. * @param \Symfony\Component\Routing\Route $route * The route object to process. * @param array $parameters * An array of parameters to be passed to the route compiler. * @param \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata * (optional) Object to collect route processors' bubbleable metadata. */
public function addOutbound(OutboundRouteProcessorInterface $processor$priority = 0) {
    $this->outboundProcessors[$priority][] = $processor;
    $this->sortedOutbound = [];
  }

  /** * {@inheritdoc} */
  public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
    $processors = $this->getOutbound();
    foreach ($processors as $processor) {
      $processor->processOutbound($route_name$route$parameters$bubbleable_metadata);
    }
  }

  /** * Returns the sorted array of outbound processors. * * @return array * An array of processor objects. */
  protected function getOutbound() {
    if (empty($this->sortedOutbound)) {
      
/** * Tests the processOutbound() method with no _csrf_token route requirement. */
  public function testProcessOutboundNoRequirement() {
    $this->csrfToken->expects($this->never())
      ->method('get');

    $route = new Route('/test-path');
    $parameters = [];

    $bubbleable_metadata = new BubbleableMetadata();
    $this->processor->processOutbound('test', $route$parameters$bubbleable_metadata);
    // No parameters should be added to the parameters array.     $this->assertEmpty($parameters);
    // Cacheability of routes without a _csrf_token route requirement is     // unaffected.     $this->assertEquals((new BubbleableMetadata())$bubbleable_metadata);
  }

  /** * Tests the processOutbound() method with a _csrf_token route requirement. */
  public function testProcessOutbound() {
    
    $this->assertGenerateFromRoute('test_1', [][]$url(new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));

    $path = $this->generator->getPathFromRoute('test_1');
    $this->assertEquals('test/one', $path);
  }

  /** * @covers ::generateFromRoute */
  public function testUrlGenerationWithDisabledPathProcessing() {
    $path_processor = $this->prophesize(OutboundPathProcessorInterface::class);
    $path_processor->processOutbound(Argument::cetera())->shouldNotBeCalled();

    $generator = new UrlGenerator($this->provider, $path_processor->reveal()$this->routeProcessorManager, $this->requestStack, ['http', 'https']);
    $generator->setContext($this->context);

    $url = $this->generator->generateFromRoute('test_1', []['path_processing' => FALSE]);
    $this->assertEquals('/test/one', $url);
  }

  /** * @covers ::generateFromRoute */
  
public function addOutbound(OutboundPathProcessorInterface $processor$priority = 0) {
    $this->outboundProcessors[$priority][] = $processor;
    $this->sortedOutbound = [];
  }

  /** * {@inheritdoc} */
  public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    $processors = $this->getOutbound();
    foreach ($processors as $processor) {
      $path = $processor->processOutbound($path$options$request$bubbleable_metadata);
    }
    return $path;
  }

  /** * Returns the sorted array of outbound processors. * * @return array * An array of processor objects. */
  protected function getOutbound() {
    
// Remove the base: scheme.     // @todo Consider using a class constant for this in     // https://www.drupal.org/node/2417459     $uri = substr($uri, 5);

    // Allow (outbound) path processing, if needed. A valid use case is the path     // alias overview form:     // @see \Drupal\path\Controller\PathController::adminOverview().     if (!empty($options['path_processing'])) {
      // Do not pass the request, since this is a special case and we do not       // want to include e.g. the request language in the processing.       $uri = $this->pathProcessor->processOutbound($uri$options, NULL, $generated_url);
    }
    // Strip leading slashes from internal paths to prevent them becoming     // external URLs without protocol. /example.com should not be turned into     // //example.com.     $uri = ltrim($uri, '/');

    // Add any subdirectory where Drupal is installed.     $current_base_path = $request->getBasePath() . '/';

    if ($options['absolute']) {
      $current_base_url = $request->getSchemeAndHttpHost() . $current_base_path;
      


    $request = Request::create('/' . $prefix . '/foo', 'GET');
    $method = new LanguageNegotiationUrl();
    $method->setLanguageManager($this->languageManager);
    $method->setConfig($config);
    $method->setCurrentUser($this->user);
    $this->assertEquals($expected_langcode$method->getLangcode($request));

    $cacheability = new BubbleableMetadata();
    $options = [];
    $method->processOutbound('foo', $options$request$cacheability);
    $expected_cacheability = new BubbleableMetadata();
    if ($expected_langcode) {
      $this->assertSame($prefix . '/', $options['prefix']);
      $expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
    }
    else {
      $this->assertFalse(isset($options['prefix']));
    }
    $this->assertEquals($expected_cacheability$cacheability);
  }

  
TRUE
      );
    $languageNegotiationContentEntityMock->expects($this->once())
      ->method('meetsContentEntityRoutesCondition')
      ->willReturnOnConsecutiveCalls(
        FALSE
      );
    $options = [];
    $path = $this->randomMachineName();

    // Case 1a: Empty request.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path));
    $request = Request::create('/foo', 'GET');
    $request->server = new ServerBag();
    // Case 1b: Missing the route key in $options.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));
    $options = ['route' => $this->createMock(Route::class)];
    // Case 1c: hasLowerLanguageNegotiationWeight() returns FALSE.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));
    // Case 1d: meetsContentEntityRoutesCondition() returns FALSE.     $this->assertEquals($path$languageNegotiationContentEntityMock->processOutbound($path$options$request));

    // Case 2: Cannot figure out the langcode.

  protected function assertUrlOutboundAlter(string $original, string $final): void {
    // Test outbound altering.     $result = $this->container->get('path_processor_manager')->processOutbound($original);
    $this->assertSame($final$resultnew FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
  }

  /** * Assert that an inbound path is altered to an expected value. * * @param string $original * The original path before it has been altered by inbound URL processing. * @param string $final * A string with the expected result. * * @internal */

  protected function assertUrlOutboundAlter(string $original, string $final): void {
    // Test outbound altering.     $result = $this->container->get('path_processor_manager')->processOutbound($original);
    $this->assertSame($final$resultnew FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
  }

  /** * Assert that an inbound path is altered to an expected value. * * @param string $original * The original path before it has been altered by inbound URL processing. * @param string $final * A string with the expected result. * * @internal */

  public function testProcessOutbound($path, array $options$expected_path) {
    $this->aliasManager->expects($this->any())
      ->method('getAliasByPath')
      ->willReturnMap([
        ['internal-url', NULL, 'urlalias'],
        ['url', NULL, 'url'],
      ]);

    $bubbleable_metadata = new BubbleableMetadata();
    $this->assertEquals($expected_path$this->pathProcessor->processOutbound($path$options, NULL, $bubbleable_metadata));
    // Cacheability of paths replaced with path aliases is permanent.     // @todo https://www.drupal.org/node/2480077     $this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT)$bubbleable_metadata);
  }

  /** * @return array */
  public function providerTestProcessOutbound() {
    return [
      ['internal-url', [], 'urlalias'],
      [
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    if (!isset($this->multilingual)) {
      $this->multilingual = $this->languageManager->isMultilingual();
    }
    if ($this->multilingual) {
      $this->negotiator->reset();
      $scope = 'outbound';
      if (!isset($this->processors[$scope])) {
        $this->initProcessors($scope);
      }
      foreach ($this->processors[$scope] as $instance) {
        $path = $instance->processOutbound($path$options$request$bubbleable_metadata);
      }
      // No language dependent path allowed in this mode.       if (empty($this->processors[$scope])) {
        unset($options['language']);
      }
    }
    return $path;
  }

  /** * Initializes the local cache for language path processors. * * @param string $scope * The scope of the processors: "inbound" or "outbound". */
Home | Imprint | This part of the site doesn't use cookies.