setLinkGenerator example


  protected function setupTestField(array $options = []) {
    /** @var \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField $field */
    $field = $this->getMockBuilder('Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField')
      ->addMethods(['l'])
      ->setConstructorArgs([$this->configuration, $this->pluginId, $this->pluginDefinition])
      ->getMock();
    $field->init($this->executable, $this->display, $options);
    $field->setLinkGenerator($this->linkGenerator);

    return $field;
  }

  /** * @covers ::getRenderTokens */
  public function testGetRenderTokensWithoutFieldsAndArguments() {
    $field = $this->setupTestField();

    $this->display->expects($this->any())
      

  public function testGenerateTwice() {
    $this->urlGenerator->expects($this->any())
      ->method('generateFromRoute')
      ->willReturn((new GeneratedUrl())->setGeneratedUrl('/'));

    $url = Url::fromRoute('<front>', []['attributes' => ['class' => ['foo', 'bar']]]);
    $url->setUrlGenerator($this->urlGenerator);

    $link = Link::fromTextAndUrl('text', $url);
    $link->setLinkGenerator($this->linkGenerator);
    $output = $link->toString() . $link->toString();
    $this->assertEquals('<a href="/" class="foo bar">text</a><a href="/" class="foo bar">text</a>', $output);
  }

  /** * Checks that a link with certain properties exists in a given HTML snippet. * * @param array $properties * An associative array of link properties, with the following keys: * - attributes: optional array of HTML attributes that should be present. * - content: optional link content. * @param \Drupal\Component\Render\MarkupInterface $html * The HTML to check. * @param int $count * How many times the link should be present in the HTML. Defaults to 1. * * @internal */
Home | Imprint | This part of the site doesn't use cookies.