AliasPathProcessor example

->willReturnCallback([$this, 'aliasManagerCallback']);

    $this->aliasManager = $alias_manager;

    $this->requestStack = new RequestStack();
    $request = Request::create('/some/path');
    $this->requestStack->push($request);

    $this->context = new RequestContext();
    $this->context->fromRequestStack($this->requestStack);

    $processor = new AliasPathProcessor($this->aliasManager);
    $processor_manager = new PathProcessorManager();
    $processor_manager->addOutbound($processor, 1000);
    $this->processorManager = $processor_manager;

    $this->routeProcessorManager = $this->getMockBuilder('Drupal\Core\RouteProcessor\RouteProcessorManager')
      ->disableOriginalConstructor()
      ->getMock();

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

  protected $pathProcessor;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->aliasManager = $this->createMock('Drupal\path_alias\AliasManagerInterface');
    $this->pathProcessor = new AliasPathProcessor($this->aliasManager);
  }

  /** * Tests the processInbound method. * * @see \Drupal\path_alias\PathProcessor\AliasPathProcessor::processInbound */
  public function testProcessInbound() {
    $this->aliasManager->expects($this->exactly(2))
      ->method('getPathByAlias')
      ->willReturnMap([
        [
// Create a user stub.     $current_user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')
      ->getMock();

    // Create a config event subscriber stub.     $config_subscriber = $this->getMockBuilder('Drupal\language\EventSubscriber\ConfigSubscriber')
      ->disableOriginalConstructor()
      ->getMock();

    // Create the processors.     $alias_processor = new AliasPathProcessor($alias_manager);
    $decode_processor = new PathProcessorDecode();
    $front_processor = new PathProcessorFront($config_factory_stub);
    $language_processor = new PathProcessorLanguage($config_factory_stub$this->languageManager, $negotiator$current_user$config_subscriber);

    // First, test the processor manager with the processors in the incorrect     // order. The alias processor will run before the language processor, meaning     // aliases will not be found.     $priorities = [
      1000 => $alias_processor,
      500 => $decode_processor,
      300 => $front_processor,
      
Home | Imprint | This part of the site doesn't use cookies.