function LinkGeneratorTest::testGenerateTwice

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateTwice()
  2. 8.9.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateTwice()
  3. 10 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateTwice()

Tests whether rendering the same link twice works.

This is a regression test for https://www.drupal.org/node/2842399.

File

core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php, line 624

Class

LinkGeneratorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21LinkGenerator.php/class/LinkGenerator/11.x" title="Provides a class which generates a link with route names and parameters." class="local">\Drupal\Core\Utility\LinkGenerator</a> @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateTwice() : void {
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.