LinkGenerator example



  /** * Sets up the unrouted URL assembler and the link generator. */
  protected function setUpUrlIntegrationServices() {
    $this->pathProcessor = $this->createMock('Drupal\Core\PathProcessor\OutboundPathProcessorInterface');
    $this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->pathProcessor);

    \Drupal::getContainer()->set('unrouted_url_assembler', $this->unroutedUrlAssembler);

    $this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface')$this->renderer);
    $this->renderer
      ->method('render')
      ->willReturnCallback(
        // Pretend to do a render.         function D&$elements$is_root_call = FALSE) {
          // Mock the ability to theme links           $link = $this->linkGenerator->generate($elements['#title']$elements['#url']);
          if (isset($elements['#prefix'])) {
            $link = $elements['#prefix'] . $link;
          }
          if (isset($elements['#suffix'])) {
            
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->urlGenerator = $this->getMockBuilder('\Drupal\Core\Routing\UrlGenerator')
      ->disableOriginalConstructor()
      ->getMock();
    $this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->renderer = $this->createMock('\Drupal\Core\Render\RendererInterface');
    $this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->moduleHandler, $this->renderer);
    $this->urlAssembler = $this->createMock('\Drupal\Core\Utility\UnroutedUrlAssemblerInterface');
  }

  /** * Provides test data for testing the link method. * * @see \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs() * * @return array * Returns some test data. */
  
Home | Imprint | This part of the site doesn't use cookies.